From f43164b7d6c9d80cdbab702a70b9b7d8e8587f91 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 1 Oct 2018 13:04:58 +0200 Subject: [PATCH] Fixed and optimized simple UI handling. --- MicroDexed.ino | 5 ++-- UI.cpp | 68 ++++++++++++++++++++++++++----------------------- UI.h | 2 +- config.h | 1 + dexed_sysex.cpp | 2 +- 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 4ea17ad..794b41d 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -47,7 +47,7 @@ int32_t enc_val[2] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE}; Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)}; elapsedMillis master_timer; uint8_t ui_state = UI_MAIN; -uint8_t ui_main_state = UI_MAIN_VOICE_SELECTED; +uint8_t ui_main_state = UI_MAIN_VOICE; #endif // GUItool: begin automatically generated code @@ -250,9 +250,10 @@ void setup() #endif #ifdef I2C_DISPLAY + lcd.clear(); ui_show_main(); #endif - + Serial.println(F("")); #ifdef TEST_NOTE diff --git a/UI.cpp b/UI.cpp index cce569e..bedbcdd 100644 --- a/UI.cpp +++ b/UI.cpp @@ -38,6 +38,7 @@ void handle_ui(void) { if (ui_back_to_main >= UI_AUTO_BACK_MS && ui_state != UI_MAIN) { + lcd.clear(); ui_show_main(); EEPROM.update(EEPROM_OFFSET + EEPROM_MASTER_VOLUME_ADDR, uint8_t(vol * UCHAR_MAX)); EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR, uint8_t(vol_right * UCHAR_MAX)); @@ -58,15 +59,12 @@ void handle_ui(void) switch (ui_main_state) { case UI_MAIN_BANK: + case UI_MAIN_BANK_SELECTED: ui_main_state = UI_MAIN_VOICE; enc[1].write(voice); enc_val[1] = enc[1].read(); break; case UI_MAIN_VOICE: - ui_main_state = UI_MAIN_VOICE_SELECTED; - enc[1].write(voice); - enc_val[1] = enc[1].read(); - break; case UI_MAIN_VOICE_SELECTED: ui_main_state = UI_MAIN_BANK; enc[1].write(bank); @@ -75,11 +73,14 @@ void handle_ui(void) } break; case 1: // right button pressed - ui_main_state = UI_MAIN_VOICE_SELECTED; - load_sysex(bank, voice); - EEPROM.update(EEPROM_OFFSET + EEPROM_BANK_ADDR, bank); - EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, voice); - update_eeprom_checksum(); + if (ui_main_state == UI_MAIN_VOICE_SELECTED) + { + ui_main_state = UI_MAIN_VOICE; + load_sysex(bank, voice); + EEPROM.update(EEPROM_OFFSET + EEPROM_BANK_ADDR, bank); + EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, voice); + update_eeprom_checksum(); + } break; } ui_show_main(); @@ -107,35 +108,25 @@ void handle_ui(void) switch (ui_main_state) { case UI_MAIN_BANK: + ui_main_state = UI_MAIN_BANK_SELECTED; + case UI_MAIN_BANK_SELECTED: if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() > max_loaded_banks-1) - enc[i].write(max_loaded_banks-1); + else if (enc[i].read() > max_loaded_banks - 1) + enc[i].write(max_loaded_banks - 1); bank = enc[i].read(); - if (!get_voice_names_from_bank(bank)) - { - bank--; - enc[i].write(bank); - get_voice_names_from_bank(bank); - } + get_voice_names_from_bank(bank); break; case UI_MAIN_VOICE: - if (enc[i].read() <= 0) - enc[i].write(0); - else if (enc[i].read() > MAX_VOICES-1) - enc[i].write(MAX_VOICES-1); - voice = enc[i].read(); - break; + ui_main_state = UI_MAIN_VOICE_SELECTED; case UI_MAIN_VOICE_SELECTED: - ui_main_state = UI_MAIN_VOICE; if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() >= MAX_VOICES-1) - enc[i].write(MAX_VOICES); + else if (enc[i].read() > MAX_VOICES - 1) + enc[i].write(MAX_VOICES - 1); voice = enc[i].read(); break; } - get_voice_names_from_bank(bank); ui_show_main(); break; } @@ -154,7 +145,6 @@ void ui_show_main(void) { ui_state = UI_MAIN; - lcd.clear(); lcd.show(0, 0, 2, bank + 1); lcd.show(0, 2, 1, " "); strip_extension(bank_names[bank], bank_name); @@ -165,25 +155,39 @@ void ui_show_main(void) lcd.show(0, 3, 10, bank_name); lcd.show(0, 14, 1, "]"); } + else if (ui_main_state == UI_MAIN_BANK_SELECTED) + { + lcd.show(0, 2, 1, "<"); + lcd.show(0, 3, 10, bank_name); + lcd.show(0, 14, 1, ">"); + } else + { + lcd.show(0, 2, 1, " "); lcd.show(0, 3, 10, bank_name); + lcd.show(0, 14, 1, " "); + } lcd.show(1, 0, 2, voice + 1); lcd.show(1, 2, 1, " "); if (ui_main_state == UI_MAIN_VOICE) { - lcd.show(1, 2, 1, "<"); + lcd.show(1, 2, 1, "["); lcd.show(1, 3, 10, voice_names[voice]); - lcd.show(1, 14, 1, ">"); + lcd.show(1, 14, 1, "]"); } else if (ui_main_state == UI_MAIN_VOICE_SELECTED) { - lcd.show(1, 2, 1, "["); + lcd.show(1, 2, 1, "<"); lcd.show(1, 3, 10, voice_names[voice]); - lcd.show(1, 14, 1, "]"); + lcd.show(1, 14, 1, ">"); } else + { + lcd.show(1, 2, 1, " "); lcd.show(1, 3, 10, voice_names[voice]); + lcd.show(1, 14, 1, " "); + } } void ui_show_volume(void) diff --git a/UI.h b/UI.h index f76a071..375a7ac 100644 --- a/UI.h +++ b/UI.h @@ -54,7 +54,7 @@ void ui_show_main(void); void ui_show_volume(void); enum ui_states {UI_MAIN, UI_VOLUME}; -enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_VOICE_SELECTED}; +enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_BANK_SELECTED, UI_MAIN_VOICE_SELECTED}; class MyEncoder : public Encoder { diff --git a/config.h b/config.h index 56081cd..74fb2f3 100644 --- a/config.h +++ b/config.h @@ -33,6 +33,7 @@ #define CONFIG_H_INCLUDED // Initial values +#define VERSION 1.0 #define MIDI_DEVICE Serial1 #define USE_ONBOARD_USB_HOST 1 #define TEENSY_AUDIO_BOARD 1 diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index 4186d27..d28015f 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -253,7 +253,7 @@ bool load_sysex(uint8_t b, uint8_t v) Serial.print(sysex_file_name); Serial.print(F(" [")); Serial.print(voice_names[v]); - Serial.println(F(" [")); + Serial.println(F("]")); #endif return (dexed->loadSysexVoice(data)); }