From 486715dd5f9e381eaf2e7183ca735703ba3b5125 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 7 May 2023 23:24:58 +0200 Subject: [PATCH] feat: save more power by disabling timer, and use gps time for tx interval instead --- src/main.cpp | 54 ++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 67429da..e1909d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -606,8 +606,15 @@ void readNmeaRmc() { } } } - uint32_t now = millis(); - if ((rmc.valid || SEND_INVALID) && ((now - lastBroadcast) / 1000 > config.interval || lastBroadcast == 0)) { + if (rmc.valid || SEND_INVALID) { + uint32_t now; + now = ((rmc.time[0] - '0') * 10 + (rmc.time[1] - '0')) * 3600; // h + now += ((rmc.time[2] - '0') * 10 + (rmc.time[3] - '0')) * 60; // m + now += ((rmc.time[4] - '0') * 10 + (rmc.time[5] - '0')); // s + uint32_t interval = (((now - lastBroadcast) % 86400) + 86400) % 86400; + if (interval < config.interval) { + return; + } lastBroadcast = now; char aprs[256]; if (rmc.valid) { @@ -695,34 +702,6 @@ void setup() { void loop() { readNmeaRmc(); - uint32_t now = millis(); -#ifdef GPSM_L80R - // L80-R: Wake up the module if config.interval has expired - wakeup happens on any serial activity - if ((now - lastBroadcast) > config.interval) { - Serial.print("\r"); - Serial.flush(); - } -#endif - if (abcPressed || setPressed) { - lastPressed = now; - } - if (off) { - if (abcPressed || setPressed) { - off = false; - abcPressed = false; - setPressed = false; - if (editingConfig || editingComment) { - lcd.blink(); - } - lcd.backlight(); - lcd.display(); - } - } else { - if (now - lastPressed > 30000) { - off = true; - lcd.noDisplay(); - lcd.noBacklight(); - } if (editingConfig) { editConfig(); return; @@ -756,6 +735,19 @@ void loop() { } else if (page == 3) { printDateTime(); } + LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); + if (!abcPressed && !setPressed) { + off = true; + lcd.noDisplay(); + lcd.noBacklight(); + } else if (off) { + off = false; + abcPressed = false; + setPressed = false; + if (editingConfig || editingComment) { + lcd.blink(); + } + lcd.backlight(); + lcd.display(); } - LowPower.idle(SLEEP_FOREVER, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_ON, TWI_OFF); }