| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "ShutterController.h"
- #include <Arduino.h>
- /// <summary>
- /// Constructs a ShutterController instance with specified GPIO pins.
- /// </summary>
- ShutterController::ShutterController(uint8_t focusPin, uint8_t shutterPin)
- : focusPin(focusPin), shutterPin(shutterPin), isFocusPressed(false)
- {
- }
- /// <summary>
- /// Performs a half press of the shutter to initiate focus.
- /// Sets the focus pin HIGH and marks focus as pressed.
- /// </summary>
- void ShutterController::halfPress()
- {
- digitalWrite(focusPin, HIGH);
- isFocusPressed = true;
- }
- /// <summary>
- /// Performs a full press of the shutter to take a photo.
- /// Automatically half-presses the shutter if not already pressed.
- /// Sets the shutter pin HIGH to simulate a full button press.
- /// </summary>
- void ShutterController::fullPress()
- {
- if (!isFocusPressed)
- {
- halfPress();
- delay(1000);
- }
-
- digitalWrite(shutterPin, HIGH);
- }
- /// <summary>
- /// Presses the shutter fully, waits for the specified delay, then releases.
- /// Automatically returns to neutral position after the delay.
- /// </summary>
- /// <param name="ms">Delay in milliseconds between full press and release</param>
- void ShutterController::pressFullWithDelay(int ms)
- {
- fullPress();
- delay(ms);
- unPress();
- }
- /// <summary>
- /// Releases the shutter and returns to neutral position.
- /// Sets both focus and shutter pins LOW and updates the focus state.
- /// </summary>
- void ShutterController::unPress()
- {
- digitalWrite(shutterPin, LOW);
- digitalWrite(focusPin, LOW);
- isFocusPressed = false;
- }
- /// <summary>
- /// Takes multiple photos in sequence with configurable timing.
- /// Ensures focus is locked before taking photos, then executes the sequence.
- /// </summary>
- /// <param name="ms">Duration of each full press in milliseconds</param>
- /// <param name="count">Number of photos to take</param>
- /// <param name="delayMs">Delay between consecutive shots in milliseconds</param>
- void ShutterController::multipleShoot(int ms, int count, int delayMs)
- {
- if (!isFocusPressed)
- {
- halfPress();
- delay(1000);
- }
-
- while (count > 0)
- {
- fullPress();
- delay(ms);
- digitalWrite(shutterPin, LOW);
- count--;
- delay(delayMs);
- }
- }
- /// <summary>
- /// Returns the current focus press state.
- /// </summary>
- /// <returns>True if focus is currently pressed, false otherwise</returns>
- bool ShutterController::getFocusPressedState() const
- {
- return isFocusPressed;
- }
|