From ce0b93943f1e5dee8842a3a66675890b3a6f94c1 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 8 Oct 2019 15:17:23 +0200 Subject: [PATCH] Fix. --- UI.hpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/UI.hpp b/UI.hpp index 191d126..91d5277 100644 --- a/UI.hpp +++ b/UI.hpp @@ -133,6 +133,78 @@ 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}; + + +void lcdml_menu_control(void) +{ + // If something must init, put in in the setup condition + if(LCDML.BT_setup()) + { + 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) { + + if(!button) + { + LCDML.BT_left(); + g_LCDML_CONTROL_button_prev[ENC_R] = LOW; + g_LCDML_CONTROL_button_press_time[ENC_R] = -1; + } + else + { + LCDML.BT_down(); + } + ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position+4); + } + else if(g_LCDML_CONTROL_Encoder_position >= 3) + { + + if(!button) + { + LCDML.BT_right(); + g_LCDML_CONTROL_button_prev[ENC_R] = LOW; + g_LCDML_CONTROL_button_press_time[ENC_R] = -1; + } + else + { + LCDML.BT_up(); + } + ENCODER[ENC_R].write(g_LCDML_CONTROL_Encoder_position-4); + } + else + { + if(!button && g_LCDML_CONTROL_button_prev[ENC_R]) //falling edge, button 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_menu_control(void) { // If something must init, put in in the setup condition @@ -199,7 +271,7 @@ void lcdml_menu_control(void) } } } - +*/ void lcdml_voice_menu_control(void) { // If something must init, put in in the setup condition