fix: idle mode was not always activated

This commit is contained in:
s3lph 2023-05-07 02:16:59 +02:00
parent 4ea4d52be0
commit f6fbc29fde
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
2 changed files with 59 additions and 35 deletions

View file

@ -15,6 +15,7 @@ framework = arduino
lib_deps =
https://github.com/marcoschwartz/LiquidCrystal_I2C
https://github.com/rocketscream/Low-Power
build_flags = -DGPSM_UBLOX6
upload_protocol = custom
upload_flags =
-C

View file

@ -529,6 +529,11 @@ void readNmeaRmc() {
}
}
if (nmeaState == 2) {
#ifdef GPSM_L80R
// L80-R: Send GPS module into standby mode
Serial.println("$PMTK161,0*28");
Serial.flush();
#endif
char buf[16];
char *bptr = buf;
uint8_t counter = 0;
@ -642,6 +647,7 @@ void readNmeaRmc() {
}
void setup() {
#if defined(GPSM_UBLOX6)
Serial.begin(9600);
// ublox NEO-6M: Switch to low-power on-off mode with peak current limiting - not sure if this actually works
Serial.print("\xb5\x62\x06\x3b\x2c\x00\x01\x06\x00\x00\x0e\x81\x00\x00\x60\xea\x00\x00\x10\x27\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x2c\x01\x00\x00\x4f\xc1\x03\x00\x86\x02\x00\x00\xfe\x00\x00\x00\x64\x40\x01\x00\xf1\xd5");
@ -653,6 +659,15 @@ void setup() {
Serial.println("$PUBX,40,VTG,0,0,0,0,0,0*5E");
Serial.println("$PUBX,40,GGA,0,0,0,0,0,0*5A");
Serial.flush();
#elif defined(GPSM_L80R)
Serial.begin(9600);
// L80-R: Disable all NMEA sentences except for GPRMC
Serial.println("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
Serial.flush();
#else
// Assume NMEA-0183 default baud rate of 4800
Serial.begin(4800);
#endif
OUT_DDR |= 0x0f;
pinMode(PTT, OUTPUT);
digitalWrite(PTT, LOW);
@ -675,6 +690,13 @@ 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;
}
@ -689,44 +711,45 @@ void loop() {
lcd.backlight();
lcd.display();
}
return;
} else if (now - lastPressed > 30000) {
off = true;
lcd.noDisplay();
lcd.noBacklight();
}
if (editingConfig) {
editConfig();
return;
}
if (editingComment) {
editComment();
return;
}
if (abcPressed) {
abcPressed = false;
page = (page + 1) % 4;
lcd.clear();
}
if (page == 0) {
printConfig();
if (setPressed) {
setPressed = false;
editingConfig = true;
lcd.blink();
} else {
if (now - lastPressed > 30000) {
off = true;
lcd.noDisplay();
lcd.noBacklight();
}
} else if (page == 1) {
printComment();
if (setPressed) {
setPressed = false;
editingComment = true;
if (editingConfig) {
editConfig();
return;
}
if (editingComment) {
editComment();
return;
}
if (abcPressed) {
abcPressed = false;
page = (page + 1) % 4;
lcd.clear();
lcd.blink();
}
} else if (page == 2) {
printLocation();
} else if (page == 3) {
printDateTime();
if (page == 0) {
printConfig();
if (setPressed) {
setPressed = false;
editingConfig = true;
lcd.blink();
}
} else if (page == 1) {
printComment();
if (setPressed) {
setPressed = false;
editingComment = true;
lcd.clear();
lcd.blink();
}
} else if (page == 2) {
printLocation();
} else if (page == 3) {
printDateTime();
}
}
LowPower.idle(SLEEP_FOREVER, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_ON, TWI_OFF);
}