Seperating encoder functions from control function.

pull/3/head
Holger Wirtz 5 years ago
parent 482e714dec
commit f59d810343
  1. 331
      UI.hpp

331
UI.hpp

@ -76,6 +76,14 @@ void lcdml_menu_display(void);
void lcdml_voice_menu_display(void); void lcdml_voice_menu_display(void);
void lcdml_menu_clear(void); void lcdml_menu_clear(void);
void lcdml_menu_control(void); void lcdml_menu_control(void);
void encoder_right_up(void);
void encoder_right_down(void);
void encoder_right_button_long(void);
void encoder_right_button_short(void);
void encoder_left_up(void);
void encoder_left_down(void);
void encoder_left_button_long(void);
void encoder_left_button_short(void);
void lcdml_voice_menu_control(void); void lcdml_voice_menu_control(void);
void UI_func_sound(uint8_t param); void UI_func_sound(uint8_t param);
void UI_func_reverb_roomsize(uint8_t param); void UI_func_reverb_roomsize(uint8_t param);
@ -170,8 +178,9 @@ void lcdml_menu_control(void)
bool button[NUM_ENCODER] = {digitalRead(BUT_R_PIN), digitalRead(BUT_L_PIN)}; bool button[NUM_ENCODER] = {digitalRead(BUT_R_PIN), digitalRead(BUT_L_PIN)};
/************************************************************************************ /************************************************************************************
Right encoder Basic encoder handlying (from LCDMenuLib2
************************************************************************************/ ************************************************************************************/
// RIGHT
if (g_LCDML_CONTROL_Encoder_position[ENC_R] <= -3) if (g_LCDML_CONTROL_Encoder_position[ENC_R] <= -3)
{ {
if (!button[ENC_R]) if (!button[ENC_R])
@ -182,45 +191,7 @@ void lcdml_menu_control(void)
} }
else else
{ {
switch (menu_state) encoder_right_up();
{
case MENU_EDIT:
case MENU_VOLUME:
menu_state = MENU_EDIT;
LCDML.BT_down();
break;
case MENU_VOICE:
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, Encoder left up"));
#endif
switch (menu_voice)
{
case MENU_VOICE_BANK:
if (configuration.bank < MAX_BANKS)
{
configuration.bank++;
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
}
break;
case MENU_VOICE_SOUND:
if (configuration.voice < MAX_VOICES)
configuration.voice++;
else
{
if (configuration.bank < MAX_BANKS)
{
configuration.bank++;
configuration.voice = 0;
}
}
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
eeprom_write();
}
UI_func_voice_selection(0);
break;
}
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4); ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4);
} }
@ -235,45 +206,7 @@ void lcdml_menu_control(void)
} }
else else
{ {
switch (menu_state) encoder_right_down();
{
case MENU_EDIT:
case MENU_VOLUME:
menu_state = MENU_EDIT;
LCDML.BT_up();
break;
case MENU_VOICE:
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, Encoder left down"));
#endif
switch (menu_voice)
{
case MENU_VOICE_BANK:
if (configuration.bank > 0)
{
configuration.bank--;
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
}
break;
case MENU_VOICE_SOUND:
if (configuration.voice > 0)
configuration.voice--;
else
{
if (configuration.bank > 0)
{
configuration.bank--;
configuration.voice = 31;
}
}
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
eeprom_write();
}
UI_func_voice_selection(0);
break;
}
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4); ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4);
} }
@ -302,35 +235,16 @@ void lcdml_menu_control(void)
} }
else if (menu_state == MENU_VOICE) else if (menu_state == MENU_VOICE)
{ {
#ifdef DEBUG encoder_right_button_long();
Serial.println(F("State: MENU_VOICE, button long press"));
#endif
} }
} }
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press) else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press)
{ {
if (menu_state == MENU_EDIT) encoder_right_button_short();
{
LCDML.BT_enter();
}
else if (menu_state == MENU_VOICE)
{
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, button short press"));
#endif
if (menu_voice == MENU_VOICE_BANK)
menu_voice = MENU_VOICE_SOUND;
else
menu_voice = MENU_VOICE_BANK;
UI_func_voice_selection(0);
}
} }
} }
} }
// LEFT
/************************************************************************************
Left encoder
************************************************************************************/
if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3) if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3)
{ {
if (!button[ENC_L]) if (!button[ENC_L])
@ -341,16 +255,7 @@ void lcdml_menu_control(void)
} }
else else
{ {
#ifdef DEBUG encoder_left_up();
Serial.println(F("Volume +"));
#endif
if (configuration.vol < 0.96)
{
soften_volume.diff = 0.05 / SOFTEN_VALUE_CHANGE_STEPS;
soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS;
eeprom_write();
}
UI_func_volume(0);
} }
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] + 4); ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] + 4);
} }
@ -365,16 +270,7 @@ void lcdml_menu_control(void)
} }
else else
{ {
#ifdef DEBUG encoder_left_down();
Serial.println(F("Volume -"));
#endif
if (configuration.vol > 0.04)
{
soften_volume.diff = -0.05 / SOFTEN_VALUE_CHANGE_STEPS;
soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS;
eeprom_write();
}
UI_func_volume(0);
} }
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] - 4); ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] - 4);
} }
@ -397,28 +293,191 @@ void lcdml_menu_control(void)
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_L]) >= g_LCDML_CONTROL_button_long_press)
{ {
//LCDML.BT_quit(); //LCDML.BT_quit();
#ifdef DEBUG encoder_left_button_long();
Serial.println(F("Encoder left long press"));
#endif
} }
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_L]) >= g_LCDML_CONTROL_button_short_press)
{ {
//LCDML.BT_enter(); //LCDML.BT_enter();
encoder_left_button_short();
}
}
}
}
/************************************************************************************
RIGHT Encoder functions
************************************************************************************/
void encoder_right_up(void)
{
switch (menu_state)
{
case MENU_EDIT:
case MENU_VOLUME:
menu_state = MENU_EDIT;
LCDML.BT_down();
break;
case MENU_VOICE:
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Encoder left short press")); Serial.println(F("State: MENU_VOICE, Encoder left up"));
#endif #endif
if (menu_state == MENU_EDIT) switch (menu_voice)
{ {
menu_state = MENU_VOICE; case MENU_VOICE_BANK:
UI_func_voice_selection(0); if (configuration.bank < MAX_BANKS)
} {
else if (menu_state == MENU_VOICE) configuration.bank++;
{ load_sysex(configuration.bank, configuration.voice);
menu_state = MENU_EDIT; get_voice_names_from_bank(configuration.bank);
LCDML.MENU_goRoot(); }
} break;
case MENU_VOICE_SOUND:
if (configuration.voice < MAX_VOICES)
configuration.voice++;
else
{
if (configuration.bank < MAX_BANKS)
{
configuration.bank++;
configuration.voice = 0;
}
}
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
eeprom_write();
} }
} UI_func_voice_selection(0);
break;
}
}
void encoder_right_down(void)
{
switch (menu_state)
{
case MENU_EDIT:
case MENU_VOLUME:
menu_state = MENU_EDIT;
LCDML.BT_up();
break;
case MENU_VOICE:
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, Encoder left down"));
#endif
switch (menu_voice)
{
case MENU_VOICE_BANK:
if (configuration.bank > 0)
{
configuration.bank--;
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
}
break;
case MENU_VOICE_SOUND:
if (configuration.voice > 0)
configuration.voice--;
else
{
if (configuration.bank > 0)
{
configuration.bank--;
configuration.voice = 31;
}
}
load_sysex(configuration.bank, configuration.voice);
get_voice_names_from_bank(configuration.bank);
eeprom_write();
}
UI_func_voice_selection(0);
break;
}
}
void encoder_right_button_long(void)
{
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, button long press"));
#else
;
#endif
}
void encoder_right_button_short(void)
{
#ifdef DEBUG
Serial.println(F("Encoder right short press"));
#endif
if (menu_state == MENU_EDIT)
{
LCDML.BT_enter();
}
else if (menu_state == MENU_VOICE)
{
#ifdef DEBUG
Serial.println(F("State: MENU_VOICE, button short press"));
#endif
if (menu_voice == MENU_VOICE_BANK)
menu_voice = MENU_VOICE_SOUND;
else
menu_voice = MENU_VOICE_BANK;
UI_func_voice_selection(0);
}
}
/************************************************************************************
LEFT Encoder functions
************************************************************************************/
void encoder_left_up(void)
{
#ifdef DEBUG
Serial.println(F("Volume +"));
#endif
if (configuration.vol < 0.96)
{
soften_volume.diff = 0.05 / SOFTEN_VALUE_CHANGE_STEPS;
soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS;
eeprom_write();
}
UI_func_volume(0);
}
void encoder_left_down(void)
{
#ifdef DEBUG
Serial.println(F("Volume -"));
#endif
if (configuration.vol > 0.04)
{
soften_volume.diff = -0.05 / SOFTEN_VALUE_CHANGE_STEPS;
soften_volume.steps = SOFTEN_VALUE_CHANGE_STEPS;
eeprom_write();
}
UI_func_volume(0);
}
void encoder_left_button_long(void)
{
#ifdef DEBUG
Serial.println(F("Encoder left long press"));
#else
;
#endif
}
void encoder_left_button_short(void)
{
#ifdef DEBUG
Serial.println(F("Encoder left short press"));
#endif
if (menu_state == MENU_EDIT)
{
menu_state = MENU_VOICE;
UI_func_voice_selection(0);
}
else if (menu_state == MENU_VOICE)
{
menu_state = MENU_EDIT;
LCDML.MENU_goRoot();
} }
} }

Loading…
Cancel
Save