fork(1) 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. int8_t max(int8_t a, int8_t b) {
  15. if (a >= b) {
  16. return a;
  17. }
  18. return b;
  19. }
  20. int8_t min(int8_t a, int8_t b) {
  21. if (a < b) {
  22. return a;
  23. }
  24. return b;
  25. }
  26.  
  27. int nextZoom(int8_t plusZoomPercentage) {
  28. //if (!unabto_query_read_int8(readBuffer, &plusZoomPercentage))
  29. //{
  30. // return AER_REQ_TOO_SMALL;
  31. //}
  32. if (plusZoomPercentage != 0)
  33. {
  34. uint8_t currentZoomPercentage = currentZoom;
  35. plusZoomPercentage = max(plusZoomPercentage, -currentZoomPercentage);
  36. plusZoomPercentage = min(plusZoomPercentage, 100 - currentZoomPercentage);
  37. zoomToPercentage(currentZoomPercentage + plusZoomPercentage);
  38. }
  39. return AER_REQ_RESPONSE_READY;
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45. nextZoom(50);
  46. nextZoom(50);
  47. nextZoom(50);
  48. nextZoom(-120);
  49. }
  50.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
Zoom to 50
Zoom to 100
Zoom to 100
Zoom to 0