From 70decbbcca420194fc144ea19fc4d1319038b8a9 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 9 Sep 2023 16:01:41 -0500 Subject: [PATCH] Only send cycles when program is running. --- vulpes/src/main.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 66a5c09..732085f 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -53,8 +53,8 @@ int yourInputMsg_old; // to save previous state and check changes float yourInputFloat; uint32_t yourInputTime; //to keep time uint32_t yourInputStartTimeUnix; -bool yourProgramRunning; -bool yourProgramRunning_old; +bool startProgram; +bool programRunning; int step_length = 30000; // 30 secs int cycle_id = 1; // number of this transmitter in cycle int n_transmitters = 2; //number of transmitters total @@ -318,7 +318,7 @@ auto morses_sequence = JLedSequence(JLedSequence::eMode::SEQUENCE, morses); //================================================================================ bool start_program(){ Serial.println("The scheduled program has started."); - yourProgramRunning = true; + startProgram = true; return false; } @@ -436,7 +436,8 @@ void setup() { yourInputSend = inputMessage.toInt(); // if not running a program, set the program running off if(yourInputSend != 2){ - yourProgramRunning = false; + startProgram = false; + programRunning = false; } } // GET inputWPM value on /get?inputWPM= @@ -538,12 +539,12 @@ void loop() { // This statement from https://github.com/garrysblog/DS3231-Alarm-With-Adafruit-RTClib-Library/blob/master/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired.ino // Check if alarm by polling SQW alarm pin - if ((yourInputSend == 2) & (digitalRead(alarmPin) == LOW)) { + if((yourInputSend == 2) & (digitalRead(alarmPin) == LOW)) { // Print current time and date DateTime now = rtc.now(); // Get the current time char buff[] = "Alarm triggered at hh:mm:ss DDD, DD MMM YYYY"; Serial.println(now.toString(buff)); - yourProgramRunning = true; + startProgram = true; // Disable and clear alarm rtc.clearAlarm(1); @@ -551,9 +552,10 @@ void loop() { } // Once alarm has started the program, set things up to run - if(yourProgramRunning == true){ + if(startProgram == true){ morses_sequence.Forever().Update(); - yourProgramRunning = false; + programRunning = true; + startProgram = false; } else // See which message we are sending // Only do this when the message has been updated. @@ -578,7 +580,7 @@ void loop() { morseToSend = morseMO5; morseToSend_blink = morseMO5_blink; } - // Keeps the key from locking up + // Keeps the key/led from locking up yourInputMsg_old = yourInputMsg; } @@ -595,22 +597,25 @@ void loop() { morseToSend_blink.Update(); // if you want to send cycle code and it is sending, keep sending - } else if((yourInputSend == 2) & (morses_sequence.Update() == true)){ + } else if((yourInputSend == 2) & (programRunning == true) &(morses_sequence.Update() == true)){ morseToSend.Update(); //morseToSend_blink.Update(); morses_sequence.Update(); // if you want to send cycle code and it's not sending, then start it up - } else if((yourInputSend == 2) & (morses_sequence.Update() == false)){ + } else if((yourInputSend == 2) & (programRunning == true) & (morses_sequence.Update() == false)){ morseToSend.Reset().Update(); //morseToSend_blink.Reset().Update(); morses_sequence.Reset(); - + // if the cycle program is not running + } else if((yourInputSend == 2 & (programRunning == false))){ + morses_sequence.Stop(); // if you don't want to send code } else { // stop sending and make sure the pin is off morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update(); morseToSend_blink.Stop(JLed::eStopMode::FULL_OFF).Update(); + morses_sequence.Stop(); } //morseToSend.Update();