You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
4.9 KiB
195 lines
4.9 KiB
/*
|
|
LiquidMenuTest
|
|
*/
|
|
|
|
#ifndef UI_HPP_INCLUDED
|
|
#define UI_HPP_INCLUDED
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
#include <LiquidMenu.h>
|
|
#include <Bounce.h>
|
|
#include "Encoder4.h"
|
|
#include "config.h"
|
|
|
|
LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES);
|
|
Encoder4 enc[NUM_ENCODER] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)};
|
|
int32_t encoder_value[NUM_ENCODER];
|
|
Bounce but[NUM_ENCODER] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
|
|
uint8_t main_menu_selector = 0;
|
|
elapsedMillis control_rate;
|
|
|
|
enum { LEFT_ENCODER, RIGHT_ENCODER };
|
|
|
|
// Recycleable objects
|
|
const char text_back[] PROGMEM = "BACK";
|
|
LiquidLine back_line(1, 1, text_back);
|
|
|
|
// Main menu
|
|
const char text10[] PROGMEM = "Favorites";
|
|
const char text11[] PROGMEM = "Sound";
|
|
const char text12[] PROGMEM = "Store";
|
|
const char text13[] PROGMEM = "Info";
|
|
LiquidLine main_line1(1, 0, text10);
|
|
LiquidLine main_line2(1, 1, text11);
|
|
LiquidLine main_line3(1, 1, text12);
|
|
LiquidLine main_line4(1, 1, text13);
|
|
LiquidScreen main_screen;
|
|
LiquidMenu main_menu(lcd);
|
|
|
|
// Sound menu
|
|
const char text20[] PROGMEM = "Decay";
|
|
const char text21[] PROGMEM = "Release";
|
|
const char text22[] PROGMEM = "Hardness";
|
|
const char text23[] PROGMEM = "Treble";
|
|
LiquidLine sound_line1(1, 0, text20);
|
|
LiquidLine sound_line2(1, 1, text21);
|
|
LiquidLine sound_line3(1, 1, text22);
|
|
LiquidLine sound_line4(1, 1, text23);
|
|
LiquidScreen sound_screen(sound_line1, sound_line2, sound_line3, sound_line4);
|
|
LiquidMenu sound_menu(lcd, sound_screen);
|
|
|
|
// Info menu
|
|
const char text40[] PROGMEM = "INFO";
|
|
LiquidLine info_line1(0, 0, text40);
|
|
LiquidScreen info_screen(info_line1);
|
|
LiquidMenu info_menu(lcd, info_screen);
|
|
|
|
// System menu
|
|
LiquidSystem menu_system(main_menu, sound_menu, info_menu);
|
|
|
|
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 callback_back_function() {
|
|
Serial.println(F("callback_back_function"));
|
|
}
|
|
|
|
void setup(void)
|
|
{
|
|
uint8_t i;
|
|
|
|
Serial.begin(38400);
|
|
|
|
pinMode(BUT_L_PIN, INPUT_PULLUP);
|
|
pinMode(BUT_R_PIN, INPUT_PULLUP);
|
|
|
|
Serial.println(F("<setup start>"));
|
|
|
|
// Encoder setup
|
|
enc[0].write(INITIAL_ENC_L_VALUE);
|
|
enc[1].write(INITIAL_ENC_R_VALUE);
|
|
// LCD display setup
|
|
lcd.init();
|
|
lcd.blink_off();
|
|
lcd.cursor_off();
|
|
lcd.backlight();
|
|
//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_screen.add_line(back_line);
|
|
|
|
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);
|
|
back_line.attach_function(1, callback_back_function );
|
|
|
|
main_screen.set_displayLineCount(2);
|
|
main_menu.add_screen(main_screen);
|
|
|
|
for (i = 0; i < NUM_ENCODER; i++)
|
|
but[i].update();
|
|
|
|
enc[LEFT_ENCODER].write(0, 0, 99, true);
|
|
encoder_value[LEFT_ENCODER] = 0;
|
|
enc[RIGHT_ENCODER].write(0, 0, 4, true);
|
|
encoder_value[RIGHT_ENCODER] = 0;
|
|
|
|
menu_system.update();
|
|
menu_system.set_focusPosition(Position::LEFT);
|
|
menu_system.switch_focus();
|
|
}
|
|
|
|
void loop(void)
|
|
{
|
|
// CONTROL-RATE-EVENT-HANDLING
|
|
if (control_rate > CONTROL_RATE_MS)
|
|
{
|
|
control_rate = 0;
|
|
|
|
handle_ui();
|
|
}
|
|
}
|
|
|
|
void handle_ui(void)
|
|
{
|
|
uint8_t i;
|
|
int32_t encoder_tmp;
|
|
|
|
for (i = 0; i < NUM_ENCODER; i++)
|
|
{
|
|
but[i].update();
|
|
|
|
switch (i)
|
|
{
|
|
case RIGHT_ENCODER:
|
|
// Encoder handling
|
|
encoder_tmp = enc[RIGHT_ENCODER].read();
|
|
if (encoder_tmp > encoder_value[RIGHT_ENCODER])
|
|
{
|
|
// move down
|
|
#ifdef DEBUG
|
|
Serial.println(F("ENC-R-DOWN"));
|
|
#endif
|
|
menu_system.switch_focus(true);
|
|
if (encoder_value[RIGHT_ENCODER] == enc[RIGHT_ENCODER].read_max())
|
|
encoder_tmp = enc[RIGHT_ENCODER].read_min();
|
|
}
|
|
else if (encoder_tmp < encoder_value[RIGHT_ENCODER])
|
|
{
|
|
// move up
|
|
#ifdef DEBUG
|
|
Serial.println(F("ENC-R-UP"));
|
|
#endif
|
|
menu_system.switch_focus(false);
|
|
if (encoder_value[RIGHT_ENCODER] == enc[RIGHT_ENCODER].read_min())
|
|
encoder_tmp = enc[RIGHT_ENCODER].read_max();
|
|
}
|
|
encoder_value[RIGHT_ENCODER] = encoder_tmp;
|
|
enc[RIGHT_ENCODER].write(encoder_value[RIGHT_ENCODER]);
|
|
|
|
/*
|
|
// button handling
|
|
if (but[i].fallingEdge()) // SELECT
|
|
{
|
|
#ifdef DEBUG
|
|
Serial.println(F("SELECT-R"));
|
|
#endif
|
|
menu_system.change_menu(sound_menu);
|
|
}*/
|
|
break;
|
|
case LEFT_ENCODER:
|
|
// Encoder handling
|
|
|
|
// button handling
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|