mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 04:36:38 +00:00
Release fonts with command clearpage all #249
This commit is contained in:
parent
32882ed33b
commit
39f8e17add
@ -608,9 +608,10 @@ IRAM_ATTR void haspLoop(void)
|
|||||||
dispatchLoop();
|
dispatchLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replaces all pages with new ones
|
||||||
void hasp_init(void)
|
void hasp_init(void)
|
||||||
{
|
{
|
||||||
haspPages.init(haspStartPage);
|
haspPages.init(haspStartPage); // StartPage is used for the BACK action
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasp_load_json(void)
|
void hasp_load_json(void)
|
||||||
|
@ -820,7 +820,9 @@ void dispatch_clear_page(const char*, const char* page, uint8_t source)
|
|||||||
uint8_t pageid;
|
uint8_t pageid;
|
||||||
if(strlen(page) > 0) {
|
if(strlen(page) > 0) {
|
||||||
if(!strcasecmp_P(page, PSTR("all"))) {
|
if(!strcasecmp_P(page, PSTR("all"))) {
|
||||||
for(pageid = 0; pageid < HASP_NUM_PAGES; pageid++) haspPages.clear(pageid);
|
// for(pageid = 0; pageid < HASP_NUM_PAGES; pageid++) haspPages.clear(pageid);
|
||||||
|
hasp_init();
|
||||||
|
font_clear_list(); // free TTF resources
|
||||||
} else {
|
} else {
|
||||||
pageid = atoi(page);
|
pageid = atoi(page);
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,34 @@ static lv_ll_t hasp_fonts_ll;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const char* payload; /* The payload with name and size */
|
char* payload; /* The payload with name and size */
|
||||||
lv_font_t* font; /* point to lvgl font */
|
lv_font_t* font; /* point to lvgl font */
|
||||||
} hasp_font_info_t;
|
} hasp_font_info_t;
|
||||||
|
|
||||||
void font_setup()
|
void font_setup()
|
||||||
{
|
{
|
||||||
_lv_ll_init(&hasp_fonts_ll, sizeof(hasp_font_info_t));
|
_lv_ll_init(&hasp_fonts_ll, sizeof(hasp_font_info_t));
|
||||||
|
|
||||||
|
// initialize the FreeType renderer
|
||||||
|
// #ifdef 1 || USE_LVGL_FREETYPE
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|
||||||
|
#if(HASP_USE_FREETYPE > 0)
|
||||||
|
|
||||||
|
if(lv_freetype_init(USE_LVGL_FREETYPE_MAX_FACES, USE_LVGL_FREETYPE_MAX_SIZES,
|
||||||
|
hasp_use_psram() ? USE_LVGL_FREETYPE_MAX_BYTES_PSRAM : USE_LVGL_FREETYPE_MAX_BYTES)) {
|
||||||
|
LOG_VERBOSE(TAG_FONT, F("FreeType v%d.%d.%d " D_SERVICE_STARTED), FREETYPE_MAJOR, FREETYPE_MINOR,
|
||||||
|
FREETYPE_PATCH);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(TAG_FONT, F("FreeType " D_SERVICE_START_FAILED));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
LOG_VERBOSE(TAG_FONT, F("FreeType " D_SERVICE_DISABLED));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(WINDOWS) || defined(POSIX)
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t font_split_payload(const char* payload)
|
size_t font_split_payload(const char* payload)
|
||||||
@ -39,12 +60,38 @@ size_t font_split_payload(const char* payload)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void font_clear_list()
|
||||||
|
{
|
||||||
|
if(_lv_ll_is_empty(&hasp_fonts_ll)) return;
|
||||||
|
|
||||||
|
void* node = _lv_ll_get_head(&hasp_fonts_ll);
|
||||||
|
while(node) {
|
||||||
|
|
||||||
|
if(hasp_font_info_t* font_p = (hasp_font_info_t*)node) {
|
||||||
|
if(font_p->font) {
|
||||||
|
if(font_p->font->user_data) { // It's a FreeType font
|
||||||
|
lv_ft_font_destroy(font_p->font);
|
||||||
|
} else { // It's a binary font
|
||||||
|
hasp_font_free(font_p->font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free the allocated font_name last */
|
||||||
|
hasp_free(font_p->payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lv_ll_remove(&hasp_fonts_ll, node);
|
||||||
|
lv_mem_free(node);
|
||||||
|
node = _lv_ll_get_head(&hasp_fonts_ll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static lv_font_t* font_find_in_list(const char* payload)
|
static lv_font_t* font_find_in_list(const char* payload)
|
||||||
{
|
{
|
||||||
hasp_font_info_t* font_p = (hasp_font_info_t*)_lv_ll_get_head(&hasp_fonts_ll);
|
hasp_font_info_t* font_p = (hasp_font_info_t*)_lv_ll_get_head(&hasp_fonts_ll);
|
||||||
while(font_p) {
|
while(font_p) {
|
||||||
if(strcmp(font_p->payload, payload) == 0) { // name and size
|
if(strcmp(font_p->payload, payload) == 0) { // name and size
|
||||||
LOG_WARNING(TAG_FONT, F("Payload %s found => line height = %d"), payload, font_p->font->line_height);
|
// LOG_DEBUG(TAG_FONT, F("Payload %s found => line height = %d"), payload, font_p->font->line_height);
|
||||||
return font_p->font;
|
return font_p->font;
|
||||||
}
|
}
|
||||||
font_p = (hasp_font_info_t*)_lv_ll_get_next(&hasp_fonts_ll, font_p);
|
font_p = (hasp_font_info_t*)_lv_ll_get_next(&hasp_fonts_ll, font_p);
|
||||||
@ -105,7 +152,7 @@ static lv_font_t* font_add_to_list(const char* payload)
|
|||||||
|
|
||||||
/* alloc payload str */
|
/* alloc payload str */
|
||||||
size_t len = strlen(payload);
|
size_t len = strlen(payload);
|
||||||
name_p = (char*)calloc(sizeof(char), len + 1);
|
name_p = (char*)hasp_calloc(sizeof(char), len + 1);
|
||||||
if(!name_p) return NULL;
|
if(!name_p) return NULL;
|
||||||
strncpy(name_p, payload, len);
|
strncpy(name_p, payload, len);
|
||||||
|
|
||||||
|
@ -6,5 +6,6 @@
|
|||||||
|
|
||||||
void font_setup();
|
void font_setup();
|
||||||
lv_font_t* get_font(const char* payload);
|
lv_font_t* get_font(const char* payload);
|
||||||
|
void font_clear_list();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -13,6 +13,15 @@ bool hasp_use_psram()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void* hasp_calloc(size_t num, size_t size)
|
||||||
|
{
|
||||||
|
#ifdef ESP32
|
||||||
|
return hasp_use_psram() ? ps_calloc(num, size) : calloc(num, size);
|
||||||
|
#else
|
||||||
|
return calloc(num, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void* hasp_malloc(size_t size)
|
void* hasp_malloc(size_t size)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
@ -231,30 +231,6 @@ static inline void gui_init_images()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the FreeType renderer
|
|
||||||
static inline void gui_init_freetype()
|
|
||||||
{
|
|
||||||
// #ifdef 1 || USE_LVGL_FREETYPE
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
|
|
||||||
#if(HASP_USE_FREETYPE > 0)
|
|
||||||
|
|
||||||
if(lv_freetype_init(USE_LVGL_FREETYPE_MAX_FACES, USE_LVGL_FREETYPE_MAX_SIZES,
|
|
||||||
hasp_use_psram() ? USE_LVGL_FREETYPE_MAX_BYTES_PSRAM : USE_LVGL_FREETYPE_MAX_BYTES)) {
|
|
||||||
LOG_VERBOSE(TAG_FONT, F("FreeType v%d.%d.%d " D_SERVICE_STARTED), FREETYPE_MAJOR, FREETYPE_MINOR,
|
|
||||||
FREETYPE_PATCH);
|
|
||||||
} else {
|
|
||||||
LOG_ERROR(TAG_FONT, F("FreeType " D_SERVICE_START_FAILED));
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
LOG_VERBOSE(TAG_FONT, F("FreeType " D_SERVICE_DISABLED));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(WINDOWS) || defined(POSIX)
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void gui_init_filesystems()
|
static inline void gui_init_filesystems()
|
||||||
{
|
{
|
||||||
#if LV_USE_FS_IF != 0
|
#if LV_USE_FS_IF != 0
|
||||||
@ -289,7 +265,6 @@ void guiSetup()
|
|||||||
gui_init_lvgl();
|
gui_init_lvgl();
|
||||||
gui_init_images();
|
gui_init_images();
|
||||||
gui_init_filesystems();
|
gui_init_filesystems();
|
||||||
gui_init_freetype();
|
|
||||||
font_setup();
|
font_setup();
|
||||||
|
|
||||||
/* Initialize the LVGL display driver with correct orientation */
|
/* Initialize the LVGL display driver with correct orientation */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user