Testing the use of object_set_group_state

This commit is contained in:
fvanroie 2021-03-18 23:02:06 +01:00
parent 83bf62d9d6
commit a5d19a2283
2 changed files with 29 additions and 26 deletions

View File

@ -546,24 +546,7 @@ static void cpicker_event_handler(lv_obj_t* obj, lv_event_t event)
// ##################### State Changers ######################################################## // ##################### State Changers ########################################################
// TODO make this a recursive function that goes over all objects only ONCE void object_set_group_value(lv_obj_t* parent, uint8_t groupid, int16_t intval)
void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj)
{
if(groupid == 0) return;
bool state = dispatch_get_event_state(eventid);
for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) {
uint8_t startid = 1;
for(uint8_t objid = startid; objid < 20; objid++) {
lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid);
if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set
lv_obj_set_state(obj, state ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT);
}
}
}
}
void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* payload)
{ {
if(groupid == 0 || parent == nullptr) return; if(groupid == 0 || parent == nullptr) return;
@ -571,10 +554,10 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo
child = lv_obj_get_child(parent, NULL); child = lv_obj_get_child(parent, NULL);
while(child) { while(child) {
/* child found, update it */ /* child found, update it */
if(groupid == child->user_data.groupid) hasp_process_obj_attribute_val(child, NULL, payload, true); if(groupid == child->user_data.groupid) hasp_process_obj_attribute_val(child, NULL, intval, intval, true);
/* update grandchildren */ /* update grandchildren */
object_set_group_value(child, groupid, payload); object_set_group_value(child, groupid, intval);
/* check tabs */ /* check tabs */
if(check_obj_type(child, LV_HASP_TABVIEW)) { if(check_obj_type(child, LV_HASP_TABVIEW)) {
@ -584,10 +567,10 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo
lv_obj_t* tab = lv_tabview_get_tab(child, i); lv_obj_t* tab = lv_tabview_get_tab(child, i);
LOG_VERBOSE(TAG_HASP, F("Found tab %i"), i); LOG_VERBOSE(TAG_HASP, F("Found tab %i"), i);
if(tab->user_data.groupid && groupid == tab->user_data.groupid) if(tab->user_data.groupid && groupid == tab->user_data.groupid)
hasp_process_obj_attribute_val(tab, NULL, payload, true); /* tab found, update it */ hasp_process_obj_attribute_val(tab, NULL, intval, intval, true); /* tab found, update it */
/* check grandchildren */ /* check grandchildren */
object_set_group_value(tab, groupid, payload); object_set_group_value(tab, groupid, intval);
} }
//#endif //#endif
} }
@ -597,10 +580,30 @@ void object_set_group_value(lv_obj_t* parent, uint8_t groupid, const char* paylo
} }
} }
void object_set_group_value(uint8_t groupid, int16_t state) // TODO make this a recursive function that goes over all objects only ONCE
void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max)
{ {
char payload[16]; if(groupid == 0) return;
itoa(state, payload, DEC); if(min == max) return;
for(uint8_t page = 0; page < HASP_NUM_PAGES; page++) {
object_set_group_value(get_page_obj(page), groupid, val);
// uint8_t startid = 1;
// for(uint8_t objid = startid; objid < 20; objid++) {
// lv_obj_t* obj = hasp_find_obj_from_parent_id(get_page_obj(page), objid);
// if(obj && obj != src_obj && obj->user_data.groupid == groupid) { // skip source object, if set
// LOG_VERBOSE(TAG_HASP, F("Found p%db%d in group %d"), page, objid, groupid);
// lv_obj_set_state(obj, val > 0 ? LV_STATE_PRESSED | LV_STATE_CHECKED : LV_STATE_DEFAULT);
// switch(obj->user_data.objid) {
// case HASP_OBJ_ARC:
// case HASP_OBJ_SLIDER:
// case HASP_OBJ_CHECKBOX:
// hasp_process_obj_attribute_val();
// default:
// }
// }
// }
}
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -76,7 +76,7 @@ void hasp_send_obj_attribute_int(lv_obj_t* obj, const char* attribute, int32_t v
void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color); void hasp_send_obj_attribute_color(lv_obj_t* obj, const char* attribute, lv_color_t color);
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload); void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload);
void object_set_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t* src_obj); void object_set_group_state(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max);
void generic_event_handler(lv_obj_t* obj, lv_event_t event); void generic_event_handler(lv_obj_t* obj, lv_event_t event);
void toggle_event_handler(lv_obj_t* obj, lv_event_t event); void toggle_event_handler(lv_obj_t* obj, lv_event_t event);