Contnued work on Menus.

pull/3/head
Holger Wirtz 5 years ago
parent c832fdd2d8
commit d99e5d6efb
  1. 3
      MicroDexed.ino
  2. 285
      UI.hpp
  3. 6
      config.h

@ -144,7 +144,7 @@ void setup()
// Enable Menu Rollover // Enable Menu Rollover
//LCDML.MENU_enRollover(); //LCDML.MENU_enRollover();
// Enable Screensaver (screensaver menu function, time to activate in ms) // Enable Screensaver (screensaver menu function, time to activate in ms)
//LCDML.SCREEN_enable(UI_voice_func_voice_selection, 10000); // set to 10 seconds LCDML.SCREEN_enable(UI_func_voice_selection, VOICE_SELECTION_MS); // set to 10 seconds
#else #else
Serial.println(F("NO LCD DISPLAY ENABLED!")); Serial.println(F("NO LCD DISPLAY ENABLED!"));
#endif #endif
@ -338,7 +338,6 @@ void loop()
#ifdef ENABLE_LCD_UI #ifdef ENABLE_LCD_UI
// LCD Menu // LCD Menu
LCDML.loop(); LCDML.loop();
LCDML_Voice.loop();
#endif #endif
control_rate = 0; control_rate = 0;

285
UI.hpp

