feat: power saving

This commit is contained in:
s3lph 2023-05-06 22:42:44 +02:00
parent ef7159689a
commit 970868457d
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
2 changed files with 10 additions and 11 deletions

View file

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

View file

@ -6,6 +6,7 @@
#include <Wire.h> #include <Wire.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <LowPower.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#define OUT_PORT PORTC #define OUT_PORT PORTC
@ -223,7 +224,7 @@ volatile bool setPressed = false;
volatile bool abcPressed = false; volatile bool abcPressed = false;
uint8_t page = 0; uint8_t page = 0;
uint32_t lastPressed = 0; uint32_t lastPressed = 0;
bool off = false; bool off = true;
bool editingConfig = false; bool editingConfig = false;
bool editingComment = false; bool editingComment = false;
uint8_t configEditState = 0; uint8_t configEditState = 0;
@ -525,8 +526,6 @@ void readNmeaRmc() {
} else { } else {
nmeaState = 0; nmeaState = 0;
} }
Serial.println(nmeaStr);
Serial.flush();
} }
} }
if (nmeaState == 2) { if (nmeaState == 2) {
@ -612,7 +611,6 @@ void readNmeaRmc() {
} }
memcpy(aprs+34, config.comment, config.commentLen); memcpy(aprs+34, config.comment, config.commentLen);
aprs[34+config.commentLen] = 0; aprs[34+config.commentLen] = 0;
Serial.println(aprs);
// AX.25 3.8 - FCS is sent MSB first // AX.25 3.8 - FCS is sent MSB first
uint16_t fcs = 0xffff; uint16_t fcs = 0xffff;
for (size_t i = 0; i < sizeof(frame); ++i) { for (size_t i = 0; i < sizeof(frame); ++i) {
@ -645,6 +643,9 @@ void readNmeaRmc() {
void setup() { void setup() {
Serial.begin(9600); 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");
Serial.flush();
// ublox NEO-6M: Disable all NMEA sentences except for GPTXT and GPRMC // ublox NEO-6M: Disable all NMEA sentences except for GPTXT and GPRMC
Serial.println("$PUBX,40,GLL,0,0,0,0,0,0*5C"); Serial.println("$PUBX,40,GLL,0,0,0,0,0,0*5C");
Serial.println("$PUBX,40,GSV,0,0,0,0,0,0*59"); Serial.println("$PUBX,40,GSV,0,0,0,0,0,0*59");
@ -652,9 +653,6 @@ void setup() {
Serial.println("$PUBX,40,VTG,0,0,0,0,0,0*5E"); 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.println("$PUBX,40,GGA,0,0,0,0,0,0*5A");
Serial.flush(); Serial.flush();
// 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\x91\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\x01\x45");
Serial.flush();
OUT_DDR |= 0x0f; OUT_DDR |= 0x0f;
pinMode(PTT, OUTPUT); pinMode(PTT, OUTPUT);
digitalWrite(PTT, LOW); digitalWrite(PTT, LOW);
@ -668,7 +666,7 @@ void setup() {
attachInterrupt(digitalPinToInterrupt(2), isrSet, FALLING); attachInterrupt(digitalPinToInterrupt(2), isrSet, FALLING);
attachInterrupt(digitalPinToInterrupt(3), isrAbc, FALLING); attachInterrupt(digitalPinToInterrupt(3), isrAbc, FALLING);
lcd.init(); lcd.init();
lcd.backlight(); lcd.noDisplay();
setPressed = false; setPressed = false;
abcPressed = false; abcPressed = false;
} }
@ -689,13 +687,12 @@ void loop() {
lcd.blink(); lcd.blink();
} }
lcd.backlight(); lcd.backlight();
lcd.on(); lcd.display();
} }
return; return;
} else if (now - lastPressed > 30000) { } else if (now - lastPressed > 30000) {
off = true; off = true;
lcd.off(); lcd.noDisplay();
lcd.noBlink();
lcd.noBacklight(); lcd.noBacklight();
} }
if (editingConfig) { if (editingConfig) {
@ -731,4 +728,5 @@ void loop() {
} else if (page == 3) { } else if (page == 3) {
printDateTime(); printDateTime();
} }
LowPower.idle(SLEEP_FOREVER, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_ON, TWI_OFF);
} }