|
@@ -1,6 +1,32 @@
|
|
|
#include "ShutterController.h"
|
|
#include "ShutterController.h"
|
|
|
#include <Arduino.h>
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
+/// <summary>
|
|
|
|
|
+/// Non-blocking delay that yields to WiFi stack regularly.
|
|
|
|
|
+/// For delays < 2 seconds, uses blocking delay directly.
|
|
|
|
|
+/// For longer delays, breaks into 2-second chunks and feeds the watchdog.
|
|
|
|
|
+/// </summary>
|
|
|
|
|
+void ShutterController::nonBlockingDelay(unsigned long ms)
|
|
|
|
|
+{
|
|
|
|
|
+ if (ms < 1000)
|
|
|
|
|
+ {
|
|
|
|
|
+ delay(ms);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unsigned long startTime = millis();
|
|
|
|
|
+ unsigned long remaining = 0;
|
|
|
|
|
+ unsigned long delayTime = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (millis() - startTime < ms)
|
|
|
|
|
+ {
|
|
|
|
|
+ remaining = ms - (millis() - startTime);
|
|
|
|
|
+ delayTime = (remaining < 1000) ? remaining : 1000;
|
|
|
|
|
+ delay(delayTime);
|
|
|
|
|
+ ESP.wdtFeed();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Constructs a ShutterController instance with specified GPIO pins.
|
|
/// Constructs a ShutterController instance with specified GPIO pins.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -29,7 +55,7 @@ void ShutterController::fullPress()
|
|
|
if (!isFocusPressed)
|
|
if (!isFocusPressed)
|
|
|
{
|
|
{
|
|
|
halfPress();
|
|
halfPress();
|
|
|
- delay(1000);
|
|
|
|
|
|
|
+ nonBlockingDelay(1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
digitalWrite(shutterPin, HIGH);
|
|
digitalWrite(shutterPin, HIGH);
|
|
@@ -43,7 +69,7 @@ void ShutterController::fullPress()
|
|
|
void ShutterController::pressFullWithDelay(int ms)
|
|
void ShutterController::pressFullWithDelay(int ms)
|
|
|
{
|
|
{
|
|
|
fullPress();
|
|
fullPress();
|
|
|
- delay(ms);
|
|
|
|
|
|
|
+ nonBlockingDelay(ms);
|
|
|
unPress();
|
|
unPress();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -70,16 +96,19 @@ void ShutterController::multipleShoot(int ms, int count, int delayMs)
|
|
|
if (!isFocusPressed)
|
|
if (!isFocusPressed)
|
|
|
{
|
|
{
|
|
|
halfPress();
|
|
halfPress();
|
|
|
- delay(1000);
|
|
|
|
|
|
|
+ nonBlockingDelay(1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
while (count > 0)
|
|
while (count > 0)
|
|
|
{
|
|
{
|
|
|
fullPress();
|
|
fullPress();
|
|
|
- delay(ms);
|
|
|
|
|
|
|
+ nonBlockingDelay(ms);
|
|
|
digitalWrite(shutterPin, LOW);
|
|
digitalWrite(shutterPin, LOW);
|
|
|
count--;
|
|
count--;
|
|
|
- delay(delayMs);
|
|
|
|
|
|
|
+ if (count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ nonBlockingDelay(delayMs);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|