diff options
author | JF <jf@codingfield.com> | 2020-07-04 13:58:15 +0200 |
---|---|---|
committer | JF <jf@codingfield.com> | 2020-07-04 13:58:15 +0200 |
commit | da39f402e5b91c78b724bfe568efc9339459f5a2 (patch) | |
tree | d2508ce6eca43c29516feb4d2680cba17890af45 /src/DisplayApp/Screens/Clock.cpp | |
parent | bb11891b6e66efdc0a0fc8a9761d94719fd4748f (diff) |
Replace bitmap icons by font icons (provided by AwesomeFont and LVGL). These icons are smaller in memory and quicker to draw.
BLE and battery icon replaced in Clock screen.
Added heartbeat and step icons in Clock screen.
Replace all labels in Menu by icons.
Add doc to generate new font.
Diffstat (limited to 'src/DisplayApp/Screens/Clock.cpp')
-rw-r--r-- | src/DisplayApp/Screens/Clock.cpp | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index 68471854..fc6441e8 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -1,13 +1,12 @@ #include <cstdio> #include <libs/date/includes/date/date.h> #include <Components/DateTime/DateTimeController.h> -#include <Version.h> #include <libs/lvgl/lvgl.h> #include "Clock.h" #include "../DisplayApp.h" #include "BatteryIcon.h" #include "BleIcon.h" - +#include "Symbols.h" using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; @@ -21,7 +20,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { Clock::Clock(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, - Controllers::Ble& bleController) : Screen(app), currentDateTime{{}}, version {{}}, + Controllers::Ble& bleController) : Screen(app), currentDateTime{{}}, dateTimeController{dateTimeController}, batteryController{batteryController}, bleController{bleController} { displayedChar[0] = 0; displayedChar[1] = 0; @@ -29,13 +28,18 @@ Clock::Clock(DisplayApp* app, displayedChar[3] = 0; displayedChar[4] = 0; - batteryIcon = lv_img_create(lv_scr_act(), NULL); - lv_img_set_src(batteryIcon, BatteryIcon::GetUnknownIcon()); - lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); + batteryIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(batteryIcon, Symbols::batteryFull); + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 2); + + batteryPlug = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(batteryPlug, Symbols::plug); + lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + + bleIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(bleIcon, Symbols::bluetooth); + lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); - bleIcon = lv_img_create(lv_scr_act(), NULL); - lv_img_set_src(bleIcon, BleIcon::GetIcon(false)); - lv_obj_align(bleIcon, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0); label_date = lv_label_create(lv_scr_act(), NULL); @@ -53,6 +57,27 @@ Clock::Clock(DisplayApp* app, lv_obj_set_size(backgroundLabel, 240, 240); lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text(backgroundLabel, ""); + + + heartbeatIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(heartbeatIcon, Symbols::heartBeat); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); + + heartbeatValue = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(heartbeatValue, "0"); + lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + + heartbeatBpm = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(heartbeatBpm, "BPM"); + lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + + stepValue = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(stepValue, "0"); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + + stepIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(stepIcon, Symbols::shoe); + lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); } Clock::~Clock() { @@ -63,17 +88,22 @@ bool Clock::Refresh() { batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); - lv_img_set_src(batteryIcon, BatteryIcon::GetIcon(batteryController.IsCharging() || batteryController.IsPowerPresent(), batteryPercent)); + lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent(); + lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging)); } bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { if(bleState.Get() == true) { - lv_img_set_src(bleIcon, BleIcon::GetIcon(true)); + lv_label_set_text(bleIcon, BleIcon::GetIcon(true)); } else { - lv_img_set_src(bleIcon, BleIcon::GetIcon(false)); + lv_label_set_text(bleIcon, BleIcon::GetIcon(false)); } } + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 5); + lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); currentDateTime = dateTimeController.CurrentDateTime(); @@ -124,6 +154,25 @@ bool Clock::Refresh() { } } + // TODO heartbeat = heartBeatController.GetValue(); + if(heartbeat.IsUpdated()) { + char heartbeatBuffer[4]; + sprintf(heartbeatBuffer, "%d", heartbeat.Get()); + lv_label_set_text(heartbeatValue, heartbeatBuffer); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2); + lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + } + + // TODO stepCount = stepController.GetValue(); + if(stepCount.IsUpdated()) { + char stepBuffer[5]; + sprintf(stepBuffer, "%lu", stepCount.Get()); + lv_label_set_text(stepValue, stepBuffer); + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2); + lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); + } + return running; } |