From 190bad2f461798d36d7753d32454cda873647a12 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 27 Sep 2018 14:41:26 +0200 Subject: [PATCH] Added showing the current selected volume inside the display. Added configurable number of steps for volume encoder. --- MicroDexed.ino | 11 +++-------- UI.cpp | 51 +++++++++++++++++++++++++++++++++++--------------- UI.h | 13 +++++++++++-- config.h | 2 ++ 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index a06c11c..318df08 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -47,6 +47,7 @@ Encoder4 enc[2] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC 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; #endif // GUItool: begin automatically generated code @@ -181,7 +182,7 @@ void setup() // load default SYSEX data load_sysex(bank, voice); #ifdef I2C_DISPLAY - enc[0].write(map(vol*100,0,100,0,20)); + enc[0].write(map(vol * 100, 0, 100, 0, ENC_VOL_STEPS)); enc[1].write(voice); but[0].update(); but[1].update(); @@ -222,13 +223,7 @@ void setup() #endif #ifdef I2C_DISPLAY - lcd.clear(); - lcd.show(0, 0, 2, bank + 1); - lcd.show(0, 2, 1, " "); - lcd.show(0, 3, 10, bank_name); - lcd.show(1, 0, 2, voice + 1); - lcd.show(1, 2, 1, " "); - lcd.show(1, 3, 10, voice_name); + ui_show_main(); #endif #ifdef TEST_NOTE diff --git a/UI.cpp b/UI.cpp index effb015..6856be6 100644 --- a/UI.cpp +++ b/UI.cpp @@ -29,12 +29,13 @@ #ifdef I2C_DISPLAY // selecting sounds by encoder, button and display - -enum ui_state {UI_MAIN}; -uint8_t ui_state = UI_MAIN; +elapsedMillis ui_back_to_main; void handle_ui(void) { + if (ui_back_to_main >= UI_AUTO_BACK_MS && ui_state != UI_MAIN) + ui_show_main(); + for (uint8_t i = 0; i < NUM_ENCODER; i++) { but[i].update(); @@ -57,11 +58,13 @@ void handle_ui(void) case 0: // left encoder moved if (enc[i].read() <= 0) enc[i].write(0); - else if (enc[i].read() >= 20) - enc[i].write(20); - set_volume(float(map(enc[i].read(), 0, 20, 0, 100))/100, vol_left, vol_right); + else if (enc[i].read() >= ENC_VOL_STEPS) + enc[i].write(ENC_VOL_STEPS); + set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, vol_left, vol_right); + ui_show_volume(); break; case 1: // right encoder moved + ui_show_main(); break; } #ifdef DEBUG @@ -75,15 +78,33 @@ void handle_ui(void) } } -/*int32_t getEncPosition(uint8_t encoder_number) - { - return enc[encoder_number].read() / 4; - } +void ui_show_main(void) +{ + ui_state = UI_MAIN; + + lcd.clear(); + lcd.show(0, 0, 2, bank + 1); + lcd.show(0, 2, 1, " "); + lcd.show(0, 3, 10, bank_name); + lcd.show(1, 0, 2, voice + 1); + lcd.show(1, 2, 1, " "); + lcd.show(1, 3, 10, voice_name); +} - void setEncPosition(uint8_t encoder_number, int32_t value) - { - enc[encoder_number].write(value * 4); - enc_val[encoder_number] = value * 4; - }*/ +void ui_show_volume(void) +{ + ui_back_to_main = 0; + + if (ui_state != UI_VOLUME) + lcd.show(0, 0, LCD_CHARS, "Volume"); + + lcd.show(0, LCD_CHARS - 3, 3, vol * 100); + for (uint8_t i = 0; i < map(vol * 100, 0, 100, 0, LCD_CHARS); i++) + lcd.show(1, i, 1, "*"); + for (uint8_t i = map(vol * 100, 0, 100, 0, LCD_CHARS); i < LCD_CHARS; i++) + lcd.show(1, i, 1, " "); + + ui_state = UI_VOLUME; +} #endif diff --git a/UI.h b/UI.h index 3716595..5e06a16 100644 --- a/UI.h +++ b/UI.h @@ -34,14 +34,23 @@ extern Encoder4 enc[2]; extern int32_t enc_val[2]; extern Bounce but[2]; +extern float vol; extern float vol_left; extern float vol_right; +extern LiquidCrystalPlus_I2C lcd; +extern uint8_t bank; +extern uint8_t voice; +extern char bank_name[11]; +extern char voice_name[11]; +extern uint8_t ui_state; extern void set_volume(float v, float vr, float vl); void handle_ui(void); -/* int32_t getEncPosition(uint8_t encoder_number); - void setEncPosition(uint8_t encoder_number, int32_t value);*/ +void ui_show_main(void); +void ui_show_volume(void); + +enum ui_states {UI_MAIN, UI_VOLUME}; class MyEncoder : public Encoder { diff --git a/config.h b/config.h index 5b937dd..7078a3a 100644 --- a/config.h +++ b/config.h @@ -92,8 +92,10 @@ #define LCD_I2C_ADDRESS 0x27 #define LCD_CHARS 16 #define LCD_LINES 2 +#define UI_AUTO_BACK_MS 2000 // Encoder with button +#define ENC_VOL_STEPS 50 #define TIMER_UI_HANDLING_MS 50 #define NUM_ENCODER 2 #define ENC_L_PIN_A 3