fork download
  1. #include<stdio.h>
  2. #include<stdint.h>
  3. #include<string.h>
  4.  
  5. #define AER_REQ_RESPONSE_READY 0
  6.  
  7. uint8_t currentZoom = 0;
  8.  
  9. void zoomToPercentage(uint8_t percentage) {
  10. printf("Zoom to %d\n", percentage);
  11. currentZoom = percentage;
  12. }
  13.  
  14. int nextZoom(int8_t plusZoomPercentage) {
  15. //if (!unabto_query_read_int8(readBuffer, &plusZoomPercentage))
  16. //{
  17. // return AER_REQ_TOO_SMALL;
  18. //}
  19. if (plusZoomPercentage != 0)
  20. {
  21. uint8_t currentZoomPercentage = currentZoom;
  22. if (plusZoomPercentage < - currentZoomPercentage) {
  23. plusZoomPercentage = - currentZoomPercentage;
  24. }
  25. if (plusZoomPercentage > 100 - currentZoomPercentage) {
  26. plusZoomPercentage = 100 - currentZoomPercentage;
  27. }
  28. zoomToPercentage(currentZoomPercentage + plusZoomPercentage);
  29. }
  30. return AER_REQ_RESPONSE_READY;
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. nextZoom(50);
  37. nextZoom(50);
  38. nextZoom(50);
  39. nextZoom(-120);
  40. }
  41.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
Zoom to 50
Zoom to 100
Zoom to 100
Zoom to 0