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;
uint32_t lastPressed = 0;
bool off = false;
bool editingConfig = false;
bool editingComment = false;
uint8_t configEditState = 0;
uint8_t commentEditState = 0;
@ -371,28 +374,25 @@ void isrAbc() {
}
void editConfig() {
uint8_t state = 0;
lcd.blink();
while (true) {
if (setPressed) {
setPressed = false;
++state;
++configEditState;
}
if (state < 6) { // callsign
lcd.setCursor(state, 0);
if (configEditState < 6) { // callsign
lcd.setCursor(configEditState, 0);
if (abcPressed) {
abcPressed = false;
for (uint8_t i = 0; i < callsignAbcLen; ++i) {
if (callsignAbc[i] == config.srcCallsign[state]) {
config.srcCallsign[state] = callsignAbc[(i+1)%callsignAbcLen];
if (callsignAbc[i] == config.srcCallsign[configEditState]) {
config.srcCallsign[configEditState] = 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;
@ -402,7 +402,7 @@ void editConfig() {
lcd.setCursor(7, 0);
}
} else if (state == 7) { // interval
} else if (configEditState == 7) { // interval
lcd.setCursor(10, 0);
if (abcPressed) {
abcPressed = false;
@ -439,7 +439,7 @@ void editConfig() {
lcd.setCursor(10, 0);
}
} else if (state == 8) { // marker
} else if (configEditState == 8) { // marker
lcd.setCursor(0, 1);
if (abcPressed) {
abcPressed = false;
@ -460,44 +460,44 @@ void editConfig() {
lcd.noBlink();
writeEepromConfig();
initFrame();
return;
}
editingConfig = false;
configEditState = 0;
}
}
void editComment() {
uint8_t state = 0;
lcd.blink();
while (true) {
if (setPressed) {
setPressed = false;
++state;
if (state >= 32) {
++commentEditState;
if (commentEditState >= 32) {
config.commentLen = 32;
lcd.noBlink();
writeEepromConfig();
editingComment = false;
commentEditState = 0;
return;
}
if (config.comment[state-1] == 255U) {
config.commentLen = state-1;
memset(config.comment + state, '\xff', 32-state);
if (config.comment[commentEditState-1] == 255U) {
config.commentLen = commentEditState-1;
memset(config.comment + commentEditState, '\xff', 32-commentEditState);
lcd.noBlink();
writeEepromConfig();
editingComment = false;
commentEditState = 0;
return;
}
}
lcd.setCursor(state%16, state/16);
lcd.setCursor(commentEditState%16, commentEditState/16);
if (abcPressed) {
abcPressed = false;
for (uint8_t i = 0; i < commentAbcLen; ++i) {
if (commentAbc[i] == config.comment[state]) {
config.comment[state] = commentAbc[(i+1)%commentAbcLen];
if (commentAbc[i] == config.comment[commentEditState]) {
config.comment[commentEditState] = commentAbc[(i+1)%commentAbcLen];
break;
}
}
lcd.print((char) config.comment[state]);
lcd.setCursor(state%16, state/16);
}
lcd.print((char) config.comment[commentEditState]);
lcd.setCursor(commentEditState%16, commentEditState/16);
}
};
@ -677,40 +677,54 @@ void setup() {
void loop() {
readNmeaRmc();
uint32_t now = millis();
if (abcPressed || setPressed) {
lastPressed = now;
}
if (off) {
if (abcPressed || setPressed) {
off = false;
abcPressed = false;
setPressed = false;
lastPressed = now;
if (editingConfig || editingComment) {
lcd.blink();
}
lcd.backlight();
lcd.on();
}
return;
} else if (now - lastPressed > 30000) {
off = true;
lcd.off();
lcd.noBlink();
lcd.noBacklight();
}
if (editingConfig) {
editConfig();
return;
}
if (editingComment) {
editComment();
return;
}
if (abcPressed) {
abcPressed = false;
page = (page + 1) % 4;
lastPressed = now;
lcd.clear();
}
if (page == 0) {
printConfig();
if (setPressed) {
setPressed = false;
lastPressed = now;
editConfig();
editingConfig = true;
lcd.blink();
}
} else if (page == 1) {
printComment();
if (setPressed) {
setPressed = false;
lastPressed = now;
editComment();
editingComment = true;
lcd.clear();
lcd.blink();
}
} else if (page == 2) {
printLocation();