mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 20:56:37 +00:00
Allow jsonl for existing objects
This commit is contained in:
parent
0112980ad1
commit
977ee521d1
@ -224,11 +224,11 @@ void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t
|
|||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[40]; // "#ffffff","r":"255","g":"255","b":"255"
|
||||||
lv_color32_t c32;
|
lv_color32_t c32;
|
||||||
c32.full = lv_color_to32(color);
|
c32.full = lv_color_to32(color);
|
||||||
snprintf(buffer, sizeof(buffer), PSTR("#%02x%02x%02x\",\"r\":\"%d\",\"g\":\"%d\",\"b\":\"%d"), c32.ch.red, c32.ch.green, c32.ch.blue, c32.ch.red,
|
snprintf(buffer, sizeof(buffer), PSTR("#%02x%02x%02x\",\"r\":\"%d\",\"g\":\"%d\",\"b\":\"%d"), c32.ch.red,
|
||||||
c32.ch.green, c32.ch.blue);
|
c32.ch.green, c32.ch.blue, c32.ch.red, c32.ch.green, c32.ch.blue);
|
||||||
hasp_send_obj_attribute_str(obj, attribute, buffer);
|
hasp_send_obj_attribute_str(obj, attribute, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,8 +442,8 @@ static void cpicker_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
char color[6];
|
char color[6];
|
||||||
snprintf_P(color, sizeof(color), PSTR("color"));
|
snprintf_P(color, sizeof(color), PSTR("color"));
|
||||||
|
|
||||||
// if(event == LV_EVENT_VALUE_CHANGED) hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj));
|
if(event == LV_EVENT_VALUE_CHANGED) hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj));
|
||||||
if(event == LV_EVENT_RELEASED) hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj));
|
// if(event == LV_EVENT_RELEASED) hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -500,28 +500,21 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, co
|
|||||||
*/
|
*/
|
||||||
void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||||
{
|
{
|
||||||
/* Validate page */
|
/* Page selection: page is the default parent_obj */
|
||||||
// uint8_t pageid = config[F("page")].isNull() ? haspGetPage() : config[F("page")].as<uint8_t>();
|
uint8_t pageid = config[F("page")].isNull() ? saved_page_id : config[F("page")].as<uint8_t>();
|
||||||
uint8_t pageid = config[F("page")].isNull() ? saved_page_id : config[F("page")].as<uint8_t>();
|
lv_obj_t * parent_obj = get_page_obj(pageid);
|
||||||
|
if(!parent_obj) {
|
||||||
/* Page selection */
|
|
||||||
lv_obj_t * page = get_page_obj(pageid);
|
|
||||||
if(!page) {
|
|
||||||
return Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid);
|
return Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid);
|
||||||
} else {
|
} else {
|
||||||
saved_page_id = pageid; /* save the current pageid */
|
saved_page_id = pageid; /* save the current pageid */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate type */
|
// lv_obj_t * parent_obj = page;
|
||||||
if(config[F("objid")].isNull()) return; // comments
|
|
||||||
|
|
||||||
lv_obj_t * parent_obj = page;
|
|
||||||
if(!config[F("parentid")].isNull()) {
|
if(!config[F("parentid")].isNull()) {
|
||||||
uint8_t parentid = config[F("parentid")].as<uint8_t>();
|
uint8_t parentid = config[F("parentid")].as<uint8_t>();
|
||||||
parent_obj = hasp_find_obj_from_parent_id(page, parentid);
|
parent_obj = hasp_find_obj_from_parent_id(parent_obj, parentid);
|
||||||
if(!parent_obj) {
|
if(!parent_obj) {
|
||||||
return Log.warning(TAG_HASP, F("Parent ID p[%u].b[%u] not found, skipping..."), pageid, parentid);
|
return Log.warning(TAG_HASP, F("Parent ID p[%u].b[%u] not found, skipping..."), pageid, parentid);
|
||||||
// parent_obj = page; // don't create on the page instead ??
|
|
||||||
} else {
|
} else {
|
||||||
Log.verbose(TAG_HASP, F("Parent ID p[%u].b[%u] found"), pageid, parentid);
|
Log.verbose(TAG_HASP, F("Parent ID p[%u].b[%u] found"), pageid, parentid);
|
||||||
}
|
}
|
||||||
@ -534,256 +527,279 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
|||||||
/* Define Objects*/
|
/* Define Objects*/
|
||||||
lv_obj_t * obj = hasp_find_obj_from_parent_id(parent_obj, id);
|
lv_obj_t * obj = hasp_find_obj_from_parent_id(parent_obj, id);
|
||||||
if(obj) {
|
if(obj) {
|
||||||
return Log.warning(TAG_HASP, F("Object ID %u already exists!"), id);
|
// return Log.warning(TAG_HASP, F("Object ID %u already exists!"), id);
|
||||||
}
|
|
||||||
|
|
||||||
switch(objid) {
|
} else {
|
||||||
/* ----- Basic Objects ------ */
|
|
||||||
case LV_HASP_BTNMATRIX:
|
|
||||||
obj = lv_btnmatrix_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btnmap_event_handler);
|
|
||||||
break;
|
|
||||||
case LV_HASP_TABLE:
|
|
||||||
obj = lv_table_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, table_event_handler);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LV_HASP_BUTTON:
|
/* Validate type */
|
||||||
obj = lv_btn_create(parent_obj, NULL);
|
if(config[F("objid")].isNull()) return; // comments
|
||||||
if(obj) {
|
|
||||||
lv_obj_t * lbl = lv_label_create(obj, NULL);
|
switch(objid) {
|
||||||
if(lbl) {
|
/* ----- Basic Objects ------ */
|
||||||
lv_label_set_text(lbl, "");
|
case LV_HASP_BTNMATRIX:
|
||||||
lbl->user_data.objid = LV_HASP_LABEL;
|
obj = lv_btnmatrix_create(parent_obj, NULL);
|
||||||
lv_obj_align(lbl, NULL, LV_ALIGN_CENTER, 0, 0);
|
if(obj) lv_obj_set_event_cb(obj, btnmap_event_handler);
|
||||||
|
break;
|
||||||
|
case LV_HASP_TABLE:
|
||||||
|
obj = lv_table_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, table_event_handler);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LV_HASP_BUTTON:
|
||||||
|
obj = lv_btn_create(parent_obj, NULL);
|
||||||
|
if(obj) {
|
||||||
|
lv_obj_t * lbl = lv_label_create(obj, NULL);
|
||||||
|
if(lbl) {
|
||||||
|
lv_label_set_text(lbl, "");
|
||||||
|
lbl->user_data.objid = LV_HASP_LABEL;
|
||||||
|
lv_obj_align(lbl, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
}
|
||||||
|
lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
}
|
}
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
break;
|
||||||
|
|
||||||
|
case LV_HASP_CHECKBOX:
|
||||||
|
obj = lv_checkbox_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, checkbox_event_handler);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LV_HASP_LABEL: {
|
||||||
|
obj = lv_label_create(parent_obj, NULL);
|
||||||
|
/* click area padding */
|
||||||
|
// uint8_t padh = config[F("padh")].as<uint8_t>();
|
||||||
|
// uint8_t padv = config[F("padv")].as<uint8_t>();
|
||||||
|
/* text align */
|
||||||
|
// if(padh > 0 || padv > 0) {
|
||||||
|
// lv_obj_set_ext_click_area(obj, padh, padh, padv, padv);
|
||||||
|
// }
|
||||||
|
// if(!config[F("align")].isNull()) {
|
||||||
|
// lv_label_set_align(obj, LV_LABEL_ALIGN_CENTER);
|
||||||
|
// }
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_IMAGE: {
|
||||||
|
obj = lv_img_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_ARC: {
|
||||||
|
obj = lv_arc_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_CONTAINER: {
|
||||||
|
obj = lv_cont_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_OBJECT: {
|
||||||
|
obj = lv_obj_create(parent_obj, NULL);
|
||||||
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_PAGE: {
|
||||||
|
obj = lv_page_create(parent_obj, NULL);
|
||||||
|
// No event handler for pages
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case LV_HASP_CHECKBOX:
|
|
||||||
obj = lv_checkbox_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, checkbox_event_handler);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LV_HASP_LABEL: {
|
|
||||||
obj = lv_label_create(parent_obj, NULL);
|
|
||||||
/* click area padding */
|
|
||||||
// uint8_t padh = config[F("padh")].as<uint8_t>();
|
|
||||||
// uint8_t padv = config[F("padv")].as<uint8_t>();
|
|
||||||
/* text align */
|
|
||||||
// if(padh > 0 || padv > 0) {
|
|
||||||
// lv_obj_set_ext_click_area(obj, padh, padh, padv, padv);
|
|
||||||
// }
|
|
||||||
// if(!config[F("align")].isNull()) {
|
|
||||||
// lv_label_set_align(obj, LV_LABEL_ALIGN_CENTER);
|
|
||||||
// }
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LV_HASP_IMAGE: {
|
|
||||||
obj = lv_img_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LV_HASP_ARC: {
|
|
||||||
obj = lv_arc_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LV_HASP_CONTAINER: {
|
|
||||||
obj = lv_cont_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LV_HASP_OBJECT: {
|
|
||||||
obj = lv_obj_create(parent_obj, NULL);
|
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LV_HASP_PAGE: {
|
|
||||||
obj = lv_page_create(parent_obj, NULL);
|
|
||||||
// No event handler for pages
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#if LV_USE_WIN && LVGL_VERSION_MAJOR == 7
|
#if LV_USE_WIN && LVGL_VERSION_MAJOR == 7
|
||||||
case LV_HASP_WINDOW: {
|
case LV_HASP_WINDOW: {
|
||||||
obj = lv_win_create(parent_obj, NULL);
|
obj = lv_win_create(parent_obj, NULL);
|
||||||
// No event handler for pages
|
// No event handler for pages
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if LVGL_VERSION_MAJOR == 8
|
#if LVGL_VERSION_MAJOR == 8
|
||||||
case LV_HASP_LED: {
|
case LV_HASP_LED: {
|
||||||
obj = lv_led_create(parent_obj);
|
obj = lv_led_create(parent_obj);
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LV_HASP_TILEVIEW: {
|
case LV_HASP_TILEVIEW: {
|
||||||
obj = lv_tileview_create(parent_obj);
|
obj = lv_tileview_create(parent_obj);
|
||||||
// No event handler for tileviews
|
// No event handler for tileviews
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LV_HASP_TABVIEW: {
|
case LV_HASP_TABVIEW: {
|
||||||
obj = lv_tabview_create(parent_obj, LV_DIR_TOP, 100);
|
obj = lv_tabview_create(parent_obj, LV_DIR_TOP, 100);
|
||||||
// No event handler for tabs
|
// No event handler for tabs
|
||||||
if(obj) {
|
if(obj) {
|
||||||
lv_obj_t * tab;
|
lv_obj_t * tab;
|
||||||
tab = lv_tabview_add_tab(obj, "tab 1");
|
tab = lv_tabview_add_tab(obj, "tab 1");
|
||||||
// lv_obj_set_user_data(tab, id + 1);
|
// lv_obj_set_user_data(tab, id + 1);
|
||||||
tab = lv_tabview_add_tab(obj, "tab 2");
|
tab = lv_tabview_add_tab(obj, "tab 2");
|
||||||
// lv_obj_set_user_data(tab, id + 2);
|
// lv_obj_set_user_data(tab, id + 2);
|
||||||
tab = lv_tabview_add_tab(obj, "tab 3");
|
tab = lv_tabview_add_tab(obj, "tab 3");
|
||||||
// lv_obj_set_user_data(tab, id + 3);
|
// lv_obj_set_user_data(tab, id + 3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
case LV_HASP_LED: {
|
case LV_HASP_LED: {
|
||||||
obj = lv_led_create(parent_obj, NULL);
|
obj = lv_led_create(parent_obj, NULL);
|
||||||
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
if(obj) lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LV_HASP_TILEVIEW: {
|
case LV_HASP_TILEVIEW: {
|
||||||
obj = lv_tileview_create(parent_obj, NULL);
|
obj = lv_tileview_create(parent_obj, NULL);
|
||||||
// No event handler for tileviews
|
// No event handler for tileviews
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LV_HASP_TABVIEW: {
|
case LV_HASP_TABVIEW: {
|
||||||
obj = lv_tabview_create(parent_obj, NULL);
|
obj = lv_tabview_create(parent_obj, NULL);
|
||||||
// No event handler for tabs
|
// No event handler for tabs
|
||||||
if(obj) {
|
if(obj) {
|
||||||
lv_obj_t * tab;
|
lv_obj_t * tab;
|
||||||
tab = lv_tabview_add_tab(obj, "tab 1");
|
tab = lv_tabview_add_tab(obj, "tab 1");
|
||||||
// lv_obj_set_user_data(tab, id + 1);
|
// lv_obj_set_user_data(tab, id + 1);
|
||||||
tab = lv_tabview_add_tab(obj, "tab 2");
|
tab = lv_tabview_add_tab(obj, "tab 2");
|
||||||
// lv_obj_set_user_data(tab, id + 2);
|
// lv_obj_set_user_data(tab, id + 2);
|
||||||
tab = lv_tabview_add_tab(obj, "tab 3");
|
tab = lv_tabview_add_tab(obj, "tab 3");
|
||||||
// lv_obj_set_user_data(tab, id + 3);
|
// lv_obj_set_user_data(tab, id + 3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
/* ----- Color Objects ------ */
|
/* ----- Color Objects ------ */
|
||||||
case LV_HASP_CPICKER: {
|
case LV_HASP_CPICKER: {
|
||||||
obj = lv_cpicker_create(parent_obj, NULL);
|
obj = lv_cpicker_create(parent_obj, NULL);
|
||||||
if(obj) lv_obj_set_event_cb(obj, cpicker_event_handler);
|
if(obj) lv_obj_set_event_cb(obj, cpicker_event_handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LV_USE_PRELOAD != 0
|
#if LV_USE_PRELOAD != 0
|
||||||
case LV_HASP_PRELOADER: {
|
case LV_HASP_PRELOADER: {
|
||||||
obj = lv_spinner_create(parent_obj, NULL);
|
obj = lv_spinner_create(parent_obj, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* ----- Range Objects ------ */
|
/* ----- Range Objects ------ */
|
||||||
case LV_HASP_SLIDER: {
|
case LV_HASP_SLIDER: {
|
||||||
obj = lv_slider_create(parent_obj, NULL);
|
obj = lv_slider_create(parent_obj, NULL);
|
||||||
if(obj) {
|
if(obj) {
|
||||||
lv_slider_set_range(obj, 0, 100);
|
lv_slider_set_range(obj, 0, 100);
|
||||||
lv_obj_set_event_cb(obj, slider_event_handler);
|
lv_obj_set_event_cb(obj, slider_event_handler);
|
||||||
|
}
|
||||||
|
// bool knobin = config[F("knobin")].as<bool>() | true;
|
||||||
|
// lv_slider_set_knob_in(obj, knobin);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// bool knobin = config[F("knobin")].as<bool>() | true;
|
case LV_HASP_GAUGE: {
|
||||||
// lv_slider_set_knob_in(obj, knobin);
|
obj = lv_gauge_create(parent_obj, NULL);
|
||||||
break;
|
if(obj) {
|
||||||
}
|
lv_gauge_set_range(obj, 0, 100);
|
||||||
case LV_HASP_GAUGE: {
|
lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
obj = lv_gauge_create(parent_obj, NULL);
|
}
|
||||||
if(obj) {
|
break;
|
||||||
lv_gauge_set_range(obj, 0, 100);
|
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
}
|
}
|
||||||
break;
|
case LV_HASP_BAR: {
|
||||||
}
|
obj = lv_bar_create(parent_obj, NULL);
|
||||||
case LV_HASP_BAR: {
|
if(obj) {
|
||||||
obj = lv_bar_create(parent_obj, NULL);
|
lv_bar_set_range(obj, 0, 100);
|
||||||
if(obj) {
|
lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
lv_bar_set_range(obj, 0, 100);
|
}
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case LV_HASP_LMETER: {
|
||||||
}
|
obj = lv_linemeter_create(parent_obj, NULL);
|
||||||
case LV_HASP_LMETER: {
|
if(obj) {
|
||||||
obj = lv_linemeter_create(parent_obj, NULL);
|
lv_linemeter_set_range(obj, 0, 100);
|
||||||
if(obj) {
|
lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
lv_linemeter_set_range(obj, 0, 100);
|
}
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case LV_HASP_CHART: {
|
||||||
}
|
obj = lv_chart_create(parent_obj, NULL);
|
||||||
case LV_HASP_CHART: {
|
if(obj) {
|
||||||
obj = lv_chart_create(parent_obj, NULL);
|
lv_chart_set_range(obj, 0, 100);
|
||||||
if(obj) {
|
lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
lv_chart_set_range(obj, 0, 100);
|
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
|
||||||
|
|
||||||
lv_chart_add_series(obj, LV_COLOR_RED);
|
lv_chart_add_series(obj, LV_COLOR_RED);
|
||||||
lv_chart_add_series(obj, LV_COLOR_GREEN);
|
lv_chart_add_series(obj, LV_COLOR_GREEN);
|
||||||
lv_chart_add_series(obj, LV_COLOR_BLUE);
|
lv_chart_add_series(obj, LV_COLOR_BLUE);
|
||||||
|
|
||||||
lv_chart_series_t * ser = lv_chart_get_series(obj, 2);
|
lv_chart_series_t * ser = lv_chart_get_series(obj, 2);
|
||||||
lv_chart_set_next(obj, ser, 10);
|
lv_chart_set_next(obj, ser, 10);
|
||||||
lv_chart_set_next(obj, ser, 20);
|
lv_chart_set_next(obj, ser, 20);
|
||||||
lv_chart_set_next(obj, ser, 30);
|
lv_chart_set_next(obj, ser, 30);
|
||||||
lv_chart_set_next(obj, ser, 40);
|
lv_chart_set_next(obj, ser, 40);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----- On/Off Objects ------ */
|
/* ----- On/Off Objects ------ */
|
||||||
case LV_HASP_SWITCH: {
|
case LV_HASP_SWITCH: {
|
||||||
obj = lv_switch_create(parent_obj, NULL);
|
obj = lv_switch_create(parent_obj, NULL);
|
||||||
if(obj) lv_obj_set_event_cb(obj, switch_event_handler);
|
if(obj) lv_obj_set_event_cb(obj, switch_event_handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* ----- List Object ------- */
|
/* ----- List Object ------- */
|
||||||
case LV_HASP_DDLIST: {
|
case LV_HASP_DDLIST: {
|
||||||
obj = lv_dropdown_create(parent_obj, NULL);
|
obj = lv_dropdown_create(parent_obj, NULL);
|
||||||
if(obj) {
|
if(obj) {
|
||||||
lv_dropdown_set_draw_arrow(obj, true);
|
lv_dropdown_set_draw_arrow(obj, true);
|
||||||
// lv_dropdown_set_anim_time(obj, 200);
|
// lv_dropdown_set_anim_time(obj, 200);
|
||||||
lv_obj_set_top(obj, true);
|
lv_obj_set_top(obj, true);
|
||||||
|
// lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
|
||||||
|
lv_obj_set_event_cb(obj, ddlist_event_handler);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_ROLLER: {
|
||||||
|
obj = lv_roller_create(parent_obj, NULL);
|
||||||
// lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
|
// lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
|
||||||
lv_obj_set_event_cb(obj, ddlist_event_handler);
|
if(obj) {
|
||||||
|
lv_roller_set_auto_fit(obj, false);
|
||||||
|
lv_obj_set_event_cb(obj, roller_event_handler);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
/* ----- Other Object ------ */
|
||||||
case LV_HASP_ROLLER: {
|
// default:
|
||||||
obj = lv_roller_create(parent_obj, NULL);
|
// return Log.warning(TAG_HASP, F("Unsupported Object ID %u"), objid);
|
||||||
// lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
|
|
||||||
if(obj) {
|
|
||||||
lv_roller_set_auto_fit(obj, false);
|
|
||||||
lv_obj_set_event_cb(obj, roller_event_handler);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----- Other Object ------ */
|
/* No object was actually created */
|
||||||
// default:
|
if(!obj) {
|
||||||
// return Log.warning(TAG_HASP, F("Unsupported Object ID %u"), objid);
|
return Log.error(TAG_HASP, F("Object ID %u is NULL, skipping..."), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent losing press when the press is slid out of the objects.
|
||||||
|
// (E.g. a Button can be released out of it if it was being pressed)
|
||||||
|
lv_obj_add_protect(obj, LV_PROTECT_PRESS_LOST);
|
||||||
|
|
||||||
|
/* id tag the object */
|
||||||
|
// lv_obj_set_user_data(obj, id);
|
||||||
|
obj->user_data.id = id;
|
||||||
|
obj->user_data.objid = objid; //& 0b11111;
|
||||||
|
obj->user_data.groupid = groupid; // & 0b111;
|
||||||
|
|
||||||
|
/** testing start **/
|
||||||
|
uint8_t temp;
|
||||||
|
if(!hasp_find_id_from_obj(obj, &pageid, &temp)) {
|
||||||
|
return Log.error(TAG_HASP, F("Lost track of the created object, not found!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** verbose reporting **/
|
||||||
|
lv_obj_type_t list;
|
||||||
|
lv_obj_get_type(obj, &list);
|
||||||
|
Log.verbose(TAG_HASP, F(" * p[%u].b[%u] = %s"), pageid, temp, list.type[0]);
|
||||||
|
|
||||||
|
/* test double-check */
|
||||||
|
lv_obj_t * test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp);
|
||||||
|
if(test != obj) {
|
||||||
|
return Log.error(TAG_HASP, F("Objects DO NOT match!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No object was actually created */
|
|
||||||
if(!obj) {
|
|
||||||
return Log.warning(TAG_HASP, F("Object ID %u is NULL, skipping..."), id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent losing press when the press is slid out of the objects.
|
|
||||||
// (E.g. a Button can be released out of it if it was being pressed)
|
|
||||||
lv_obj_add_protect(obj, LV_PROTECT_PRESS_LOST);
|
|
||||||
|
|
||||||
/* id tag the object */
|
|
||||||
// lv_obj_set_user_data(obj, id);
|
|
||||||
obj->user_data.id = id;
|
|
||||||
obj->user_data.objid = objid; //& 0b11111;
|
|
||||||
obj->user_data.groupid = groupid; // & 0b111;
|
|
||||||
|
|
||||||
/* do not process these attributes */
|
/* do not process these attributes */
|
||||||
config.remove(F("page"));
|
config.remove(F("page"));
|
||||||
config.remove(F("id"));
|
config.remove(F("id"));
|
||||||
config.remove(F("objid"));
|
config.remove(F("objid"));
|
||||||
config.remove(F("parentid"));
|
config.remove(F("parentid"));
|
||||||
|
|
||||||
String v((char *)0);
|
String v((char *)0);
|
||||||
v.reserve(64);
|
v.reserve(64);
|
||||||
|
|
||||||
@ -792,21 +808,4 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
|||||||
hasp_process_obj_attribute(obj, keyValue.key().c_str(), v.c_str(), true);
|
hasp_process_obj_attribute(obj, keyValue.key().c_str(), v.c_str(), true);
|
||||||
// Log.verbose(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str());
|
// Log.verbose(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** testing start **/
|
|
||||||
uint8_t temp;
|
|
||||||
if(!hasp_find_id_from_obj(obj, &pageid, &temp)) {
|
|
||||||
return Log.error(TAG_HASP, F("Lost track of the created object, not found!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** verbose reporting **/
|
|
||||||
lv_obj_type_t list;
|
|
||||||
lv_obj_get_type(obj, &list);
|
|
||||||
Log.verbose(TAG_HASP, F(" * p[%u].b[%u] = %s"), pageid, temp, list.type[0]);
|
|
||||||
|
|
||||||
/* test double-check */
|
|
||||||
lv_obj_t * test = hasp_find_obj_from_parent_id(get_page_obj(pageid), (uint8_t)temp);
|
|
||||||
if(test != obj) {
|
|
||||||
return Log.error(TAG_HASP, F("Objects DO NOT match!"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user