feat(lcd): blank display when idle during config edit
This commit is contained in:
parent
eb1f1ad71c
commit
ef7159689a
1 changed files with 137 additions and 123 deletions
86
src/main.cpp
86
src/main.cpp
|
@ -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,28 +374,25 @@ void isrAbc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void editConfig() {
|
void editConfig() {
|
||||||
uint8_t state = 0;
|
|
||||||
lcd.blink();
|
|
||||||
while (true) {
|
|
||||||
if (setPressed) {
|
if (setPressed) {
|
||||||
setPressed = false;
|
setPressed = false;
|
||||||
++state;
|
++configEditState;
|
||||||
}
|
}
|
||||||
if (state < 6) { // callsign
|
if (configEditState < 6) { // callsign
|
||||||
lcd.setCursor(state, 0);
|
lcd.setCursor(configEditState, 0);
|
||||||
if (abcPressed) {
|
if (abcPressed) {
|
||||||
abcPressed = false;
|
abcPressed = false;
|
||||||
for (uint8_t i = 0; i < callsignAbcLen; ++i) {
|
for (uint8_t i = 0; i < callsignAbcLen; ++i) {
|
||||||
if (callsignAbc[i] == config.srcCallsign[state]) {
|
if (callsignAbc[i] == config.srcCallsign[configEditState]) {
|
||||||
config.srcCallsign[state] = callsignAbc[(i+1)%callsignAbcLen];
|
config.srcCallsign[configEditState] = callsignAbc[(i+1)%callsignAbcLen];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd.print((char) config.srcCallsign[state]);
|
lcd.print((char) config.srcCallsign[configEditState]);
|
||||||
lcd.setCursor(state, 0);
|
lcd.setCursor(configEditState, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == 6) { // ssid
|
} else if (configEditState == 6) { // ssid
|
||||||
lcd.setCursor(7, 0);
|
lcd.setCursor(7, 0);
|
||||||
if (abcPressed) {
|
if (abcPressed) {
|
||||||
abcPressed = false;
|
abcPressed = false;
|
||||||
|
@ -402,7 +402,7 @@ void editConfig() {
|
||||||
lcd.setCursor(7, 0);
|
lcd.setCursor(7, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == 7) { // interval
|
} else if (configEditState == 7) { // interval
|
||||||
lcd.setCursor(10, 0);
|
lcd.setCursor(10, 0);
|
||||||
if (abcPressed) {
|
if (abcPressed) {
|
||||||
abcPressed = false;
|
abcPressed = false;
|
||||||
|
@ -439,7 +439,7 @@ void editConfig() {
|
||||||
lcd.setCursor(10, 0);
|
lcd.setCursor(10, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == 8) { // marker
|
} else if (configEditState == 8) { // marker
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
if (abcPressed) {
|
if (abcPressed) {
|
||||||
abcPressed = false;
|
abcPressed = false;
|
||||||
|
@ -460,44 +460,44 @@ void editConfig() {
|
||||||
lcd.noBlink();
|
lcd.noBlink();
|
||||||
writeEepromConfig();
|
writeEepromConfig();
|
||||||
initFrame();
|
initFrame();
|
||||||
return;
|
editingConfig = false;
|
||||||
}
|
configEditState = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void editComment() {
|
void editComment() {
|
||||||
uint8_t state = 0;
|
|
||||||
lcd.blink();
|
|
||||||
while (true) {
|
|
||||||
if (setPressed) {
|
if (setPressed) {
|
||||||
setPressed = false;
|
setPressed = false;
|
||||||
++state;
|
++commentEditState;
|
||||||
if (state >= 32) {
|
if (commentEditState >= 32) {
|
||||||
config.commentLen = 32;
|
config.commentLen = 32;
|
||||||
lcd.noBlink();
|
lcd.noBlink();
|
||||||
writeEepromConfig();
|
writeEepromConfig();
|
||||||
|
editingComment = false;
|
||||||
|
commentEditState = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (config.comment[state-1] == 255U) {
|
if (config.comment[commentEditState-1] == 255U) {
|
||||||
config.commentLen = state-1;
|
config.commentLen = commentEditState-1;
|
||||||
memset(config.comment + state, '\xff', 32-state);
|
memset(config.comment + commentEditState, '\xff', 32-commentEditState);
|
||||||
lcd.noBlink();
|
lcd.noBlink();
|
||||||
writeEepromConfig();
|
writeEepromConfig();
|
||||||
|
editingComment = false;
|
||||||
|
commentEditState = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd.setCursor(state%16, state/16);
|
lcd.setCursor(commentEditState%16, commentEditState/16);
|
||||||
if (abcPressed) {
|
if (abcPressed) {
|
||||||
abcPressed = false;
|
abcPressed = false;
|
||||||
for (uint8_t i = 0; i < commentAbcLen; ++i) {
|
for (uint8_t i = 0; i < commentAbcLen; ++i) {
|
||||||
if (commentAbc[i] == config.comment[state]) {
|
if (commentAbc[i] == config.comment[commentEditState]) {
|
||||||
config.comment[state] = commentAbc[(i+1)%commentAbcLen];
|
config.comment[commentEditState] = commentAbc[(i+1)%commentAbcLen];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd.print((char) config.comment[state]);
|
lcd.print((char) config.comment[commentEditState]);
|
||||||
lcd.setCursor(state%16, state/16);
|
lcd.setCursor(commentEditState%16, commentEditState/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();
|
||||||
|
|
Loading…
Reference in a new issue