ShutterController.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef SHUTTER_CONTROLLER_H
  2. #define SHUTTER_CONTROLLER_H
  3. #include <Arduino.h>
  4. /// <summary>
  5. /// Interface for camera shutter control operations.
  6. /// Defines the contract for controlling camera focus and shutter functionality.
  7. /// </summary>
  8. class IShutterController
  9. {
  10. public:
  11. virtual ~IShutterController() = default;
  12. /// <summary>
  13. /// Performs a half press of the shutter to initiate focus.
  14. /// This is equivalent to pressing the shutter button halfway down.
  15. /// </summary>
  16. virtual void halfPress() = 0;
  17. /// <summary>
  18. /// Performs a full press of the shutter to take a photo.
  19. /// Automatically calls halfPress() if not already pressed.
  20. /// </summary>
  21. virtual void fullPress() = 0;
  22. /// <summary>
  23. /// Releases the shutter and returns to neutral position.
  24. /// Resets focus state and shutter pin to LOW.
  25. /// </summary>
  26. virtual void unPress() = 0;
  27. /// <summary>
  28. /// Presses the shutter fully, waits for specified delay, then releases.
  29. /// </summary>
  30. /// <param name="ms">Delay in milliseconds between full press and release</param>
  31. virtual void pressFullWithDelay(int ms) = 0;
  32. /// <summary>
  33. /// Takes multiple photos in sequence with configurable timing.
  34. /// </summary>
  35. /// <param name="ms">Duration of each full press in milliseconds</param>
  36. /// <param name="count">Number of photos to take</param>
  37. /// <param name="delayMs">Delay between consecutive shots in milliseconds</param>
  38. virtual void multipleShoot(int ms, int count, int delayMs) = 0;
  39. };
  40. /// <summary>
  41. /// Implementation of camera shutter control for Minolta remote.
  42. /// Controls focus and shutter via GPIO pins to simulate button presses.
  43. /// </summary>
  44. class ShutterController : public IShutterController
  45. {
  46. private:
  47. /// <summary>GPIO pin number for focus control</summary>
  48. uint8_t focusPin;
  49. /// <summary>GPIO pin number for shutter control</summary>
  50. uint8_t shutterPin;
  51. /// <summary>Flag indicating whether focus is currently pressed</summary>
  52. bool isFocusPressed;
  53. /// <summary>
  54. /// Non-blocking delay that yields to WiFi stack regularly.
  55. /// Breaks long delays into small chunks to prevent Soft WDT reset.
  56. /// </summary>
  57. /// <param name="ms">Delay duration in milliseconds</param>
  58. void nonBlockingDelay(unsigned long ms);
  59. public:
  60. /// <summary>
  61. /// Constructs a ShutterController instance.
  62. /// </summary>
  63. /// <param name="focusPin">GPIO pin for focus control (e.g., D1/GPIO5)</param>
  64. /// <param name="shutterPin">GPIO pin for shutter control (e.g., D2/GPIO4)</param>
  65. ShutterController(uint8_t focusPin, uint8_t shutterPin);
  66. /// <summary>
  67. /// Performs a half press of the shutter to initiate focus.
  68. /// </summary>
  69. void halfPress() override;
  70. /// <summary>
  71. /// Performs a full press of the shutter to take a photo.
  72. /// </summary>
  73. void fullPress() override;
  74. /// <summary>
  75. /// Releases the shutter and returns to neutral position.
  76. /// </summary>
  77. void unPress() override;
  78. /// <summary>
  79. /// Presses the shutter fully, waits for specified delay, then releases.
  80. /// </summary>
  81. /// <param name="ms">Delay in milliseconds between full press and release</param>
  82. void pressFullWithDelay(int ms) override;
  83. /// <summary>
  84. /// Takes multiple photos in sequence with configurable timing.
  85. /// </summary>
  86. /// <param name="ms">Duration of each full press in milliseconds</param>
  87. /// <param name="count">Number of photos to take</param>
  88. /// <param name="delayMs">Delay between consecutive shots in milliseconds</param>
  89. void multipleShoot(int ms, int count, int delayMs) override;
  90. /// <summary>
  91. /// Gets the current focus press state.
  92. /// </summary>
  93. /// <returns>True if focus is currently pressed, false otherwise</returns>
  94. bool getFocusPressedState() const;
  95. };
  96. #endif // SHUTTER_CONTROLLER_H