inline object_get_type functions

This commit is contained in:
fvanroie 2021-05-15 13:49:04 +02:00
parent 8fb8733f05
commit 17cdca19df
2 changed files with 44 additions and 48 deletions

View File

@ -72,51 +72,6 @@ bool hasp_find_id_from_obj(const lv_obj_t* obj, uint8_t* pageid, uint8_t* objid)
return true;
}
/**
* Get the object type name of an object
* @param obj an lv_obj_t* of the object to check its type
* @return name of the object type
* @note
*/
const char* obj_get_type_name(const lv_obj_t* obj)
{
lv_obj_type_t list;
lv_obj_get_type(obj, &list);
const char* objtype = list.type[0];
return objtype + 3; // skip lv_
}
/**
* Check if an lvgl objecttype name corresponds to a given HASP object ID
* @param obj an lv_obj_t* of the object to check its type
* @param haspobjtype the HASP object ID to check against
* @return true or false wether the types match
* @note
*/
bool obj_check_type(const lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype)
{
#if 1
if(!obj) return false;
return obj->user_data.objid == (uint8_t)haspobjtype;
#else
lv_obj_type_t list;
lv_obj_get_type(obj, &list);
const char* objtype = list.type[0];
return obj_check_type(objtype, haspobjtype);
#endif
}
/**
* Get the hasp object type of a given LVGL object
* @param obj an lv_obj_t* of the object to check its type
* @return lv_hasp_obj_type_t
* @note
*/
lv_hasp_obj_type_t obj_get_type(const lv_obj_t* obj)
{
return (lv_hasp_obj_type_t)obj->user_data.objid;
}
void hasp_object_tree(const lv_obj_t* parent, uint8_t pageid, uint16_t level)
{
if(parent == nullptr) return;

View File

@ -82,9 +82,7 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id);
lv_obj_t* hasp_find_obj_from_parent_id(lv_obj_t* parent, uint8_t objid);
lv_obj_t* hasp_find_obj_from_page_id(uint8_t pageid, uint8_t objid);
bool hasp_find_id_from_obj(const lv_obj_t* obj, uint8_t* pageid, uint8_t* objid);
const char* obj_get_type_name(const lv_obj_t* obj);
bool obj_check_type(const lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype);
lv_hasp_obj_type_t obj_get_type(const lv_obj_t* obj);
void hasp_object_tree(const lv_obj_t* parent, uint8_t pageid, uint16_t level);
void object_dispatch_state(uint8_t pageid, uint8_t btnid, const char* payload);
@ -93,6 +91,49 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, con
void object_set_normalized_group_values(hasp_update_value_t& value);
/**
* Get the object type name of an object
* @param obj an lv_obj_t* of the object to check its type
* @return name of the object type
* @note
*/
inline const char* obj_get_type_name(const lv_obj_t* obj)
{
lv_obj_type_t list;
lv_obj_get_type(obj, &list);
const char* objtype = list.type[0];
return objtype + 3; // skip lv_
}
/**
* Get the hasp object type of a given LVGL object
* @param obj an lv_obj_t* of the object to check its type
* @return lv_hasp_obj_type_t
* @note
*/
inline lv_hasp_obj_type_t obj_get_type(const lv_obj_t* obj)
{
return (lv_hasp_obj_type_t)obj->user_data.objid;
}
/**
* Check if an lvgl objecttype name corresponds to a given HASP object ID
* @param obj an lv_obj_t* of the object to check its type
* @param haspobjtype the HASP object ID to check against
* @return true or false wether the types match
* @note
*/
inline bool obj_check_type(const lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype)
{
#if 1
if(!obj) return false;
return obj->user_data.objid == (uint8_t)haspobjtype;
#else
lv_obj_type_t list;
lv_obj_get_type(obj, &list);
const char* objtype = list.type[0];
return obj_check_type(objtype, haspobjtype);
#endif
}
#define HASP_OBJ_BAR 1971
#define HASP_OBJ_BTN 3164
#define HASP_OBJ_CPICKER 3313