Make action attribute a text value

This commit is contained in:
fvanroie 2021-04-17 19:32:57 +02:00
parent 57c0bb29b0
commit 52fd90cf46
3 changed files with 20 additions and 1 deletions

View File

@ -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:

View File

@ -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)
{

View File

@ -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);