serial_commands.ino 2.3 KB

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