feat(lcd): blank display when idle during config edit

This commit is contained in:
s3lph 2023-05-06 16:44:04 +02:00
parent eb1f1ad71c
commit ef7159689a
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5

View file

@ -224,7 +224,10 @@ 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 = false;
bool editingConfig = false;
bool editingComment = false;
uint8_t configEditState = 0;
uint8_t commentEditState = 0;
@ -371,133 +374,130 @@ void isrAbc() {
} }
void editConfig() { void editConfig() {
uint8_t state = 0; if (setPressed) {
lcd.blink(); setPressed = false;
while (true) { ++configEditState;
if (setPressed) { }
setPressed = false; if (configEditState < 6) { // callsign
++state; lcd.setCursor(configEditState, 0);
} if (abcPressed) {
if (state < 6) { // callsign abcPressed = false;
lcd.setCursor(state, 0); for (uint8_t i = 0; i < callsignAbcLen; ++i) {
if (abcPressed) { if (callsignAbc[i] == config.srcCallsign[configEditState]) {
abcPressed = false; config.srcCallsign[configEditState] = callsignAbc[(i+1)%callsignAbcLen];
for (uint8_t i = 0; i < callsignAbcLen; ++i) { break;
if (callsignAbc[i] == config.srcCallsign[state]) {
config.srcCallsign[state] = callsignAbc[(i+1)%callsignAbcLen];
break;
}
} }
lcd.print((char) config.srcCallsign[state]);
lcd.setCursor(state, 0);
} }
lcd.print((char) config.srcCallsign[configEditState]);
lcd.setCursor(configEditState, 0);
}
} else if (state == 6) { // ssid } else if (configEditState == 6) { // ssid
lcd.setCursor(7, 0);
if (abcPressed) {
abcPressed = false;
config.srcSsid = (config.srcSsid + 1) % 16;
lcd.print(config.srcSsid);
lcd.print(' ');
lcd.setCursor(7, 0); lcd.setCursor(7, 0);
if (abcPressed) {
abcPressed = false;
config.srcSsid = (config.srcSsid + 1) % 16;
lcd.print(config.srcSsid);
lcd.print(' ');
lcd.setCursor(7, 0);
}
} else if (state == 7) { // interval
lcd.setCursor(10, 0);
if (abcPressed) {
abcPressed = false;
if (config.interval < 60) {
config.interval += 10;
} else if (config.interval < 300) {
config.interval += 60;
} else if (config.interval < 1800) {
config.interval += 300;
} else if (config.interval < 3600) {
config.interval += 600;
} else if (config.interval < 43200) {
config.interval += 3600;
} else {
config.interval = 0;
}
uint16_t seconds = config.interval;
if (seconds >= 3600) {
lcd.print(seconds / 3600);
lcd.print('h');
seconds %= 3600;
}
if (seconds >= 60) {
lcd.print(seconds / 60);
lcd.print('m');
seconds %= 60;
}
if (seconds > 0 || config.interval == 0) {
lcd.print(seconds);
lcd.print('s');
}
lcd.print(emptyLine);
lcd.setCursor(10, 0);
}
} else if (state == 8) { // marker
lcd.setCursor(0, 1);
if (abcPressed) {
abcPressed = false;
char marker[17];
for (uint8_t i = 0; i < 80; ++i) {
if (pgm_read_byte(&symbolId[i]) == config.marker) {
config.marker = pgm_read_byte(&symbolId[(i+1)%80]);
strncpy_P(marker, symbolReadable[(i+1)%80], 17);
lcd.setCursor(0, 1);
lcd.print(marker);
lcd.print(emptyLine);
break;
}
}
}
} else {
lcd.noBlink();
writeEepromConfig();
initFrame();
return;
} }
} else if (configEditState == 7) { // interval
lcd.setCursor(10, 0);
if (abcPressed) {
abcPressed = false;
if (config.interval < 60) {
config.interval += 10;
} else if (config.interval < 300) {
config.interval += 60;
} else if (config.interval < 1800) {
config.interval += 300;
} else if (config.interval < 3600) {
config.interval += 600;
} else if (config.interval < 43200) {
config.interval += 3600;
} else {
config.interval = 0;
}
uint16_t seconds = config.interval;
if (seconds >= 3600) {
lcd.print(seconds / 3600);
lcd.print('h');
seconds %= 3600;
}
if (seconds >= 60) {
lcd.print(seconds / 60);
lcd.print('m');
seconds %= 60;
}
if (seconds > 0 || config.interval == 0) {
lcd.print(seconds);
lcd.print('s');
}
lcd.print(emptyLine);
lcd.setCursor(10, 0);
}
} else if (configEditState == 8) { // marker
lcd.setCursor(0, 1);
if (abcPressed) {
abcPressed = false;
char marker[17];
for (uint8_t i = 0; i < 80; ++i) {
if (pgm_read_byte(&symbolId[i]) == config.marker) {
config.marker = pgm_read_byte(&symbolId[(i+1)%80]);
strncpy_P(marker, symbolReadable[(i+1)%80], 17);
lcd.setCursor(0, 1);
lcd.print(marker);
lcd.print(emptyLine);
break;
}
}
}
} else {
lcd.noBlink();
writeEepromConfig();
initFrame();
editingConfig = false;
configEditState = 0;
} }
} }
void editComment() { void editComment() {
uint8_t state = 0; if (setPressed) {
lcd.blink(); setPressed = false;
while (true) { ++commentEditState;
if (setPressed) { if (commentEditState >= 32) {
setPressed = false; config.commentLen = 32;
++state; lcd.noBlink();
if (state >= 32) { writeEepromConfig();
config.commentLen = 32; editingComment = false;
lcd.noBlink(); commentEditState = 0;
writeEepromConfig(); return;
return; }
} if (config.comment[commentEditState-1] == 255U) {
if (config.comment[state-1] == 255U) { config.commentLen = commentEditState-1;
config.commentLen = state-1; memset(config.comment + commentEditState, '\xff', 32-commentEditState);
memset(config.comment + state, '\xff', 32-state); lcd.noBlink();
lcd.noBlink(); writeEepromConfig();
writeEepromConfig(); editingComment = false;
return; commentEditState = 0;
return;
}
}
lcd.setCursor(commentEditState%16, commentEditState/16);
if (abcPressed) {
abcPressed = false;
for (uint8_t i = 0; i < commentAbcLen; ++i) {
if (commentAbc[i] == config.comment[commentEditState]) {
config.comment[commentEditState] = commentAbc[(i+1)%commentAbcLen];
break;
} }
} }
lcd.setCursor(state%16, state/16); lcd.print((char) config.comment[commentEditState]);
if (abcPressed) { lcd.setCursor(commentEditState%16, commentEditState/16);
abcPressed = false;
for (uint8_t i = 0; i < commentAbcLen; ++i) {
if (commentAbc[i] == config.comment[state]) {
config.comment[state] = commentAbc[(i+1)%commentAbcLen];
break;
}
}
lcd.print((char) config.comment[state]);
lcd.setCursor(state%16, state/16);
}
} }
}; };
@ -677,40 +677,54 @@ void setup() {
void loop() { void loop() {
readNmeaRmc(); readNmeaRmc();
uint32_t now = millis(); uint32_t now = millis();
if (abcPressed || setPressed) {
lastPressed = now;
}
if (off) { if (off) {
if (abcPressed || setPressed) { if (abcPressed || setPressed) {
off = false; off = false;
abcPressed = false; abcPressed = false;
setPressed = false; setPressed = false;
lastPressed = now; if (editingConfig || editingComment) {
lcd.blink();
}
lcd.backlight(); lcd.backlight();
lcd.on(); lcd.on();
} }
return;
} else if (now - lastPressed > 30000) { } else if (now - lastPressed > 30000) {
off = true; off = true;
lcd.off(); lcd.off();
lcd.noBlink();
lcd.noBacklight(); lcd.noBacklight();
} }
if (editingConfig) {
editConfig();
return;
}
if (editingComment) {
editComment();
return;
}
if (abcPressed) { if (abcPressed) {
abcPressed = false; abcPressed = false;
page = (page + 1) % 4; page = (page + 1) % 4;
lastPressed = now;
lcd.clear(); lcd.clear();
} }
if (page == 0) { if (page == 0) {
printConfig(); printConfig();
if (setPressed) { if (setPressed) {
setPressed = false; setPressed = false;
lastPressed = now; editingConfig = true;
editConfig(); lcd.blink();
} }
} else if (page == 1) { } else if (page == 1) {
printComment(); printComment();
if (setPressed) { if (setPressed) {
setPressed = false; setPressed = false;
lastPressed = now; editingComment = true;
editComment();
lcd.clear(); lcd.clear();
lcd.blink();
} }
} else if (page == 2) { } else if (page == 2) {
printLocation(); printLocation();