From f439470d016cbd2c37dd55336de8c195d43d0c99 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 5 May 2019 18:25:44 +0200 Subject: [PATCH] Several additions for LiquidMenu structures. --- MicroMDAEPiano.ino | 14 ++++---- UI.hpp | 88 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index c2e93d8..db70e21 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -91,7 +91,6 @@ AudioConnection patchCord13(volume_l, 0, pt8211_1, 0); mdaEPiano* ep; LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES); Encoder4 enc[2] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)}; -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)}; // Variables @@ -122,16 +121,18 @@ void setup() menu_init(); + lcd.clear(); + lcd.setCursor(1,0); + lcd.print(F("MicroMDAEpiano")); + lcd.setCursor(0,1); + lcd.print(F("(c)parasiTstudio")); + Serial.begin(SERIAL_SPEED); delay(500); // Encoder setup enc[0].write(INITIAL_ENC_L_VALUE); - enc_val[0] = enc[0].read(); enc[1].write(INITIAL_ENC_R_VALUE); - enc_val[1] = enc[1].read(); - but[0].update(); - but[1].update(); // Debug output Serial.println(F("MicroMDAEPiano based on https://sourceforge.net/projects/mda-vst")); @@ -230,7 +231,6 @@ void setup() Serial.println(F("")); - menu_system.next_screen(); menu_system.update(); menu_system.switch_focus(); @@ -301,6 +301,8 @@ void loop() if (control_rate > CONTROL_RATE_MS) { control_rate = 0; + + handle_ui(); } } diff --git a/UI.hpp b/UI.hpp index b6f7e80..0215a80 100644 --- a/UI.hpp +++ b/UI.hpp @@ -21,21 +21,20 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include - #ifndef UI_HPP_INCLUDED #define UI_HPP_INCLUDED -extern LiquidCrystal_I2C lcd; +#include +#include +#include +#include "Encoder4.h" +extern LiquidCrystal_I2C lcd; +extern Encoder4 enc[2]; +extern Bounce but[2]; -// Welcome screen -const char text00[] PROGMEM = "MicroMDAEPiano"; -const char text01[] PROGMEM = "(c)parasiTstudio"; -LiquidLine welcome_line1(1, 0, text00); -LiquidLine welcome_line2(0, 1, text01); -LiquidScreen welcome_screen(welcome_line1, welcome_line2); +// Global vars +uint8_t main_menu_selector = 0; // Main menu const char text10[] PROGMEM = "Favorites "; @@ -44,8 +43,10 @@ const char text12[] PROGMEM = "Store "; const char text13[] PROGMEM = "Info "; LiquidLine main_line1(0, 0, text10); LiquidLine main_line2(0, 1, text11); -LiquidScreen main_screen(main_line1, main_line2); -LiquidMenu main_menu(lcd,welcome_screen,main_screen,1); +LiquidLine main_line3(0, 1, text12); +LiquidLine main_line4(0, 1, text13); +LiquidScreen main_screen; +LiquidMenu main_menu(lcd); // Sound menu const char text20[] PROGMEM = "Decay "; @@ -57,27 +58,78 @@ LiquidLine sound_line2(0, 1, text21); LiquidLine sound_line3(0, 1, text22); LiquidLine sound_line4(0, 1, text23); LiquidScreen sound_screen(sound_line1, sound_line2, sound_line3, sound_line4); -LiquidMenu sound_menu(lcd,sound_screen); +LiquidMenu sound_menu(lcd, sound_screen); // System menu LiquidSystem menu_system(main_menu, sound_menu); -void callback_main_function() { - Serial.println(F("You called the main callback function.")); +void callback_favorites_function() { + Serial.println(F("callback_favorites_function")); +} + +void callback_sound_function() { + Serial.println(F("callback_sound_function")); +} + +void callback_store_function() { + Serial.println(F("callback_store_function")); +} + +void callback_info_function() { + Serial.println(F("callback_info_function")); } void menu_init(void) { + uint8_t i; + // LCD display setup lcd.init(); lcd.blink_off(); lcd.cursor_off(); lcd.backlight(); - lcd.noAutoscroll(); + //lcd.noAutoscroll(); + + main_screen.add_line(main_line1); + main_screen.add_line(main_line2); + main_screen.add_line(main_line3); + main_screen.add_line(main_line4); + + main_line1.attach_function(1, callback_favorites_function); + main_line2.attach_function(2, callback_sound_function); + main_line3.attach_function(3, callback_store_function); + main_line4.attach_function(4, callback_info_function); + + main_screen.set_displayLineCount(2); + main_menu.add_screen(main_screen); - main_line1.attach_function(1, callback_main_function); - menu_system.update(); + + for (i = 0; i < NUM_ENCODER; i++) + but[i].update(); + + enc[1].write(0, 0, 99); + enc[1].write(1, 0, 4); } +void handle_ui(void) +{ + uint8_t i; + + for (i = 0; i < NUM_ENCODER; i++) + { + but[i].update(); + + switch (i) + { + case 1: + if (but[i].risingEdge() || but[i].fallingEdge()) + { + Serial.println(F("B0")); + main_menu.switch_focus(); + } + break; + } + } +} #endif