From 7954c1912b52bf667688a924d6af0ff55999c4ae Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 21 Nov 2020 04:41:18 +0100 Subject: [PATCH] Code cleanup --- lib/lv_lib_zifont/lv_zifont.cpp | 27 +++++++++++++++++++++------ src/hasp_debug.cpp | 2 +- src/hasp_mdns.cpp | 5 ----- src/hasp_ota.cpp | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 06977352..209dc79d 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -87,13 +87,21 @@ static inline bool openFont(File & file, const char * filename) return file; } -static inline void initCharacterFrame(size_t size) +static inline bool initCharacterFrame(size_t size) { if(size > _lv_mem_get_size(charBitmap_p)) { - if(charBitmap_p) lv_mem_free(charBitmap_p); + lv_mem_free(charBitmap_p); charBitmap_p = (uint8_t *)lv_mem_alloc(size); + Log.warning(TAG_FONT, F("Pixel buffer is %d bytes"), _lv_mem_get_size(charBitmap_p)); + } + + if(charBitmap_p != NULL) { + _lv_memset_00(charBitmap_p, size); // init the bitmap to white + return true; + } else { + Log.error(TAG_FONT, F("Failed to allocate pixel buffer")); + return false; } - _lv_memset_00(charBitmap_p, size); // init the bitmap to white } int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size) @@ -243,8 +251,11 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, if(unicode_letter == 0x20) { charInfo = &fdsc->ascii_glyph_dsc[0]; size_t size = (charInfo->width * fdsc->CharHeight + 1) / 2; // add 1 for rounding up - initCharacterFrame(size); - charInBuffer = unicode_letter; + if(initCharacterFrame(size)) { + charInBuffer = unicode_letter; + } else { + charInBuffer = 0; + } return charBitmap_p; } @@ -254,6 +265,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint16_t charmap_position; if(unicode_letter >= 0xF000) { + //return NULL; sprintf_P(filename, PSTR("/fontawesome%u.zi"), fdsc->CharHeight); charmap_position = 25 + sizeof(zi_font_header_t); glyphID = unicode_letter - 0xf000; // start of fontawesome @@ -299,7 +311,9 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, /* Allocate & Initialize Buffer for 4bpp */ uint32_t size = (charInfo->width * fdsc->CharHeight + 1) / 2; // add 1 for rounding up - initCharacterFrame(size); + if(!initCharacterFrame(size)) { + return NULL; + } char data[256]; file.seek(datapos + 1, SeekSet); // +1 for skipping bpp byte @@ -440,6 +454,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ /* Open the font for reading */ if(unicode_letter >= 0xF000) { + // return false; char filename[32]; sprintf_P(filename, PSTR("/fontawesome%u.zi"), fdsc->CharHeight); if(!openFont(file, filename)) return false; diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 2c6bf47c..ad1fe812 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -151,7 +151,7 @@ void debugSetup() { // memset(serialInputBuffer, 0, sizeof(serialInputBuffer)); // serialInputIndex = 0; - Log.error(TAG_DEBG, F("Setting the console parser")); + Log.notice(TAG_DEBG, F("Setting the console parser")); console.setLineCallback(dispatchTextLine); } diff --git a/src/hasp_mdns.cpp b/src/hasp_mdns.cpp index 208943b4..3a4cdb71 100644 --- a/src/hasp_mdns.cpp +++ b/src/hasp_mdns.cpp @@ -67,11 +67,6 @@ void mdnsStart() MDNS.addService(F("telnet"), F("tcp"), 23); // } - // MDNS.addService(F("arduino"), F("tcp"), port); - // MDNS.addServiceTxt(F("arduino"), F("tcp"), "tcp_check", "no"); - // MDNS.addServiceTxt(F("arduino"), F("tcp"), "ssh_upload", "no"); - // MDNS.addServiceTxt(F("arduino"), F("tcp"), "board", ARDUINO_BOARD); - // addServiceTxt("arduino", F("tcp"), "auth_upload", (auth) ? "yes" : "no"); Log.trace(TAG_MDNS, F("Responder started")); } diff --git a/src/hasp_ota.cpp b/src/hasp_ota.cpp index 4e02df0e..11a1eb52 100644 --- a/src/hasp_ota.cpp +++ b/src/hasp_ota.cpp @@ -95,7 +95,7 @@ void otaSetup() } otaPrecentageComplete = -1; - Log.error(TAG_OTA, F("ERROR - %s failed (%s)"), buffer, error); + Log.error(TAG_OTA, F("%s failed (%s)"), buffer, error); haspProgressMsg(F("ESP OTA FAILED")); // delay(5000); // haspSendCmd("page " + String(nextionActivePage));