From 958e71513cfe3647fcaa0448e782f77be51fd33d Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 10 Sep 2023 12:35:02 -0500 Subject: [PATCH] Snapshot. --- vulpes/src/main.cpp | 136 +++++++++++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 40 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 732085f..a1491e6 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -43,6 +43,9 @@ const char* PARAM_FLOAT = "inputFloat"; const char* PARAM_TIME = "inputTimeUnix"; const char* PARAM_START = "inputStartTimeUnix"; const char* PARAM_RUNNING = "programRunning"; +const char* PARAM_STEPLENGTH = "inputStepLength"; +const char* PARAM_CYCLEID = "inputCycleID"; +const char* PARAM_NTRANS = "inputNtransmitters"; // Global variables String yourInputString; @@ -55,7 +58,10 @@ uint32_t yourInputTime; //to keep time uint32_t yourInputStartTimeUnix; bool startProgram; bool programRunning; -int step_length = 30000; // 30 secs +int yourInputStepLength; +int yourInputCycleID; +int yourInputNtransmitters; +int step_length = 10000; // 10 secs int cycle_id = 1; // number of this transmitter in cycle int n_transmitters = 2; //number of transmitters total @@ -107,19 +113,19 @@ const char index_html[] PROGMEM = R"rawliteral( } - +

Vulpes Radio Orienteering Controller

Local time:

- -

