mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +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)
|
||||
{
|
||||
char buffer[32];
|
||||
char buffer[40]; // "#ffffff","r":"255","g":"255","b":"255"
|
||||
lv_color32_t c32;
|
||||
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,
|
||||
c32.ch.green, c32.ch.blue);
|
||||
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, c32.ch.green, c32.ch.blue);
|
||||
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];
|
||||
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_RELEASED) 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));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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)
|
||||
{
|
||||
/* Validate page */
|
||||
// uint8_t pageid = config[F("page")].isNull() ? haspGetPage() : config[F("page")].as<uint8_t>();
|
||||
/* Page selection: page is the default parent_obj */
|
||||
uint8_t pageid = config[F("page")].isNull() ? saved_page_id : config[F("page")].as<uint8_t>();
|
||||
|
||||
/* Page selection */
|
||||
lv_obj_t * page = get_page_obj(pageid);
|
||||
if(!page) {
|
||||
lv_obj_t * parent_obj = get_page_obj(pageid);
|
||||
if(!parent_obj) {
|
||||
return Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid);
|
||||
} else {
|
||||
saved_page_id = pageid; /* save the current pageid */
|
||||
}
|
||||
|
||||
/* Validate type */
|
||||
if(config[F("objid")].isNull()) return; // comments
|
||||
|
||||
lv_obj_t * parent_obj = page;
|
||||
// lv_obj_t * parent_obj = page;
|
||||
if(!config[F("parentid")].isNull()) {
|
||||
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) {
|
||||
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 {
|
||||
Log.verbose(TAG_HASP, F("Parent ID p[%u].b[%u] found"), pageid, parentid);
|
||||
}
|
||||
@ -534,8 +527,12 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||
/* Define Objects*/
|
||||
lv_obj_t * obj = hasp_find_obj_from_parent_id(parent_obj, id);
|
||||
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);
|
||||
|
||||
} else {
|
||||
|
||||
/* Validate type */
|
||||
if(config[F("objid")].isNull()) return; // comments
|
||||
|
||||
switch(objid) {
|
||||
/* ----- Basic Objects ------ */
|
||||
@ -766,7 +763,7 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||
|
||||
/* No object was actually created */
|
||||
if(!obj) {
|
||||
return Log.warning(TAG_HASP, F("Object ID %u is NULL, skipping..."), id);
|
||||
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.
|
||||
@ -779,20 +776,6 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||
obj->user_data.objid = objid; //& 0b11111;
|
||||
obj->user_data.groupid = groupid; // & 0b111;
|
||||
|
||||
/* do not process these attributes */
|
||||
config.remove(F("page"));
|
||||
config.remove(F("id"));
|
||||
config.remove(F("objid"));
|
||||
config.remove(F("parentid"));
|
||||
String v((char *)0);
|
||||
v.reserve(64);
|
||||
|
||||
for(JsonPair keyValue : config) {
|
||||
v = keyValue.value().as<String>();
|
||||
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());
|
||||
}
|
||||
|
||||
/** testing start **/
|
||||
uint8_t temp;
|
||||
if(!hasp_find_id_from_obj(obj, &pageid, &temp)) {
|
||||
@ -809,4 +792,20 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||
if(test != obj) {
|
||||
return Log.error(TAG_HASP, F("Objects DO NOT match!"));
|
||||
}
|
||||
}
|
||||
|
||||
/* do not process these attributes */
|
||||
config.remove(F("page"));
|
||||
config.remove(F("id"));
|
||||
config.remove(F("objid"));
|
||||
config.remove(F("parentid"));
|
||||
|
||||
String v((char *)0);
|
||||
v.reserve(64);
|
||||
|
||||
for(JsonPair keyValue : config) {
|
||||
v = keyValue.value().as<String>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user