diff --git a/UI.hpp b/UI.hpp index a0fd61e..318a7a3 100644 --- a/UI.hpp +++ b/UI.hpp @@ -98,7 +98,7 @@ extern char g_bank_name[NUM_DEXED][BANK_NAME_LEN]; ************************************************************************/ elapsedMillis back_from_volume; uint8_t instance_num[8][8]; -char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +const char accepted_chars[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-abcdefghijklmnopqrstuvwxyz"; #ifdef I2C_DISPLAY #include @@ -256,6 +256,7 @@ void UI_func_eq_treble(uint8_t param); void UI_function_not_enabled(void); void UI_function_not_implemented(uint8_t param); bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool init); +uint8_t search_accepted_char(uint8_t c); void lcd_display_int(int16_t var, uint8_t size, bool zeros, bool brackets, bool sign); void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign); void lcd_display_bar_int(const char* title, uint32_t value, float factor, int32_t min_value, int32_t max_value, uint8_t size, bool zeros, bool sign, bool init); @@ -5081,6 +5082,7 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i { static int8_t edit_pos; static bool edit_mode; + static uint8_t edit_value; if (init == true) { @@ -5088,6 +5090,7 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i lcd.print(edit_string); edit_mode = false; edit_pos = 0; + edit_value = search_accepted_char(edit_string[edit_pos]); lcd.setCursor(x, y); return (false); } @@ -5098,7 +5101,12 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i { if (edit_mode == true) { - edit_string[edit_pos] = constrain(edit_string[edit_pos] + 1, 32, 126); + edit_value = search_accepted_char(edit_string[edit_pos]); + + if (edit_value < sizeof(accepted_chars) - 2) + edit_value++; + edit_string[edit_pos] = accepted_chars[edit_value]; + lcd.setCursor(x + edit_pos, y); lcd.print(edit_string[edit_pos]); } @@ -5122,7 +5130,12 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i { if (edit_mode == true) { - edit_string[edit_pos] = constrain(edit_string[edit_pos] - 1, 32, 126); + edit_value = search_accepted_char(edit_string[edit_pos]); + + if (edit_value >= 1) + edit_value--; + edit_string[edit_pos] = accepted_chars[edit_value]; + lcd.setCursor(x + edit_pos, y); lcd.print(edit_string[edit_pos]); } @@ -5164,6 +5177,19 @@ bool UI_select_name(uint8_t y, uint8_t x, char* edit_string, uint8_t len, bool i return (false); } +uint8_t search_accepted_char(uint8_t c) +{ + if (c == 0) + c = 32; + + for (uint8_t i = 0; i < sizeof(accepted_chars); i++) + { + if (c == accepted_chars[i]) + return (i); + } + return (0); +} + void lcd_display_int(int16_t var, uint8_t size, bool zeros, bool brackets, bool sign) { lcd_display_float(float(var), size, 0, zeros, brackets, sign);