ShutterController.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "ShutterController.h"
  2. #include <Arduino.h>
  3. /// <summary>
  4. /// Constructs a ShutterController instance with specified GPIO pins.
  5. /// </summary>
  6. ShutterController::ShutterController(uint8_t focusPin, uint8_t shutterPin)
  7. : focusPin(focusPin), shutterPin(shutterPin), isFocusPressed(false)
  8. {
  9. }
  10. /// <summary>
  11. /// Performs a half press of the shutter to initiate focus.
  12. /// Sets the focus pin HIGH and marks focus as pressed.
  13. /// </summary>
  14. void ShutterController::halfPress()
  15. {
  16. digitalWrite(focusPin, HIGH);
  17. isFocusPressed = true;
  18. }
  19. /// <summary>
  20. /// Performs a full press of the shutter to take a photo.
  21. /// Automatically half-presses the shutter if not already pressed.
  22. /// Sets the shutter pin HIGH to simulate a full button press.
  23. /// </summary>
  24. void ShutterController::fullPress()
  25. {
  26. if (!isFocusPressed)
  27. {
  28. halfPress();
  29. delay(1000);
  30. }
  31. digitalWrite(shutterPin, HIGH);
  32. }
  33. /// <summary>
  34. /// Presses the shutter fully, waits for the specified delay, then releases.
  35. /// Automatically returns to neutral position after the delay.
  36. /// </summary>
  37. /// <param name="ms">Delay in milliseconds between full press and release</param>
  38. void ShutterController::pressFullWithDelay(int ms)
  39. {
  40. fullPress();
  41. delay(ms);
  42. unPress();
  43. }
  44. /// <summary>
  45. /// Releases the shutter and returns to neutral position.
  46. /// Sets both focus and shutter pins LOW and updates the focus state.
  47. /// </summary>
  48. void ShutterController::unPress()
  49. {
  50. digitalWrite(shutterPin, LOW);
  51. digitalWrite(focusPin, LOW);
  52. isFocusPressed = false;
  53. }
  54. /// <summary>
  55. /// Takes multiple photos in sequence with configurable timing.
  56. /// Ensures focus is locked before taking photos, then executes the sequence.
  57. /// </summary>
  58. /// <param name="ms">Duration of each full press in milliseconds</param>
  59. /// <param name="count">Number of photos to take</param>
  60. /// <param name="delayMs">Delay between consecutive shots in milliseconds</param>
  61. void ShutterController::multipleShoot(int ms, int count, int delayMs)
  62. {
  63. if (!isFocusPressed)
  64. {
  65. halfPress();
  66. delay(1000);
  67. }
  68. while (count > 0)
  69. {
  70. fullPress();
  71. delay(ms);
  72. digitalWrite(shutterPin, LOW);
  73. count--;
  74. delay(delayMs);
  75. }
  76. }
  77. /// <summary>
  78. /// Returns the current focus press state.
  79. /// </summary>
  80. /// <returns>True if focus is currently pressed, false otherwise</returns>
  81. bool ShutterController::getFocusPressedState() const
  82. {
  83. return isFocusPressed;
  84. }