Sending program (cycle doesn't work yet) (current value: %inputSend%): +

General Settings

+

Sending program:
- Message (current value %inputMsg%): + Message:

+

Cycle Settings

Cycle start time
Current value: , but only day-of-month HH:MM:SS are used. Only applies when Sending Program is set to "2 - Cycle". @@ -136,6 +143,11 @@ const char index_html[] PROGMEM = R"rawliteral(

+

+ Step length:
+ Cycle ID:
+ Number of transmitters:
+

@@ -221,6 +233,15 @@ String processor(const String& var){ else if(var == "inputMsg"){ return readFile(SPIFFS, "/inputMsg.txt"); } + else if(var == "inputStepLength"){ + return readFile(SPIFFS, "/inputStepLength.txt"); + } + else if(var == "inputCycleID"){ + return readFile(SPIFFS, "/inputCycleID.txt"); + } + else if(var == "inputNtransmitters"){ + return readFile(SPIFFS, "/inputNtransmitters.txt"); + } else if(var == "inputFloat"){ return readFile(SPIFFS, "/inputFloat.txt"); } else if(var == "inputStartTimeUnix"){ @@ -304,14 +325,14 @@ int period = morse_cycle.Period(); int repeats = step_length / period; int remainder_wait = step_length - (period * repeats); int total_wait = ((step_length * (n_transmitters - 1) + remainder_wait)); -JLed morses[] = { +JLed morses_blink[] = { // WOW it looks like you can't do Repeat() and DelayAfter() at the same time? // Opened https://github.com/jandelgado/jled/issues/122 JLed(blinker).UserFunc(&morse_cycle).Repeat(repeats), //JLed(blinker).FadeOn(1000).Repeat(3) JLed(blinker).Off(total_wait) }; -auto morses_sequence = JLedSequence(JLedSequence::eMode::SEQUENCE, morses); +auto morses_sequence_blink = JLedSequence(JLedSequence::eMode::SEQUENCE, morses_blink); //================================================================================ // start_program(): a function to start the planned program at the planned time @@ -328,9 +349,6 @@ bool start_program(){ void setup() { Serial.begin(115200); - Serial.print("morseEffectTEST.Period(): "); - Serial.println(morseEffectTEST.Period()); - pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup if (! rtc.begin()) { @@ -349,6 +367,11 @@ void setup() { //rtc.adjust(DateTime(2023, 9, 2, 17, 32, 0)); } + // Report the RTC time + Serial.print("RTC time on startup: "); + Serial.println(rtc.now().unixtime()); + Serial.println(rtc.now().timestamp()); + // Are there any RTC alarms set? DateTime alarm_one = rtc.getAlarm1(); // Get the current time char buff[] = "Alarm 1 set for at hh:mm:ss DDD, DD MMM YYYY"; @@ -373,8 +396,6 @@ void setup() { return; } - - // Read in existing data yourInputString = readFile(SPIFFS, "/inputString.txt"); yourInputSend = readFile(SPIFFS, "/inputSend.txt").toInt(); @@ -382,6 +403,9 @@ void setup() { yourInputMsg = readFile(SPIFFS, "/inputMsg.txt").toInt(); yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat(); yourInputStartTimeUnix = readFile(SPIFFS, "/inputStartTimeUnix.txt").toInt(); + yourInputStepLength = readFile(SPIFFS, "/inputStepLength.txt").toInt(); + yourInputCycleID = readFile(SPIFFS, "/inputCycleID.txt").toInt(); + yourInputNtransmitters = readFile(SPIFFS, "/inputNtransmitters.txt").toInt(); // On restart, keep doing what you were doing before yourInputMsg_old = yourInputMsg; @@ -454,6 +478,24 @@ void setup() { yourInputMsg_old = yourInputMsg; yourInputMsg = inputMessage.toInt(); } + // GET inputStepLength value on /get?inputStepLength= + if (request->hasParam(PARAM_STEPLENGTH)) { + inputMessage = request->getParam(PARAM_STEPLENGTH)->value(); + writeFile(SPIFFS, "/inputStepLength.txt", inputMessage.c_str()); + yourInputStepLength = inputMessage.toInt(); + } + // GET inputCycleID value on /get?inputCycleID= + if (request->hasParam(PARAM_CYCLEID)) { + inputMessage = request->getParam(PARAM_CYCLEID)->value(); + writeFile(SPIFFS, "/inputCycleID.txt", inputMessage.c_str()); + yourInputCycleID = inputMessage.toInt(); + } + // GET inputNtransmitters value on /get?inputNtransmitters= + if (request->hasParam(PARAM_NTRANS)) { + inputMessage = request->getParam(PARAM_NTRANS)->value(); + writeFile(SPIFFS, "/inputNtransmitters.txt", inputMessage.c_str()); + yourInputNtransmitters = inputMessage.toInt(); + } // GET inputTimeUnix value on /get?inputTimeUnix= if (request->hasParam(PARAM_TIME)) { inputMessage = request->getParam(PARAM_TIME)->value(); @@ -537,27 +579,7 @@ void loop() { // Timers timer.tick(); - // 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)) { - // 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)); - startProgram = true; - - // Disable and clear alarm - rtc.clearAlarm(1); - rtc.clearAlarm(2); // clear the other one just in case - } - - // Once alarm has started the program, set things up to run - if(startProgram == true){ - morses_sequence.Forever().Update(); - programRunning = true; - startProgram = false; - } else - // See which message we are sending +// See which message we are sending // Only do this when the message has been updated. if(yourInputMsg != yourInputMsg_old){ //morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update(); @@ -584,6 +606,40 @@ void loop() { yourInputMsg_old = yourInputMsg; } + // 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)) { + // 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)); + startProgram = true; + + // Disable and clear alarm + rtc.clearAlarm(1); + rtc.clearAlarm(2); // clear the other one just in case + } + + // Once alarm has started the program, set things up to run + if(startProgram == true){ + //auto morse_cycle = morseEffectMOS; + int period = morse_cycle.Period(); + int repeats = step_length / period; + int remainder_wait = step_length - (period * repeats); + int total_wait = ((step_length * (n_transmitters - 1) + remainder_wait)); + JLed morses_blink[] = { + // WOW it looks like you can't do Repeat() and DelayAfter() at the same time? + // Opened https://github.com/jandelgado/jled/issues/122 + JLed(blinker).UserFunc(&morse_cycle).Repeat(repeats), + //JLed(blinker).FadeOn(1000).Repeat(3) + JLed(blinker).Off(total_wait) + }; + auto morses_sequence_blink = JLedSequence(JLedSequence::eMode::SEQUENCE, morses_blink); + + morses_sequence_blink.Forever().Update(); + programRunning = true; + startProgram = false; + } // if you want to send continuous code, and it's not sending, then start it up if((yourInputSend == 1) & (morseToSend.IsRunning() == false)){ @@ -597,25 +653,25 @@ void loop() { morseToSend_blink.Update(); // if you want to send cycle code and it is sending, keep sending - } else if((yourInputSend == 2) & (programRunning == true) &(morses_sequence.Update() == true)){ + } else if((yourInputSend == 2) & (programRunning == true) &(morses_sequence_blink.Update() == true)){ morseToSend.Update(); //morseToSend_blink.Update(); - morses_sequence.Update(); + morses_sequence_blink.Update(); // if you want to send cycle code and it's not sending, then start it up - } else if((yourInputSend == 2) & (programRunning == true) & (morses_sequence.Update() == false)){ + } else if((yourInputSend == 2) & (programRunning == true) & (morses_sequence_blink.Update() == false)){ morseToSend.Reset().Update(); //morseToSend_blink.Reset().Update(); - morses_sequence.Reset(); + morses_sequence_blink.Reset(); // if the cycle program is not running - } else if((yourInputSend == 2 & (programRunning == false))){ - morses_sequence.Stop(); + } else if((yourInputSend == 2) & (programRunning == false)){ + morses_sequence_blink.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(); + morses_sequence_blink.Stop(); } //morseToSend.Update();