diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 5cb56f6c..6863570d 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1963,6 +1963,7 @@ static hasp_attribute_type_t attribute_common_method(lv_obj_t* obj, uint16_t att case ATTR_OPEN: case ATTR_CLOSE: if(!obj_check_type(obj, LV_HASP_DROPDOWN)) return HASP_ATTR_TYPE_NOT_FOUND; + event_reset_last_value_sent(); // Prevents manual selection bug because no manual 'down' occured if(attr_hash == ATTR_OPEN) lv_dropdown_open(obj); else diff --git a/src/hasp/hasp_event.cpp b/src/hasp/hasp_event.cpp index e4d3676b..99e9db36 100644 --- a/src/hasp/hasp_event.cpp +++ b/src/hasp/hasp_event.cpp @@ -30,10 +30,18 @@ #include "lv_core/lv_obj.h" // for tabview ext static lv_style_int_t last_value_sent; +static lv_obj_t* last_obj_sent = NULL; static lv_color_t last_color_sent; void swipe_event_handler(lv_obj_t* obj, lv_event_t event); +// resets the last_value_sent +void event_reset_last_value_sent() +{ + last_obj_sent = NULL; + last_value_sent = INT16_MIN; +} + /** * Clean-up allocated memory before an object is deleted * @param obj pointer to an object to clean-up @@ -403,6 +411,7 @@ void textarea_event_handler(lv_obj_t* obj, lv_event_t event) void generic_event_handler(lv_obj_t* obj, lv_event_t event) { log_event("generic", event); + last_obj_sent = obj; // updated but not used in this function switch(event) { case LV_EVENT_GESTURE: @@ -479,6 +488,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) } dispatch_current_page(); } + } else { char data[512]; { @@ -494,7 +504,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) } // Update group objects and gpios on release - if(last_value_sent != LV_EVENT_LONG_PRESSED || last_value_sent != LV_EVENT_LONG_PRESSED_REPEAT) { + if(last_value_sent != LV_EVENT_LONG_PRESSED && last_value_sent != LV_EVENT_LONG_PRESSED_REPEAT) { bool state = Parser::get_event_state(last_value_sent); event_update_group(obj->user_data.groupid, obj, state, state, HASP_EVENT_OFF, HASP_EVENT_ON); } @@ -508,6 +518,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event) void toggle_event_handler(lv_obj_t* obj, lv_event_t event) { log_event("toggle", event); + last_obj_sent = obj; // updated but not used in this function uint8_t hasp_event_id; if(!translate_event(obj, event, hasp_event_id)) return; @@ -606,8 +617,11 @@ void selector_event_handler(lv_obj_t* obj, lv_event_t event) return; // Invalid selector type } - if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val) return; // same value as before + if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj) + return; // same object and value as before + last_value_sent = val; + last_obj_sent = obj; event_object_selection_changed(obj, hasp_event_id, val, buffer); if(obj->user_data.groupid && max > 0) // max a cannot be 0, its the divider @@ -642,9 +656,11 @@ void btnmatrix_event_handler(lv_obj_t* obj, lv_event_t event) strncpy(buffer, txt, sizeof(buffer)); } - if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val) return; // same value as before + if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj) + return; // same object and value as before last_value_sent = val; + last_obj_sent = obj; event_object_selection_changed(obj, hasp_event_id, val, buffer); // if(max > 0) // max a cannot be 0, its the divider @@ -678,9 +694,11 @@ void msgbox_event_handler(lv_obj_t* obj, lv_event_t event) buffer[0] = 0; // empty string } - if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val) return; // same value as before + if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj) + return; // same object and value as before last_value_sent = val; + last_obj_sent = obj; event_object_selection_changed(obj, hasp_event_id, val, buffer); // if(max > 0) event_update_group(obj->user_data.groupid, obj, val, 0, max); } @@ -716,9 +734,11 @@ void slider_event_handler(lv_obj_t* obj, lv_event_t event) return; // not a slider } - if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val) return; // same value as before + if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj) + return; // same object and value as before last_value_sent = val; + last_obj_sent = obj; event_object_val_event(obj, hasp_event_id, val); if(obj->user_data.groupid && (hasp_event_id == HASP_EVENT_CHANGED || hasp_event_id == HASP_EVENT_UP) && min != max) @@ -783,7 +803,8 @@ void calendar_event_handler(lv_obj_t* obj, lv_event_t event) if(!date) return; lv_style_int_t val = date->day + date->month * 31; - if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val) return; // same value as before + if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj) + return; // same object and value as before char data[512]; { @@ -791,6 +812,7 @@ void calendar_event_handler(lv_obj_t* obj, lv_event_t event) Parser::get_event_name(hasp_event_id, eventname, sizeof(eventname)); last_value_sent = val; + last_obj_sent = obj; if(const char* tag = my_obj_get_tag(obj)) snprintf_P(data, sizeof(data), diff --git a/src/hasp/hasp_event.h b/src/hasp/hasp_event.h index 0612584c..a10b862a 100644 --- a/src/hasp/hasp_event.h +++ b/src/hasp/hasp_event.h @@ -28,4 +28,7 @@ void cpicker_event_handler(lv_obj_t* obj, lv_event_t event); void calendar_event_handler(lv_obj_t* obj, lv_event_t event); void textarea_event_handler(lv_obj_t* obj, lv_event_t event); +// Other functions +void event_reset_last_value_sent(); + #endif // HASP_EVENT_H \ No newline at end of file