From cbdc7ec939da54c4e00ee7a2b29fa33a778651f0 Mon Sep 17 00:00:00 2001 From: mattbk Date: Fri, 8 Sep 2023 15:00:48 -0500 Subject: [PATCH] Use Alarm2 instead of Alarm2 to avoid late alarms. --- vulpes/src/main.cpp | 50 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 5e54d7e..ab78e07 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -116,7 +116,7 @@ const char index_html[] PROGMEM = R"rawliteral(
Message (current value %inputMsg%): @@ -129,8 +129,10 @@ const char index_html[] PROGMEM = R"rawliteral(

-

Program start time
- Current value: +

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". + You cannot set a cycle start date more than a month in advance.

@@ -437,10 +439,10 @@ void setup() { } // Are there any RTC alarms set? - DateTime alarm_two = rtc.getAlarm2(); // Get the current time - char buff[] = "Alarm 2 set for at hh:mm:ss DDD, DD MMM YYYY"; - Serial.print(alarm_two.toString(buff)); - Serial.println(" (only accurate to day of month)"); + DateTime alarm_one = rtc.getAlarm1(); // Get the current time + char buff[] = "Alarm 1 set for at hh:mm:ss DDD, DD MMM YYYY"; + Serial.print(alarm_one.toString(buff)); + Serial.println(" (only HH:MM:SS day-of-month are accurate)"); // Timer example, blink main LED pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT @@ -575,14 +577,17 @@ void setup() { Serial.println(yourInputTime); // update the RTC time rtc.adjust(DateTime(yourInputTime)); + DateTime now = rtc.now(); // Might work to fix random errors? If date is far in the future, // try to update again. - while(rtc.now().year() > 2040){ + // replace if with while if you want it to try a bunch... + if(now.year() > 2040){ + Serial.print("Year is "); + Serial.println(now.year()); Serial.println("RTC can't set time. Trying again."); rtc.adjust(DateTime(yourInputTime)); } -; - DateTime now = rtc.now(); + Serial.print("UTC time from browser: "); Serial.print(now.year(), DEC); Serial.print('/'); @@ -627,12 +632,12 @@ void setup() { // Serial.println(active_tasks); // Use alarm built into RTC - rtc.setAlarm2(DateTime(yourInputStartTimeUnix), DS3231_A2_Date); + rtc.setAlarm1(DateTime(yourInputStartTimeUnix), DS3231_A1_Date); //rtc.setAlarm1(DateTime(2020, 6, 25, 15, 34, 0), DS3231_A2_Date); - DateTime alarm_two = rtc.getAlarm2(); // Get the current time - char buff[] = "Alarm 2 set for at hh:mm:ss DDD, DD MMM YYYY"; - Serial.print(alarm_two.toString(buff)); - Serial.println(" (only accurate to day of month)"); + DateTime alarm_one = rtc.getAlarm1(); // Get the current alarm time + char buff[] = "Alarm 1 set for at hh:mm:ss DDD, DD MMM YYYY"; + Serial.print(alarm_one.toString(buff)); + Serial.println(" (only HH:MM:SS day-of-month are accurate)"); } // else { // inputMessage = "No message sent"; @@ -659,20 +664,17 @@ void loop() { // Timers timer.tick(); - // This function 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 by using alarmFired - // We don't want old alarms, though. - //& (rtc.getAlarm2() >= rtc.now()) - // if ((rtc.alarmFired(2) == 1) ){ - if (digitalRead(alarmPin) == LOW) { - + // 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)); // Disable and clear alarm - rtc.clearAlarm(2); + rtc.clearAlarm(1); + rtc.clearAlarm(2); // clear the other one just in case } // DateTime now = rtc.now(); @@ -742,7 +744,7 @@ void loop() { morseToSend_blink.Update(); // if you want to send cycle code and it's not sending, then start it up - } else if((yourInputSend == 2) & (morseToSend.IsRunning() == true)){ + } else if((yourInputSend == 2) & (morseToSend.IsRunning() == false)){ morseToSend.Reset().Update(); morseToSend_blink.Reset().Update();