@ -26,10 +26,10 @@
#ifndef _UI_HPP_ #ifndef _UI_HPP_
#define _UI_HPP_ #define _UI_HPP_
#include "config.h"
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#include <LCDMenuLib2.h> #include <LCDMenuLib2.h>
#include <Encoder.h> #include <Encoder.h>
#include "config.h"
#define _LCDML_DISP_cols LCD_cols #define _LCDML_DISP_cols LCD_cols
#define _LCDML_DISP_rows LCD_rows #define _LCDML_DISP_rows LCD_rows
@ -51,6 +51,8 @@ const uint8_t scroll_bar[5][8] = {
}; };
enum { ENC_R, ENC_L }; enum { ENC_R, ENC_L };
enum { MENU_R_SHOW, MENU_R_EDIT};
uint8_t menu_state = MENU_R_SHOW;
void lcdml_menu_display(void); void lcdml_menu_display(void);
void lcdml_voice_menu_display(void); void lcdml_voice_menu_display(void);
@ -76,8 +78,7 @@ void UI_func_stereo_mono(uint8_t param);
void UI_func_polyphony(uint8_t param); void UI_func_polyphony(uint8_t param);
void UI_func_engine(uint8_t param); void UI_func_engine(uint8_t param);
void UI_func_information(uint8_t param); void UI_func_information(uint8_t param);
void UI_voice_func_bank_selection(uint8_t param); void UI_func_voice_selection(uint8_t param);
void UI_voice_func_voice_selection(uint8_t param);
void UI_func_back(uint8_t param); void UI_func_back(uint8_t param);
void UI_func_goToRootMenu(uint8_t param); void UI_func_goToRootMenu(uint8_t param);
@ -85,10 +86,6 @@ void UI_func_goToRootMenu(uint8_t param);
LCDMenuLib2_menu LCDML_0(255, 0, 0, NULL, NULL); // normal root menu element (do not change) LCDMenuLib2_menu LCDML_0(255, 0, 0, NULL, NULL); // normal root menu element (do not change)
LCDMenuLib2 LCDML(LCDML_0, _LCDML_DISP_rows, _LCDML_DISP_cols, lcdml_menu_display, lcdml_menu_clear, lcdml_menu_control); LCDMenuLib2 LCDML(LCDML_0, _LCDML_DISP_rows, _LCDML_DISP_cols, lcdml_menu_display, lcdml_menu_clear, lcdml_menu_control);
// voice menu
LCDMenuLib2_menu LCDML_1(255, 0, 0, NULL, NULL); // voice root menu element (do not change)
LCDMenuLib2 LCDML_Voice(LCDML_1, _LCDML_DISP_rows, _LCDML_DISP_cols, lcdml_voice_menu_display, lcdml_menu_clear, lcdml_voice_menu_control);
// LCDML_add(id, prev_layer, new_num, lang_char_array, callback_function) // LCDML_add(id, prev_layer, new_num, lang_char_array, callback_function)
LCDML_add(0, LCDML_0, 1, "Sound", UI_func_sound); LCDML_add(0, LCDML_0, 1, "Sound", UI_func_sound);
LCDML_add(1, LCDML_0, 2, "Effect", NULL); LCDML_add(1, LCDML_0, 2, "Effect", NULL);
@ -116,9 +113,7 @@ LCDML_add(22, LCDML_0_4, 4, "Stereo/Mono", UI_func_stereo_mono);
LCDML_add(23, LCDML_0_4, 5, "Polyphony", UI_func_polyphony); LCDML_add(23, LCDML_0_4, 5, "Polyphony", UI_func_polyphony);
LCDML_add(24, LCDML_0_4, 6, "Engine", UI_func_engine); LCDML_add(24, LCDML_0_4, 6, "Engine", UI_func_engine);
LCDML_add(25, LCDML_0, 5, "Info", UI_func_information); LCDML_add(25, LCDML_0, 5, "Info", UI_func_information);
LCDML_add(26, LCDML_1, 1, "B01:DEFAULT", UI_voice_func_bank_selection); #define _LCDML_DISP_cnt 25
LCDML_add(27, LCDML_1, 2, "V01:INIT", UI_voice_func_voice_selection);
#define _LCDML_DISP_cnt 27
// create menu // create menu
LCDML_createMenu(_LCDML_DISP_cnt); LCDML_createMenu(_LCDML_DISP_cnt);
@ -134,8 +129,7 @@ Encoder ENCODER[NUM_ENCODER] = {Encoder(ENC_R_PIN_B, ENC_R_PIN_A), Encoder(ENC_L
long g_LCDML_CONTROL_button_press_time[NUM_ENCODER] = {0, 0}; long g_LCDML_CONTROL_button_press_time[NUM_ENCODER] = {0, 0};
bool g_LCDML_CONTROL_button_prev[NUM_ENCODER] = {HIGH, HIGH}; bool g_LCDML_CONTROL_button_prev[NUM_ENCODER] = {HIGH, HIGH};
uint8_t g_LCDML_CONTROL_prev[NUM_ENCODER] = {0, 0};
void lcdml_menu_control(void) void lcdml_menu_control(void)
{ {
@ -146,12 +140,12 @@ void lcdml_menu_control(void)
} }
//Volatile Variable //Volatile Variable
long g_LCDML_CONTROL_Encoder_position = ENCODER[ENC_R].read(); long g_LCDML_CONTROL_Encoder_position[NUM_ENCODER] = {ENCODER[ENC_R].read(), ENCODER[ENC_L].read()};
bool button = digitalRead(BUT_R_PIN); bool button[NUM_ENCODER] = {digitalRead(BUT_R_PIN), digitalRead(BUT_L_PIN)};
if(g_LCDML_CONTROL_Encoder_position <= -3) {
if(!button) if (g_LCDML_CONTROL_Encoder_position[ENC_R] <= -3)
{
if (!button[ENC_R])
{ {
LCDML.BT_left(); LCDML.BT_left();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW; g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
@ -159,14 +153,15 @@ void lcdml_menu_control(void)
} }
else else
{ {
if (menu_state == MENU_R_SHOW)
LCDML.BT_down(); LCDML.BT_down();
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position+4); ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4);
} }
else if(g_LCDML_CONTROL_Encoder_position >= 3) else if (g_LCDML_CONTROL_Encoder_position[ENC_R] >= 3)
{ {
if(!button) if (!button[ENC_R])
{ {
LCDML.BT_right(); LCDML.BT_right();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW; g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
@ -174,18 +169,19 @@ void lcdml_menu_control(void)
} }
else else
{ {
if (menu_state == MENU_R_SHOW)
LCDML.BT_up(); LCDML.BT_up();
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position-4); ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4);
} }
else else
{ {
if(!button && g_LCDML_CONTROL_button_prev[ENC_R]) //falling edge, button pressed if (!button[ENC_R] && g_LCDML_CONTROL_button_prev[ENC_R]) //falling edge, button[ENC_R] pressed
{ {
g_LCDML_CONTROL_button_prev[ENC_R] = LOW; g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_R] = millis(); g_LCDML_CONTROL_button_press_time[ENC_R] = millis();
} }
else if(button && !g_LCDML_CONTROL_button_prev[ENC_R]) //rising edge, button not active else if (button[ENC_R] && !g_LCDML_CONTROL_button_prev[ENC_R]) //rising edge, button[ENC_R] not active
{ {
g_LCDML_CONTROL_button_prev[ENC_R] = HIGH; g_LCDML_CONTROL_button_prev[ENC_R] = HIGH;
@ -204,74 +200,24 @@ void lcdml_menu_control(void)
} }
} }
} }
} /*
// checking encoder left (volume)
void lcdml_voice_menu_control(void) if (g_LCDML_CONTROL_old_var[ENC_L] != g_LCDML_CONTROL_Encoder_position[ENC_L])
{
// If something must init, put in in the setup condition
if (LCDML_Voice.BT_setup())
{
pinMode(BUT_L_PIN, INPUT_PULLUP);
}
//Volatile Variable
long g_LCDML_CONTROL_Encoder_position = ENCODER[ENC_L].read();
bool button_l = digitalRead(BUT_L_PIN);
if (g_LCDML_CONTROL_Encoder_position <= -3) {
if (!button_l)
{
LCDML_Voice.BT_left();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{
LCDML_Voice.BT_down();
}
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position + 4);
}
else if (g_LCDML_CONTROL_Encoder_position >= 3)
{
if (!button_l)
{
LCDML_Voice.BT_right();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{
LCDML_Voice.BT_up();
}
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position - 4);
}
else
{
if (!button_l && g_LCDML_CONTROL_button_prev[ENC_L]) //falling edge, button_l pressed
{
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = millis();
}
else if (button_l && !g_LCDML_CONTROL_button_prev[ENC_L]) //rising edge, button_l not active
{
g_LCDML_CONTROL_button_prev[ENC_L] = HIGH;
if (g_LCDML_CONTROL_button_press_time[ENC_L] < 0)
{ {
g_LCDML_CONTROL_button_press_time[ENC_L] = millis(); if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3)
//Reset for left right action
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_long_press)
{ {
LCDML_Voice.BT_quit(); #ifdef DEBUG
Serial.println(F("Volume +"));
#endif
} }
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_short_press) else if (g_LCDML_CONTROL_Encoder_position[ENC_L] >= 3)
{ {
Serial.println("------------------------------------------------->LLLLLLLLLLLLLLLLLLLLLLLLLLLLL"); #ifdef DEBUG
LCDML_Voice.BT_enter(); Serial.println(F("Volume -"));
} #endif
}
} }
g_LCDML_CONTROL_old_var[ENC_L] = g_LCDML_CONTROL_Encoder_position[ENC_L];
}*/
} }
/*********************************************************************** /***********************************************************************
@ -344,7 +290,6 @@ void lcdml_menu_display(void)
uint8_t scrollbar_cur_pos = LCDML.MENU_getCursorPosAbs(); uint8_t scrollbar_cur_pos = LCDML.MENU_getCursorPosAbs();
uint8_t scroll_pos = ((1.*n_max * _LCDML_DISP_rows) / (scrollbar_max - 1) * scrollbar_cur_pos); uint8_t scroll_pos = ((1.*n_max * _LCDML_DISP_rows) / (scrollbar_max - 1) * scrollbar_cur_pos);
// display rows // display rows
for (uint8_t n = 0; n < n_max; n++) for (uint8_t n = 0; n < n_max; n++)
{ {
@ -393,116 +338,6 @@ void lcdml_menu_display(void)
} }
} }
void lcdml_voice_menu_display(void)
{
// update content
// ***************
if (LCDML_Voice.DISP_checkMenuUpdate()) {
// clear menu
// ***************
LCDML_Voice.DISP_clear();
// declaration of some variables
// ***************
// content variable
char content_text[_LCDML_DISP_cols]; // save the content text of every menu element
// menu element object
LCDMenuLib2_menu *tmp;
// some limit values
uint8_t i = LCDML_Voice.MENU_getScroll();
uint8_t maxi = _LCDML_DISP_rows + i;
uint8_t n = 0;
// check if this element has children
if ((tmp = LCDML_Voice.MENU_getDisplayedObj()) != NULL)
{
// loop to display lines
do
{
// check if a menu element has a condition and if the condition be true
if (tmp->checkCondition())
{
// check the type off a menu element
if (tmp->checkType_menu() == true)
{
// display normal content
LCDML_getContent(content_text, tmp->getID());
lcd.setCursor(1, n);
lcd.print(content_text);
}
else
{
if (tmp->checkType_dynParam()) {
tmp->callback(n);
}
}
// increment some values
i++;
n++;
}
// try to go to the next sibling and check the number of displayed rows
} while (((tmp = tmp->getSibling(1)) != NULL) && (i < maxi));
}
}
if (LCDML_Voice.DISP_checkMenuCursorUpdate())
{
// init vars
uint8_t n_max = (LCDML_Voice.MENU_getChilds() >= _LCDML_DISP_rows) ? _LCDML_DISP_rows : (LCDML_Voice.MENU_getChilds());
uint8_t scrollbar_min = 0;
uint8_t scrollbar_max = LCDML_Voice.MENU_getChilds();
uint8_t scrollbar_cur_pos = LCDML_Voice.MENU_getCursorPosAbs();
uint8_t scroll_pos = ((1.*n_max * _LCDML_DISP_rows) / (scrollbar_max - 1) * scrollbar_cur_pos);
// display rows
for (uint8_t n = 0; n < n_max; n++)
{
//set cursor
lcd.setCursor(0, n);
//set cursor char
if (n == LCDML_Voice.MENU_getCursorPos()) {
lcd.write(_LCDML_DISP_cfg_cursor);
} else {
lcd.write(' ');
}
// delete or reset scrollbar
if (_LCDML_DISP_cfg_scrollbar == 1) {
if (scrollbar_max > n_max) {
lcd.setCursor((_LCDML_DISP_cols - 1), n);
lcd.write((uint8_t)0);
}
else {
lcd.setCursor((_LCDML_DISP_cols - 1), n);
lcd.print(' ');
}
}
}
// display scrollbar
if (_LCDML_DISP_cfg_scrollbar == 1) {
if (scrollbar_max > n_max) {
//set scroll position
if (scrollbar_cur_pos == scrollbar_min) {
// min pos
lcd.setCursor((_LCDML_DISP_cols - 1), 0);
lcd.write((uint8_t)1);
} else if (scrollbar_cur_pos == (scrollbar_max - 1)) {
// max pos
lcd.setCursor((_LCDML_DISP_cols - 1), (n_max - 1));
lcd.write((uint8_t)4);
} else {
// between
lcd.setCursor((_LCDML_DISP_cols - 1), scroll_pos / n_max);
lcd.write((uint8_t)(scroll_pos % n_max) + 1);
}
}
}
}
}
/*********************************************************************** /***********************************************************************
MENU MENU
***********************************************************************/ ***********************************************************************/
@ -643,61 +478,7 @@ void UI_func_information(uint8_t param)
} }
} }
void UI_voice_func_bank_selection(uint8_t param) void UI_func_voice_selection(uint8_t param)
{
if (LCDML_Voice.FUNC_setup()) // ****** SETUP *********
{
// update LCD content
lcd.setCursor(0, 0); // set cursor
lcd.print("B01:DEFAULT"); // print change content
lcd.setCursor(0, 1); // set cursor
lcd.print("Select Bank");
LCDML_Voice.FUNC_setLoopInterval(100); // starts a trigger event for the loop function every 100 milliseconds
}
if (LCDML_Voice.FUNC_loop())
{
if (LCDML_Voice.BT_checkEnter()) // check if any button is pressed (enter, up, down, left, right)
{
LCDML_Voice.FUNC_goBackToMenu(); // leave this function
}
}
if (LCDML_Voice.FUNC_close())
{
// The screensaver go to the root menu
LCDML_Voice.MENU_goRoot();
}
}
void UI_voice_func_voice_selection(uint8_t param)
{
if (LCDML_Voice.FUNC_setup()) // ****** SETUP *********
{
// update LCD content
lcd.setCursor(0, 0); // set cursor
lcd.print("Select Voice"); // print change content
lcd.setCursor(0, 1); // set cursor
lcd.print("V01:INIT");
LCDML_Voice.FUNC_setLoopInterval(100); // starts a trigger event for the loop function every 100 milliseconds
}
if (LCDML_Voice.FUNC_loop())
{
if (LCDML_Voice.BT_checkEnter()) // check if any button is pressed (enter, up, down, left, right)
{
LCDML_Voice.FUNC_goBackToMenu(); // leave this function
}
}
if (LCDML_Voice.FUNC_close())
{
// The screensaver go to the root menu
LCDML_Voice.MENU_goRoot();
}
}
void UI_func_screensaver(uint8_t param)
{ {
if (LCDML.FUNC_setup()) // ****** SETUP ********* if (LCDML.FUNC_setup()) // ****** SETUP *********
{ {

@ -148,12 +148,14 @@
// LCD Display // LCD Display
#define I2C_DISPLAY 1 #define I2C_DISPLAY 1
// [I2C] SCL: Pin 19, SDA: Pin 18 (https://www.pjrc.com/teensy/td_libs_Wire.html) // [I2C] SCL: Pin 19, SDA: Pin 18 (https://www.pjrc.com/teensy/td_libs_Wire.html)
//#define LCD_GFX 1
#define LCD_I2C_ADDRESS 0x27 #define LCD_I2C_ADDRESS 0x27
#define LCD_CHARS 16 #define LCD_CHARS 16
#define LCD_LINES 2 #define LCD_LINES 2
#define UI_AUTO_BACK_MS 3000
// Internal timer
#define AUTOSTORE_MS 5000 #define AUTOSTORE_MS 5000
#define AUTOSTORE_FAST_MS 50 #define VOICE_SELECTION_MS 2000
// EEPROM address // EEPROM address
#define EEPROM_START_ADDRESS 0 #define EEPROM_START_ADDRESS 0

Loading…
Cancel
Save