diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-04 22:25:47 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-06-11 01:00:20 (GMT) |
| commit | d61633a8ca0476c4381c4e72c2eb8d3d142b45d3 (patch) | |
| tree | 144789f897d5871f13a6dc413adbe466b78a8f4e | |
| parent | 16882a1f9e8e82873ec14d631db96010f817149d (diff) | |
Make neofont0mono available.
Reduce memfrag visor to 3x4 characters
test allocations with 8-byte granularity, try to test pvPort(Malloc|Free)
Improve display by displaying 8-byte words, try to improve pvPortMalloc fragmentation detection
Display memory fragmentation stats at the beginning and update when screen is touched.
Align fragmentation stats display to right.
| -rw-r--r-- | src/displayapp/fonts/neofont.c | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.cpp | 129 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 13 | ||||
| -rw-r--r-- | src/libs/lv_conf.h | 2 |
4 files changed, 145 insertions, 3 deletions
diff --git a/src/displayapp/fonts/neofont.c b/src/displayapp/fonts/neofont.c index e89682b..b4ec7d5 100644 --- a/src/displayapp/fonts/neofont.c +++ b/src/displayapp/fonts/neofont.c @@ -1482,8 +1482,8 @@ static const uint8_t * neofont0_glyph_bitmap_cb(const lv_font_t * font, uint32_t lv_font_t neofont0 = { .get_glyph_dsc = neofont0_glyph_dsc_cb, /*Set a callback to get info about gylphs*/ .get_glyph_bitmap = neofont0_glyph_bitmap_cb, /*Set a callback to get bitmap of a glyp*/ - .line_height = 12, /*The real line height where any text fits*/ - .base_line = 2, + .line_height = 6, /*The real line height where any text fits*/ + .base_line = 1, .dsc = 0, /*Store any implementation specific data here*/ #if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) .subpx = LV_FONT_SUBPX_NONE, diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 3b46c3b..98e1199 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -3,6 +3,7 @@ #include <date/date.h> #include <lvgl/lvgl.h> #include <cstdio> +#include <FreeRTOS.h> #include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BleIcon.h" #include "displayapp/screens/NotificationIcon.h" @@ -77,6 +78,13 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_fmt(label_temp, "??°C"); lv_obj_align(label_temp, nullptr, LV_ALIGN_CENTER, 60, -60); + memfragLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(memfragLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); + lv_obj_set_style_local_text_color(memfragLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x272727)); + lv_label_set_text_static(memfragLabel, memfrag_label_text); + lv_obj_align(memfragLabel, nullptr, LV_ALIGN_IN_RIGHT_MID, 0, -50); + // lv_obj_set_hidden(memfragLabel, true); + label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont3); lv_label_set_text_fmt(label_time, hhmm_label_text); @@ -126,6 +134,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); + RefreshStats(); } WatchFaceDigital::~WatchFaceDigital() { @@ -133,6 +142,125 @@ WatchFaceDigital::~WatchFaceDigital() { lv_obj_clean(lv_scr_act()); } +bool WatchFaceDigital::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + if (event == Pinetime::Applications::TouchEvents::Tap) { + RefreshStats(); + } + return false; +} + +// bool WatchFaceDigital::OnButtonPushed() { +// RefreshStats(); +// return true; +// } + +namespace { + template <typename Malloc, typename Free> struct AllocStats { + inline AllocStats(const Malloc& m, const Free& f) : ourMalloc(m), ourFree(f) { }; + const Malloc& ourMalloc; + const Free& ourFree; + bool tryAlloc(uint16_t s1, uint16_t s2) { + bool good = false; +#ifndef INFINISIM + portENTER_CRITICAL(); +#endif + void*p1 = ourMalloc(s1); + if (p1 != nullptr) { + if (s2 > 0) { + void*p2 = ourMalloc(s2); + if (p2 != nullptr) { + good = true; + ourFree(p2); + } + } else { + good = true; + } + ourFree(p1); + } +#ifndef INFINISIM + portEXIT_CRITICAL(); +#endif + return good; + } + inline auto stats(uint16_t maximumPlusOne = 10000) { + uint16_t min1 = 0; + uint16_t max1 = 0; + while (1) { + max1 = 1 + max1 * 2; + if (max1 > maximumPlusOne) { + max1 = maximumPlusOne; + break; + } + if (!tryAlloc(max1,0)) { + break; + } + min1 = max1; + } + for (decltype(max1) d; (d = ((max1 - min1) >> 4)) > 0;) { + auto mid = min1 + (d << 3); + if (tryAlloc(mid, 0)) { + min1 = mid; + } else { + max1 = mid; + } + } + uint16_t min2 = 0; + uint16_t max2 = 0; + while (1) { + max2 = 1 + max2 * 2; + if (max2 > min1) { + max2 = min1; max2 += (1 << 3); + break; + } + if (!tryAlloc(min1,max2)) { + break; + } + min2 = max2; + } + for (decltype(max2) d; (d = ((max2 - min2) >> 4)) > 0;) { + auto mid = min2 + (d << 3); + if (tryAlloc(min1, mid)) { + min2 = mid; + } else { + max2 = mid; + } + } + return std::array<uint16_t, 2>({ min1, min2 }); + } + }; + inline void*cppMalloc(uint16_t x) { + return operator new(x); + } + inline void cppFree(void*x) { + operator delete(x); + } + inline auto memfragStats() { +#ifdef INFINISIM + auto a = AllocStats{malloc,free}.stats((200+1)*8); +#else + auto a = AllocStats(pvPortMalloc,vPortFree).stats((200+1)*8); +#endif + // auto a = AllocStats{cppMalloc,cppFree}.stats(200); + auto b = AllocStats{lv_mem_alloc,lv_mem_free}.stats(8008); + // return std::array<uint16_t, 4>{ 1, 10, 100, 1000 }; + return std::array<uint16_t, 4>{ a[0], a[1], b[0], b[1] }; + } +} + +void WatchFaceDigital::RefreshStats() { + char *s = memfrag_label_text; + for (uint16_t x : memfragStats()) { + s += 2; + x >>= 3; + (s--)[0] = '0' + x%10; x /= 10; + (s--)[0] = '0' + x%10; x /= 10; + s[0] = '0' + x%10; x /= 10; + s += 4; + } + lv_label_set_text_static(memfragLabel, memfrag_label_text); + // lv_obj_set_hidden(memfragLabel, false); +} + void WatchFaceDigital::Refresh() { bool batteryRefreshed = false; @@ -237,6 +365,7 @@ void WatchFaceDigital::Refresh() { hhmm_label_text[4] = '0' + (minute % 10); lv_label_set_text_static(label_time, hhmm_label_text); lv_obj_set_hidden(label_time_pm, hide_pm); + // RefreshStats(); } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 1ef9244..09dae6e 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -37,6 +37,9 @@ namespace Pinetime { void Refresh() override; + bool OnTouchEvent(TouchEvents event) override; + // bool OnButtonPushed() override; + private: System::SystemTask& systemTask; uint8_t displayedHour = -1; @@ -56,6 +59,13 @@ namespace Pinetime { char battery_percent_label_text[5] = { '?', '?', '?', '%', 0 }; char battery_voltage_label_text[8] = { '0', '0', '0', '0', ' ', 'm', 'V', 0 }; + char memfrag_label_text[16] = { + '0', '0', '0', '\n', + '0', '0', '0', '\n', + '0', '0', '0', '\n', + '0', '0', '0', 0 + }; + DirtyValue<uint8_t> batteryPercentRemaining {}; DirtyValue<bool> powerPresent {}; DirtyValue<bool> bleState {}; @@ -84,6 +94,7 @@ namespace Pinetime { lv_obj_t* notificationIcon; lv_obj_t* batteryPercentLabel; lv_obj_t* batteryVoltageLabel; + lv_obj_t* memfragLabel; Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; @@ -94,6 +105,8 @@ namespace Pinetime { Controllers::MotionController& motionController; lv_task_t* taskRefresh; + + void RefreshStats(); }; } } diff --git a/src/libs/lv_conf.h b/src/libs/lv_conf.h index ff38aec..9f6a995 100644 --- a/src/libs/lv_conf.h +++ b/src/libs/lv_conf.h @@ -413,7 +413,7 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in * LV_FONT_DECLARE(my_font_2) */ -#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(neofont0) \ +#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(neofont0mono) \ LV_FONT_DECLARE(neofont1) \ LV_FONT_DECLARE(neofont15) \ LV_FONT_DECLARE(neofont15mono) \ |
