Contnued work on Menus.

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

@ -144,7 +144,7 @@ void setup()
// Enable Menu Rollover
//LCDML.MENU_enRollover();
// 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
Serial.println(F("NO LCD DISPLAY ENABLED!"));
#endif
@ -338,7 +338,6 @@ void loop()
#ifdef ENABLE_LCD_UI
// LCD Menu
LCDML.loop();
LCDML_Voice.loop();
#endif
control_rate = 0;

317
UI.hpp

@ -26,10 +26,10 @@
#ifndef _UI_HPP_
#define _UI_HPP_
#include "config.h"
#include <LiquidCrystal_I2C.h>
#include <LCDMenuLib2.h>
#include <Encoder.h>
#include "config.h"
#define _LCDML_DISP_cols LCD_cols
#define _LCDML_DISP_rows LCD_rows
@ -51,6 +51,8 @@ const uint8_t scroll_bar[5][8] = {
};
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_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_engine(uint8_t param);
void UI_func_information(uint8_t param);
void UI_voice_func_bank_selection(uint8_t param);
void UI_voice_func_voice_selection(uint8_t param);
void UI_func_voice_selection(uint8_t param);
void UI_func_back(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 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(0, LCDML_0, 1, "Sound", UI_func_sound);
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(24, LCDML_0_4, 6, "Engine", UI_func_engine);
LCDML_add(25, LCDML_0, 5, "Info", UI_func_information);
LCDML_add(26, LCDML_1, 1, "B01:DEFAULT", UI_voice_func_bank_selection);
LCDML_add(27, LCDML_1, 2, "V01:INIT", UI_voice_func_voice_selection);
#define _LCDML_DISP_cnt 27
#define _LCDML_DISP_cnt 25
// create menu
LCDML_createMenu(_LCDML_DISP_cnt);
@ -134,24 +129,23 @@ 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};
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)
{
// If something must init, put in in the setup condition
if(LCDML.BT_setup())
if (LCDML.BT_setup())
{
pinMode(BUT_R_PIN, INPUT_PULLUP);
pinMode(BUT_R_PIN, INPUT_PULLUP);
}
//Volatile Variable
long g_LCDML_CONTROL_Encoder_position = ENCODER[ENC_R].read();
bool button = digitalRead(BUT_R_PIN);
if(g_LCDML_CONTROL_Encoder_position <= -3) {
long g_LCDML_CONTROL_Encoder_position[NUM_ENCODER] = {ENCODER[ENC_R].read(), ENCODER[ENC_L].read()};
bool button[NUM_ENCODER] = {digitalRead(BUT_R_PIN), digitalRead(BUT_L_PIN)};
if(!button)
if (g_LCDML_CONTROL_Encoder_position[ENC_R] <= -3)
{
if (!button[ENC_R])
{
LCDML.BT_left();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
@ -159,14 +153,15 @@ void lcdml_menu_control(void)
}
else
{
LCDML.BT_down();
if (menu_state == MENU_R_SHOW)
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();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
@ -174,104 +169,55 @@ void lcdml_menu_control(void)
}
else
{
LCDML.BT_up();
if (menu_state == MENU_R_SHOW)
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
{
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_press_time[ENC_R] = millis();
}
else if(button && !g_LCDML_CONTROL_button_prev[ENC_R]) //rising edge, button not active
{
g_LCDML_CONTROL_button_prev[ENC_R] = HIGH;
if(g_LCDML_CONTROL_button_press_time[ENC_R] < 0)
{
g_LCDML_CONTROL_button_press_time[ENC_R] = millis();
//Reset for left right action
}
else if((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_long_press)
{
LCDML.BT_quit();
}
else if((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press)
{
LCDML.BT_enter();
}
}
}
}
void lcdml_voice_menu_control(void)
{
// 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
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_L] = HIGH;
g_LCDML_CONTROL_button_prev[ENC_R] = HIGH;
if (g_LCDML_CONTROL_button_press_time[ENC_L] < 0)
if (g_LCDML_CONTROL_button_press_time[ENC_R] < 0)
{
g_LCDML_CONTROL_button_press_time[ENC_L] = millis();
g_LCDML_CONTROL_button_press_time[ENC_R] = millis();
//Reset for left right action
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_long_press)
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_long_press)
{
LCDML_Voice.BT_quit();
LCDML.BT_quit();
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_short_press)
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press)
{
Serial.println("------------------------------------------------->LLLLLLLLLLLLLLLLLLLLLLLLLLLLL");
LCDML_Voice.BT_enter();
LCDML.BT_enter();
}
}
}
/*
// checking encoder left (volume)
if (g_LCDML_CONTROL_old_var[ENC_L] != g_LCDML_CONTROL_Encoder_position[ENC_L])
{
if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3)
{
#ifdef DEBUG
Serial.println(F("Volume +"));
#endif
}
else if (g_LCDML_CONTROL_Encoder_position[ENC_L] >= 3)
{
#ifdef DEBUG
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 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++)
{
@ -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
***********************************************************************/
@ -643,61 +478,7 @@ void UI_func_information(uint8_t param)
}
}
void UI_voice_func_bank_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)
void UI_func_voice_selection(uint8_t param)
{
if (LCDML.FUNC_setup()) // ****** SETUP *********
{

@ -148,12 +148,14 @@
// LCD Display
#define I2C_DISPLAY 1
// [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_CHARS 16
#define LCD_LINES 2
#define UI_AUTO_BACK_MS 3000
// Internal timer
#define AUTOSTORE_MS 5000
#define AUTOSTORE_FAST_MS 50
#define VOICE_SELECTION_MS 2000
// EEPROM address
#define EEPROM_START_ADDRESS 0

Loading…
Cancel
Save