serial_commands.ino 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "serial_commands.h"
  2. void serial_commands()
  3. {
  4. if (Serial.available() > 0)
  5. {
  6. // Get the camera model reference.
  7. CameraModel *model = CameraModel::getInstance();
  8. char input = Serial.read();
  9. sensor_t *cam = esp_camera_sensor_get();
  10. switch (input)
  11. {
  12. case '>': // Toggle dithering.
  13. model->setIsDitheringDisabled(
  14. !model->getIsDitheringDisabled());
  15. break;
  16. case '<': // Toggle invert.
  17. model->setIsInverted(
  18. !model->getIsInverted());
  19. break;
  20. case 'b': // Remove brightness.
  21. cam->set_contrast(cam, cam->status.brightness - 1);
  22. break;
  23. case 'B': // Add brightness.
  24. cam->set_contrast(cam, cam->status.brightness + 1);
  25. break;
  26. case 'c': // Remove contrast.
  27. cam->set_contrast(cam, cam->status.contrast - 1);
  28. break;
  29. case 'C': // Add contrast.
  30. cam->set_contrast(cam, cam->status.contrast + 1);
  31. break;
  32. case 'f': // Turn the flash off.
  33. pinMode(FLASH_GPIO_NUM, OUTPUT);
  34. digitalWrite(FLASH_GPIO_NUM, LOW);
  35. model->setIsFlashEnabled(false);
  36. break;
  37. case 'F': // Turn the flash on.
  38. pinMode(FLASH_GPIO_NUM, OUTPUT);
  39. digitalWrite(FLASH_GPIO_NUM, HIGH);
  40. model->setIsFlashEnabled(true);
  41. break;
  42. case 'P': // Save image to the onboard SD card.
  43. // @todo - Future feature.
  44. // save_picture();
  45. break;
  46. case 'M': // Toggle Mirror.
  47. cam->set_hmirror(cam, !cam->status.hmirror);
  48. break;
  49. case 's': // Stop stream.
  50. model->setIsStreamEnabled(false);
  51. break;
  52. case 'S': // Start stream.
  53. model->setIsStreamEnabled(true);
  54. break;
  55. case '0': // Use Floyd Steinberg dithering.
  56. model->setDitherAlgorithm(FLOYD_STEINBERG);
  57. break;
  58. case '1': // Use Jarvis Judice dithering.
  59. model->setDitherAlgorithm(JARVIS_JUDICE_NINKE);
  60. break;
  61. case '2': // Use Stucki dithering.
  62. model->setDitherAlgorithm(STUCKI);
  63. break;
  64. default:
  65. // Do nothing.
  66. break;
  67. }
  68. }
  69. }