From f0a4233b3930ce16425328b1eee07fad632fb48b Mon Sep 17 00:00:00 2001 From: philippe44 Date: Wed, 15 Jan 2020 16:17:22 -0800 Subject: [PATCH] process_button fix + option for remap --- components/services/audio_controls.c | 23 +++++++++++++---------- components/services/audio_controls.h | 7 +++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/components/services/audio_controls.c b/components/services/audio_controls.c index 5700ec54..a1da7c52 100644 --- a/components/services/audio_controls.c +++ b/components/services/audio_controls.c @@ -18,7 +18,7 @@ * along with this program. If not, see . * */ -//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE + #include #include #include @@ -68,18 +68,18 @@ static const char * TAG = "audio controls"; static actrls_config_t *json_config; static actrls_t default_controls, current_controls; -static void control_handler(void *id, button_event_e event, button_press_e press, bool long_press) { - actrls_config_t *key = (actrls_config_t*) id; +static void control_handler(void *client, button_event_e event, button_press_e press, bool long_press) { + actrls_config_t *key = (actrls_config_t*) client; actrls_action_e action; switch(press) { case BUTTON_NORMAL: - if (long_press) action = key->longpress[event == BUTTON_PRESSED ? 0 : 1]; - else action = key->normal[event == BUTTON_PRESSED ? 0 : 1]; + if (long_press) action = key->longpress[event == BUTTON_PRESSED ? 0 : 1].action; + else action = key->normal[event == BUTTON_PRESSED ? 0 : 1].action; break; case BUTTON_SHIFTED: - if (long_press) action = key->longshifted[event == BUTTON_PRESSED ? 0 : 1]; - else action = key->shifted[event == BUTTON_PRESSED ? 0 : 1]; + if (long_press) action = key->longshifted[event == BUTTON_PRESSED ? 0 : 1].action; + else action = key->shifted[event == BUTTON_PRESSED ? 0 : 1].action; break; default: action = ACTRLS_NONE; @@ -88,8 +88,11 @@ static void control_handler(void *id, button_event_e event, button_press_e press ESP_LOGD(TAG, "control gpio:%u press:%u long:%u event:%u action:%u", key->gpio, press, long_press, event, action); - if (action != ACTRLS_NONE) { - ESP_LOGD(TAG, " calling action %u", action); + if (action > ACTRLS_MAX) { + // need to do the remap here + ESP_LOGD(TAG, "remapping buttons"); + } else if (action != ACTRLS_NONE) { + ESP_LOGD(TAG, "calling action %u", action); if (current_controls[action]) (*current_controls[action])(); } } @@ -227,7 +230,7 @@ esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_confi } esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_config) { - esp_err_t err= ESP_FAIL; + esp_err_t err= ESP_OK; const cJSON *member; cJSON_ArrayForEach(member, button) diff --git a/components/services/audio_controls.h b/components/services/audio_controls.h index eaddfe40..2a63f1df 100644 --- a/components/services/audio_controls.h +++ b/components/services/audio_controls.h @@ -31,14 +31,17 @@ typedef void (*actrls_handler)(void); typedef actrls_handler actrls_t[ACTRLS_MAX - ACTRLS_NONE - 1]; // BEWARE any change to struct below must be mapped to actrls_config_map -typedef struct { +typedef struct actrl_config_s { int gpio; int type; bool pull; int debounce; int long_press; int shifter_gpio; - actrls_action_e normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased + union { + actrls_action_e action; + struct actrl_config_s *config; + } normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased } actrls_config_t; esp_err_t actrls_init(int n, const actrls_config_t *config);