From 52fd90cf461a0af754dfcb1d6fbae24d06f3d5b6 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 17 Apr 2021 19:32:57 +0200 Subject: [PATCH] Make action attribute a text value --- src/hasp/hasp_attribute.cpp | 3 ++- src/hasp/hasp_parser.cpp | 17 +++++++++++++++++ src/hasp/hasp_parser.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 5c2f4dc3..7378e2dd 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1454,7 +1454,8 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p break; // attribute_found case ATTR_ACTION: - update ? (void)(obj->user_data.actionid = (uint8_t)val) : attr_out_int(obj, attr, obj->user_data.actionid); + update ? (void)(obj->user_data.actionid = Parser::get_action_id(payload)) + : attr_out_int(obj, attr, obj->user_data.actionid); break; // attribute_found case ATTR_TRANSITION: diff --git a/src/hasp/hasp_parser.cpp b/src/hasp/hasp_parser.cpp index 535ba971..3ac427c1 100644 --- a/src/hasp/hasp_parser.cpp +++ b/src/hasp/hasp_parser.cpp @@ -191,6 +191,23 @@ int Parser::format_bytes(size_t filesize, char* buf, size_t len) return snprintf_P(buf, len, PSTR("%d.%d %ciB"), filesize / 10, filesize % 10, labels[unit]); } +uint8_t Parser::get_action_id(const char* action) +{ + if(!strcasecmp_P(action, PSTR("prev"))) { + return HASP_NUM_PAGE_PREV; + } else if(!strcasecmp_P(action, PSTR("next"))) { + return HASP_NUM_PAGE_NEXT; + } else if(!strcasecmp_P(action, PSTR("back"))) { + return HASP_NUM_PAGE_BACK; + } else if(action[0] == 'p') { + action++; + if(is_only_digits(action)) { + return atoi(action); + } + } + return 0; +} + #ifndef ARDUINO long map(long x, long in_min, long in_max, long out_min, long out_max) { diff --git a/src/hasp/hasp_parser.h b/src/hasp/hasp_parser.h index 28c7c01c..862ee32f 100644 --- a/src/hasp/hasp_parser.h +++ b/src/hasp/hasp_parser.h @@ -13,6 +13,7 @@ class Parser { static bool haspPayloadToColor(const char* payload, lv_color32_t& color); static bool get_event_state(uint8_t eventid); static void get_event_name(uint8_t eventid, char* buffer, size_t size); + static uint8_t get_action_id(const char* action); static uint16_t get_sdbm(const char* str); static bool is_true(const char* s); static bool is_only_digits(const char* s);