diff --git a/src/main.cpp b/src/main.cpp index a9cc673..766ec25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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,133 +374,130 @@ void isrAbc() { } void editConfig() { - uint8_t state = 0; - lcd.blink(); - while (true) { - if (setPressed) { - setPressed = false; - ++state; - } - if (state < 6) { // callsign - lcd.setCursor(state, 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]; - break; - } + if (setPressed) { + setPressed = false; + ++configEditState; + } + 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[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; + config.srcSsid = (config.srcSsid + 1) % 16; + lcd.print(config.srcSsid); + lcd.print(' '); 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() { - uint8_t state = 0; - lcd.blink(); - while (true) { - if (setPressed) { - setPressed = false; - ++state; - if (state >= 32) { - config.commentLen = 32; - lcd.noBlink(); - writeEepromConfig(); - return; - } - if (config.comment[state-1] == 255U) { - config.commentLen = state-1; - memset(config.comment + state, '\xff', 32-state); - lcd.noBlink(); - writeEepromConfig(); - return; + if (setPressed) { + setPressed = false; + ++commentEditState; + if (commentEditState >= 32) { + config.commentLen = 32; + lcd.noBlink(); + writeEepromConfig(); + editingComment = false; + commentEditState = 0; + return; + } + 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(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); - 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]; - 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();