Fix for freetype caching bug

This commit is contained in:
fvanroie 2022-04-12 22:14:35 +02:00
parent b603742c55
commit 991b5fc73e
4 changed files with 39 additions and 33 deletions

View File

@ -64,6 +64,7 @@ build_flags =
-D STREAMUTILS_ENABLE_EEPROM=1 ; for STM32, it also supports EEPROM
; -- Hasp build options ----------------------------
-D HASP_USE_FREETYPE=1
-D HASP_VER_MAJ=0
-D HASP_VER_MIN=6
;-D HASP_VER_REV=3

View File

@ -1420,7 +1420,7 @@ static hasp_attribute_type_t attribute_common_json(lv_obj_t* obj, uint16_t attr_
{
switch(attr_hash) {
case ATTR_JSONL: {
DeserializationError jsonError;
DeserializationError jsonError = DeserializationError::Ok;
if(update) {
@ -1433,17 +1433,20 @@ static hasp_attribute_type_t attribute_common_json(lv_obj_t* obj, uint16_t attr_
DeserializationError jsonError = deserializeJson(json, (char*)payload);
json.shrinkToFit();
if(!jsonError) {
if(jsonError == DeserializationError::Ok) {
// Make sure we have a valid JsonObject to start from
if(JsonObject keys = json.as<JsonObject>()) {
hasp_parse_json_attributes(obj, keys); // json is valid object, cast as a JsonObject
} else {
LOG_WARNING(TAG_ATTR, "%s %d", __FILE__, __LINE__);
jsonError = DeserializationError::InvalidInput;
}
} else {
LOG_WARNING(TAG_ATTR, "%s %d", __FILE__, __LINE__);
jsonError = DeserializationError::IncompleteInput;
}
}
LOG_WARNING(TAG_ATTR, "%s %d", __FILE__, __LINE__);
if(jsonError) { // Couldn't parse incoming JSON object
dispatch_json_error(TAG_ATTR, jsonError);

View File

@ -135,7 +135,9 @@ void dispatch_state_val(const char* topic, hasp_event_t eventid, int32_t val)
void dispatch_json_error(uint8_t tag, DeserializationError& jsonError)
{
LOG_ERROR(tag, F(D_JSON_FAILED " %s"), jsonError.c_str());
LOG_ERROR(tag, F(D_JSON_FAILED " %d"), jsonError);
// const char * error = jsonError.c_str();
// LOG_ERROR(tag, F(D_JSON_FAILED " %s"), error);
}
// p[x].b[y].attr=value

View File

@ -20,13 +20,13 @@ static lv_ll_t hasp_fonts_ll;
typedef struct
{
const char* name; /* The name of the font file */
lv_font_t* font; /* point to lvgl font */
const char* payload; /* The payload with name and size */
lv_font_t* font; /* point to lvgl font */
} hasp_font_info_t;
void font_setup()
{
_lv_ll_init(&hasp_fonts_ll, sizeof(lv_ft_info_t));
_lv_ll_init(&hasp_fonts_ll, sizeof(hasp_font_info_t));
}
size_t font_split_payload(const char* payload)
@ -43,7 +43,8 @@ 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);
while(font_p) {
if(strcmp(font_p->name, payload) == 0) {
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);
return font_p->font;
}
font_p = (hasp_font_info_t*)_lv_ll_get_next(&hasp_fonts_ll, font_p);
@ -62,27 +63,27 @@ static lv_font_t* font_add_to_list(const char* payload)
char* name_p = NULL;
#if defined(ARDUINO_ARCH_ESP32) && (HASP_USE_FREETYPE > 0)
// if(!font) {
// // Try .ttf file
if(!font) {
// Try .ttf file
// size_t pos = font_split_payload(payload);
// if(pos > 0 && pos < 56) {
// uint16_t size = atoi(payload + pos);
size_t pos = font_split_payload(payload);
if(pos > 0 && pos < 56) {
uint16_t size = atoi(payload + pos);
// char fontname[64];
// memset(fontname, 0, sizeof(fontname));
// strncpy(fontname, payload, pos);
// snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.ttf"), fontname);
char fontname[64];
memset(fontname, 0, sizeof(fontname));
strncpy(fontname, payload, pos);
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.ttf"), fontname);
// lv_ft_info_t info;
// info.name = filename;
// info.weight = size;
// info.style = FT_FONT_STYLE_NORMAL;
// if(lv_ft_font_init(&info)) {
// font = info.font;
// }
// }
// }
lv_ft_info_t info;
info.name = filename;
info.weight = size;
info.style = FT_FONT_STYLE_NORMAL;
if(lv_ft_font_init(&info)) {
font = info.font;
}
}
}
if(!font) {
// Try .otf file
@ -101,20 +102,19 @@ static lv_font_t* font_add_to_list(const char* payload)
if(!font) return NULL;
LOG_VERBOSE(TAG_FONT, F("Loaded font %s size %d"), filename, font->line_height);
/* allox payload str */
size_t len = strlen(payload);
name_p = (char*)calloc(sizeof(char), len + 1);
if(!name_p) return NULL;
strncpy(name_p, payload, len);
hasp_font_info_t info;
info.name = name_p;
info.font = font;
hasp_font_info_t* new_font_item;
new_font_item = (hasp_font_info_t*)_lv_ll_ins_tail(&hasp_fonts_ll);
if(!new_font_item) return NULL;
hasp_font_info_t* info_p;
info_p = (hasp_font_info_t*)_lv_ll_ins_tail(&hasp_fonts_ll);
*info_p = info;
return info.font;
new_font_item->payload = name_p;
new_font_item->font = font;
return font;
}
// Convert the payload to a font pointer