Add line object

This commit is contained in:
fvanroie 2021-07-02 23:28:44 +02:00
parent a5b783a03a
commit f77b76df87
5 changed files with 37 additions and 17 deletions

View File

@ -135,15 +135,13 @@ static void my_msgbox_set_map(lv_obj_t* obj, const char* payload)
void line_clear_points(lv_obj_t* obj)
{
lv_line_ext_t* ext = (lv_line_ext_t*)lv_obj_get_ext_attr(obj);
if(ext->point_array && (ext->point_num > 0)) {
const lv_point_t* ptr = ext->point_array;
lv_line_set_points(obj, NULL, 0);
lv_mem_free(ptr);
}
lv_line_ext_t* ext = (lv_line_ext_t*)lv_obj_get_ext_attr(obj);
const lv_point_t* ptr = ext->point_array;
lv_line_set_points(obj, NULL, 0);
lv_mem_free(ptr);
}
static void line_set_points(lv_obj_t* obj, const char* payload)
static bool my_line_set_points(lv_obj_t* obj, const char* payload)
{
line_clear_points(obj); // delete pointmap
@ -155,7 +153,7 @@ static void line_set_points(lv_obj_t* obj, const char* payload)
if(jsonError) { // Couldn't parse incoming JSON payload
dispatch_json_error(TAG_ATTR, jsonError);
return;
return false;
}
JsonArray arr = doc.as<JsonArray>(); // Parse payload
@ -164,7 +162,7 @@ static void line_set_points(lv_obj_t* obj, const char* payload)
lv_point_t* point_arr = (lv_point_t*)lv_mem_alloc(tot_len);
if(point_arr == NULL) {
LOG_ERROR(TAG_ATTR, F("Out of memory while creating line points"));
return;
return false;
}
memset(point_arr, 0, tot_len);
@ -177,9 +175,9 @@ static void line_set_points(lv_obj_t* obj, const char* payload)
index++;
}
line_clear_points(obj); // free previous pointlist!
lv_line_set_points(obj, point_arr, arr.size());
// TO DO : free & destroy previous pointlist!
return true;
}
static lv_font_t* haspPayloadToFont(const char* payload)
@ -2077,6 +2075,12 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attribute, const char
ret = hasp_process_lmeter_attribute(obj, attr_hash, val, update);
break;
case LV_HASP_LINE:
if(attr_hash == ATTR_POINTS) {
ret = my_line_set_points(obj, payload) ? HASP_ATTR_TYPE_METHOD_OK : HASP_ATTR_TYPE_RANGE_ERROR;
}
break;
case LV_HASP_CPICKER:
if(attr_hash == ATTR_COLOR) {
if(update) {

View File

@ -157,12 +157,12 @@ struct hasp_attr_update_char_const_t
}
#define _HASP_ATTRIBUTE(prop_name, func_name, value_type) \
static inline hasp_attribute_type_t attribute_##func_name(lv_obj_t* obj, uint8_t part, lv_state_t state, bool update, \
value_type val, int32_t& res) \
static inline hasp_attribute_type_t attribute_##func_name(lv_obj_t* obj, uint8_t part, lv_state_t state, \
bool update, value_type val, int32_t& res) \
{ \
if(update) lv_obj_set_style_local_##func_name(obj, part, state, (value_type)val); \
res = (int32_t)lv_obj_get_style_##func_name(obj, part); \
return HASP_ATTR_TYPE_INT; \
return HASP_ATTR_TYPE_INT; \
}
_HASP_ATTRIBUTE(RADIUS, radius, lv_style_int_t)
@ -468,6 +468,10 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
//#define ATTR_ARC_LENGTH 755 - use ATTR_ANGLE
// #define ATTR_DIRECTION 32415 - see Dropdown
// Line
#define ATTR_POINTS 8643
#define ATTR_Y_INVERT 44252
/* hasp user data */
#define ATTR_ACTION 42102
#define ATTR_TRANSITION 10933

View File

@ -38,8 +38,10 @@ void swipe_event_handler(lv_obj_t* obj, lv_event_t event);
* Clean-up allocated memory before an object is deleted
* @param obj pointer to an object to clean-up
*/
static void event_delete_object(lv_obj_t* obj)
void delete_event_handler(lv_obj_t* obj, lv_event_t event)
{
if(event != LV_EVENT_DELETE) return;
switch(obj_get_type(obj)) {
case LV_HASP_LINE:
line_clear_points(obj);
@ -175,7 +177,7 @@ static bool translate_event(lv_obj_t* obj, lv_event_t event, uint8_t& eventid)
case LV_EVENT_DELETE:
LOG_VERBOSE(TAG_EVENT, F(D_OBJECT_DELETED));
event_delete_object(obj);
delete_event_handler(obj, event);
break;
case LV_EVENT_PRESSED:
@ -392,7 +394,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event)
case LV_EVENT_DELETE:
LOG_VERBOSE(TAG_EVENT, F(D_OBJECT_DELETED));
event_delete_object(obj); // free and destroy persistent memory allocated for certain objects
delete_event_handler(obj, event); // free and destroy persistent memory allocated for certain objects
return;
case LV_EVENT_PRESSING:

View File

@ -16,6 +16,7 @@ void event_timer_calendar(lv_task_t* task);
void event_timer_clock(lv_task_t* task);
// Object event Handlers
void delete_event_handler(lv_obj_t* obj, lv_event_t event);
void wakeup_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);

View File

@ -508,6 +508,15 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
}
break;
case LV_HASP_LINE:
case HASP_OBJ_LINE:
obj = lv_line_create(parent_obj, NULL);
if(obj) {
lv_obj_set_event_cb(obj, delete_event_handler);
obj->user_data.objid = LV_HASP_LINE;
}
break;
case LV_HASP_BAR:
case HASP_OBJ_BAR:
obj = lv_bar_create(parent_obj, NULL);