Add my_image_release_resources and my_line_clear_points

This commit is contained in:
fvanroie 2021-10-03 00:13:22 +02:00
parent b191dfc363
commit 22f226243a
3 changed files with 33 additions and 18 deletions

View File

@ -29,6 +29,28 @@
LV_FONT_DECLARE(unscii_8_icon);
extern const char** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map
void my_image_release_resources(lv_obj_t* obj)
{
const void* src = lv_img_get_src(obj);
lv_img_src_t src_type = lv_img_src_get_type(src);
switch(src_type) {
case LV_IMG_SRC_VARIABLE: {
lv_img_dsc_t* img_dsc = (lv_img_dsc_t*)src;
free((uint8_t*)img_dsc->data); // free image data
lv_mem_free(img_dsc); // free image descriptor
break;
}
case LV_IMG_SRC_FILE:
lv_img_cache_invalidate_src(src);
break;
default:
break;
}
}
void my_btnmatrix_map_clear(lv_obj_t* obj)
{
lv_btnmatrix_ext_t* ext = (lv_btnmatrix_ext_t*)lv_obj_get_ext_attr(obj);
@ -151,7 +173,7 @@ static void my_msgbox_set_map(lv_obj_t* obj, const char* payload)
LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__);
}
void line_clear_points(lv_obj_t* obj)
void my_line_clear_points(lv_obj_t* obj)
{
lv_line_ext_t* ext = (lv_line_ext_t*)lv_obj_get_ext_attr(obj);
const lv_point_t* ptr = ext->point_array;
@ -161,7 +183,7 @@ void line_clear_points(lv_obj_t* obj)
static bool my_line_set_points(lv_obj_t* obj, const char* payload)
{
line_clear_points(obj); // delete pointmap
my_line_clear_points(obj); // delete pointmap
// Create new points
// Reserve memory for JsonDocument
@ -196,7 +218,7 @@ static bool my_line_set_points(lv_obj_t* obj, const char* payload)
}
}
line_clear_points(obj); // free previous pointlist
my_line_clear_points(obj); // free previous pointlist
lv_line_set_points(obj, point_arr, index); // arr.size());
return true;
}
@ -996,15 +1018,7 @@ static hasp_attribute_type_t special_attribute_src(lv_obj_t* obj, const char* pa
if(!obj_check_type(obj, LV_HASP_IMAGE)) return HASP_ATTR_TYPE_NOT_FOUND;
if(update) {
const void* src = lv_img_get_src(obj);
lv_img_src_t src_type = lv_img_src_get_type(src);
lv_img_cache_invalidate_src(src);
if(src_type == LV_IMG_SRC_VARIABLE) {
lv_img_dsc_t* img_dsc = (lv_img_dsc_t*)src;
lodepng_free((uint8_t*)img_dsc->data);
lv_mem_free(img_dsc);
}
my_image_release_resources(obj);
if(payload != strstr_P(payload, PSTR("http://"))) { // not start with http
if(payload == strstr_P(payload, PSTR("L:"))) { // startsWith command/

View File

@ -1,8 +1,8 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_ATTR_SET_H
#define HASP_ATTR_SET_H
#ifndef HASP_ATTRIBUTE_H
#define HASP_ATTRIBUTE_H
#include "hasplib.h"
@ -17,7 +17,8 @@ lv_chart_series_t* my_chart_get_series(lv_obj_t* chart, uint8_t ser_num);
void my_obj_set_value_str_text(lv_obj_t* obj, uint8_t part, lv_state_t state, const char* text);
void my_btnmatrix_map_clear(lv_obj_t* obj);
void my_msgbox_map_clear(lv_obj_t* obj);
void line_clear_points(lv_obj_t* obj);
void my_line_clear_points(lv_obj_t* obj);
void my_image_release_resources(lv_obj_t* obj);
void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* payload, bool update);
@ -492,4 +493,4 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
#define ATTR_TEXT_VERSION 60178
#define ATTR_TEXT_SSID 62981
#endif
#endif // HASP_ATTRIBUTE_H

View File

@ -44,7 +44,7 @@ void delete_event_handler(lv_obj_t* obj, lv_event_t event)
switch(obj_get_type(obj)) {
case LV_HASP_LINE:
line_clear_points(obj);
my_line_clear_points(obj);
break;
case LV_HASP_BTNMATRIX:
@ -56,7 +56,7 @@ void delete_event_handler(lv_obj_t* obj, lv_event_t event)
break;
case LV_HASP_IMAGE:
lv_img_cache_invalidate_src(NULL);
my_image_release_resources(obj);
break;
case LV_HASP_GAUGE: