diff --git a/firmware/src/customize.cpp b/firmware/src/customize.cpp index ce24a82..6ca841f 100644 --- a/firmware/src/customize.cpp +++ b/firmware/src/customize.cpp @@ -4,18 +4,52 @@ void customize_setup(); -void customize() { - while (true) { - customize_setup(); - float wireDiameter = number_input(-1, 0.1); - tick(); - Serial.println(wireDiameter); - } -} +float wireDiameter = -1; +float coreLength = -1; -void customize_setup() { +void customize() { +setup: + wireDiameter = -1; + coreLength = -1; + +wireDiameterStep: lcd.clear(); lcd.print("Wire diameter:"); lcd.setCursor(14, 1); lcd.print("mm"); + + float inputWireDiameter = number_input(wireDiameter, 0.1); + tick(); + if (inputWireDiameter == NUMBER_INPUT_BACK) { + return; + } else { + wireDiameter = inputWireDiameter; + Serial.print("Selected wire diameter: "); + Serial.println(wireDiameter); + } + +coreLengthStep: + lcd.clear(); + lcd.print("Core length:"); + lcd.setCursor(14, 1); + lcd.print("mm"); + + float inputCoreLength = number_input(coreLength, 0.1); + tick(); + if (inputCoreLength == NUMBER_INPUT_BACK) { + goto wireDiameterStep; + } else { + coreLength = inputCoreLength; + Serial.print("Selected core length: "); + Serial.println(coreLength); + } + + + lcd.clear(); + lcd.print("Customization done"); + delay(1000); +} + +void customize_setup() { + } diff --git a/firmware/src/number_input.cpp b/firmware/src/number_input.cpp index 6a3fa07..9fc3797 100644 --- a/firmware/src/number_input.cpp +++ b/firmware/src/number_input.cpp @@ -2,6 +2,7 @@ #include "buzzer.h" #include "screen.h" #include "characters.h" +#include "number_input.h" String numberInput = ""; int8_t dotPosition = -1; @@ -48,7 +49,14 @@ float number_input(float defaultValue, float encoderStep) { auto len = numberInput.length(); bool isAtLength = len >= MAX_LENGTH; - if (input.key) { + if (input.key == KEY_C || input.switchEvent == SWITCH_RELEASED) { + if (numberInput.length() > 0) { + lcd.noCursor(); + return numberInput.toFloat(); + } else { + beep(); + } + } else if (input.key) { auto digit = getPressedDigit(input.key); if (digit != -1) { // append digit (if it fits) @@ -81,9 +89,8 @@ float number_input(float defaultValue, float encoderStep) { beep(); } } else if (input.key == KEY_B) { - goto on_back; - } else if (input.key == KEY_C) { - goto on_continue; + lcd.noCursor(); + return NUMBER_INPUT_BACK; } else { beep(); } @@ -117,19 +124,10 @@ float number_input(float defaultValue, float encoderStep) { number_input_update(); } else if (input.switchEvent == SWITCH_RELEASED) { - goto on_continue; } else if (input.hasInput && input.switchEvent != SWITCH_PRESSED) { beep(); } } - -on_continue: - lcd.noCursor(); - return numberInput.length() ? numberInput.toFloat() : -1; - -on_back: - lcd.noCursor(); - return -1; } diff --git a/firmware/src/number_input.h b/firmware/src/number_input.h index e24de76..4084ca1 100644 --- a/firmware/src/number_input.h +++ b/firmware/src/number_input.h @@ -1,5 +1,7 @@ #pragma once +#define NUMBER_INPUT_BACK -1 + /** * Uses second row of the screen, keyboard, and encoder to get a number from the user. * @@ -9,7 +11,7 @@ * defaultValue will be truncated to at most 3 decimal places. * * It will return the number when it's confirmed by encoder press or [C]ontinue. - * It will return -1 if [B]ack is pressed. + * It will return NUMBER_INPUT_BACK if [B]ack is pressed. * * LCD is set to .noCursor() before returning. */