Seperating encoder functions from control function.

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

231
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])
@ -181,6 +190,124 @@ void lcdml_menu_control(void)
g_LCDML_CONTROL_button_press_time[ENC_R] = -1; g_LCDML_CONTROL_button_press_time[ENC_R] = -1;
} }
else else
{
encoder_right_up();
}
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4);
}
else if (g_LCDML_CONTROL_Encoder_position[ENC_R] >= 3)
{
if (!button[ENC_R])
{
LCDML.BT_right();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_R] = -1;
}
else
{
encoder_right_down();
}
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4);
}
else
{
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[ENC_R] && !g_LCDML_CONTROL_button_prev[ENC_R]) //rising edge, button[ENC_R] 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();
if (menu_state == MENU_EDIT)
{
LCDML.BT_quit();
}
else if (menu_state == MENU_VOICE)
{
encoder_right_button_long();
}
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press)
{
encoder_right_button_short();
}
}
}
// LEFT
if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3)
{
if (!button[ENC_L])
{
//LCDML.BT_left();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{
encoder_left_up();
}
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] + 4);
}
else if (g_LCDML_CONTROL_Encoder_position[ENC_L] >= 3)
{
if (!button[ENC_L])
{
//LCDML.BT_right();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{
encoder_left_down();
}
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] - 4);
}
else
{
if (!button[ENC_L] && g_LCDML_CONTROL_button_prev[ENC_L]) //falling edge, button[ENC_L] pressed
{
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = millis();
}
else if (button[ENC_L] && !g_LCDML_CONTROL_button_prev[ENC_L]) //rising edge, button[ENC_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();
//Reset for left right action
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_long_press)
{
//LCDML.BT_quit();
encoder_left_button_long();
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_short_press)
{
//LCDML.BT_enter();
encoder_left_button_short();
}
}
}
}
/************************************************************************************
RIGHT Encoder functions
************************************************************************************/
void encoder_right_up(void)
{ {
switch (menu_state) switch (menu_state)
{ {
@ -222,18 +349,8 @@ void lcdml_menu_control(void)
break; break;
} }
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] + 4);
}
else if (g_LCDML_CONTROL_Encoder_position[ENC_R] >= 3)
{
if (!button[ENC_R]) void encoder_right_down(void)
{
LCDML.BT_right();
g_LCDML_CONTROL_button_prev[ENC_R] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_R] = -1;
}
else
{ {
switch (menu_state) switch (menu_state)
{ {
@ -275,40 +392,21 @@ void lcdml_menu_control(void)
break; break;
} }
} }
ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position[ENC_R] - 4);
}
else
{
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[ENC_R] && !g_LCDML_CONTROL_button_prev[ENC_R]) //rising edge, button[ENC_R] not active
{
g_LCDML_CONTROL_button_prev[ENC_R] = HIGH;
if (g_LCDML_CONTROL_button_press_time[ENC_R] < 0) void encoder_right_button_long(void)
{
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();
if (menu_state == MENU_EDIT)
{
LCDML.BT_quit();
}
else if (menu_state == MENU_VOICE)
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("State: MENU_VOICE, button long press")); Serial.println(F("State: MENU_VOICE, button long press"));
#else
;
#endif #endif
} }
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_R]) >= g_LCDML_CONTROL_button_short_press) void encoder_right_button_short(void)
{ {
#ifdef DEBUG
Serial.println(F("Encoder right short press"));
#endif
if (menu_state == MENU_EDIT) if (menu_state == MENU_EDIT)
{ {
LCDML.BT_enter(); LCDML.BT_enter();
@ -325,21 +423,11 @@ void lcdml_menu_control(void)
UI_func_voice_selection(0); UI_func_voice_selection(0);
} }
} }
}
}
/************************************************************************************ /************************************************************************************
Left encoder LEFT Encoder functions
************************************************************************************/ ************************************************************************************/
if (g_LCDML_CONTROL_Encoder_position[ENC_L] <= -3) void encoder_left_up(void)
{
if (!button[ENC_L])
{
//LCDML.BT_left();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Volume +")); Serial.println(F("Volume +"));
@ -352,18 +440,8 @@ void lcdml_menu_control(void)
} }
UI_func_volume(0); UI_func_volume(0);
} }
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] + 4);
}
else if (g_LCDML_CONTROL_Encoder_position[ENC_L] >= 3)
{
if (!button[ENC_L]) void encoder_left_down(void)
{
//LCDML.BT_right();
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = -1;
}
else
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Volume -")); Serial.println(F("Volume -"));
@ -376,34 +454,18 @@ void lcdml_menu_control(void)
} }
UI_func_volume(0); UI_func_volume(0);
} }
ENCODER[ENC_L].write(g_LCDML_CONTROL_Encoder_position[ENC_L] - 4);
}
else
{
if (!button[ENC_L] && g_LCDML_CONTROL_button_prev[ENC_L]) //falling edge, button[ENC_L] pressed
{
g_LCDML_CONTROL_button_prev[ENC_L] = LOW;
g_LCDML_CONTROL_button_press_time[ENC_L] = millis();
}
else if (button[ENC_L] && !g_LCDML_CONTROL_button_prev[ENC_L]) //rising edge, button[ENC_L] not active
{
g_LCDML_CONTROL_button_prev[ENC_L] = HIGH;
if (g_LCDML_CONTROL_button_press_time[ENC_L] < 0) void encoder_left_button_long(void)
{
g_LCDML_CONTROL_button_press_time[ENC_L] = millis();
//Reset for left right action
}
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_long_press)
{ {
//LCDML.BT_quit();
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Encoder left long press")); Serial.println(F("Encoder left long press"));
#else
;
#endif #endif
} }
else if ((millis() - g_LCDML_CONTROL_button_press_time[ENC_L]) >= g_LCDML_CONTROL_button_short_press)
void encoder_left_button_short(void)
{ {
//LCDML.BT_enter();
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Encoder left short press")); Serial.println(F("Encoder left short press"));
#endif #endif
@ -418,9 +480,6 @@ void lcdml_menu_control(void)
LCDML.MENU_goRoot(); LCDML.MENU_goRoot();
} }
} }
}
}
}
/*********************************************************************** /***********************************************************************
DISPLAY DISPLAY

Loading…
Cancel
Save