From 3b674d75ab76500ae72645c9841c69ba674e1923 Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Thu, 10 Feb 2022 18:16:49 +0100 Subject: [PATCH] implement run skeleton --- PhotoStepper/PhotoStepper.ino | 1 + PhotoStepper/Scenerunner.cpp | 49 ++++++++++++++++++++++++++++++++--- PhotoStepper/Scenerunner.h | 12 ++++++--- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/PhotoStepper/PhotoStepper.ino b/PhotoStepper/PhotoStepper.ino index cb627ca..06eb3e6 100644 --- a/PhotoStepper/PhotoStepper.ino +++ b/PhotoStepper/PhotoStepper.ino @@ -82,6 +82,7 @@ result enter_jog() { result enter_run() { Serial.println("enter_run()"); state = STATE_RUN; + scenerunner.start(); return proceed; } diff --git a/PhotoStepper/Scenerunner.cpp b/PhotoStepper/Scenerunner.cpp index 5ad41fa..2217864 100644 --- a/PhotoStepper/Scenerunner.cpp +++ b/PhotoStepper/Scenerunner.cpp @@ -11,10 +11,51 @@ Scenerunner::Scenerunner(LiquidCrystal *lcd, BasicStepperDriver *stepper, int pi _pin_shutter = pin_shutter; } -void Scenerunner::nextAction(){ - // TODO: implement actions +void Scenerunner::start() { _lcd->clear(); _lcd->print("Running..."); - _lcd->setCursor(0, 1); - _lcd->print("[sel] to exit"); + steps_left = nSteps; + runStep = RUN_SETTLE; + runStepStart = millis(); +} + +void Scenerunner::nextAction() { + _lcd->setCursor(0, 1); + switch (runStep) { + case RUN_OFF: + _lcd->print("rS: OFF "); + break; + case RUN_SETTLE: + _lcd->print("rS: SETTLE "); + if (millis() >= runStepStart + tSettle) { + runStep = RUN_FOCUS; + runStepStart = millis(); + } + break; + case RUN_FOCUS: + _lcd->print("rS: FOCUS "); + if (millis() >= runStepStart + tFocus) { + runStep = RUN_SHUTTER; + runStepStart = millis(); + } + break; + case RUN_SHUTTER: + _lcd->print("rS: SHUTTER "); + if (millis() >= runStepStart + tShutter) { + runStep = RUN_MOVE; + runStepStart = millis(); + } + break; + case RUN_MOVE: + _lcd->print("rS: MOVE "); + if (millis() >= runStepStart + 1234) { + // dummy wait time + runStep = RUN_SETTLE; + runStepStart = millis(); + } + break; + case RUN_RETURN: + _lcd->print("rS: RETURN "); + break; + } } diff --git a/PhotoStepper/Scenerunner.h b/PhotoStepper/Scenerunner.h index a9ab253..fb776ba 100644 --- a/PhotoStepper/Scenerunner.h +++ b/PhotoStepper/Scenerunner.h @@ -9,9 +9,9 @@ class Scenerunner { public: // configuration values - int tSettle = 100; - int tFocus = 500; - int tShutter = 500; + int tSettle = 1000; + int tFocus = 1000; + int tShutter = 1000; bool bReturn = true; bool bDarkenLcd = true; @@ -20,6 +20,7 @@ class Scenerunner { float distance = 0.5; Scenerunner(LiquidCrystal *lcd, BasicStepperDriver *stepper, int pin_focus, int pin_shutter); + void start(); void nextAction(); private: @@ -27,8 +28,11 @@ class Scenerunner { BasicStepperDriver *_stepper; int _pin_focus; int _pin_shutter; - enum RunStep { RUN_OFF, RUN_SETTLE, RUN_FOCUS, RUN_SHUTTER, RUN_RETURN }; + + int steps_left; + enum RunStep { RUN_OFF, RUN_SETTLE, RUN_FOCUS, RUN_SHUTTER, RUN_MOVE, RUN_RETURN }; RunStep runStep = RUN_OFF; + unsigned long int runStepStart; };