summaryrefslogtreecommitdiff
path: root/src/DisplayApp/Screens/Clock.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-03-14 16:33:47 +0100
committerJF <jf@codingfield.com>2020-03-14 16:33:47 +0100
commit4d2aacf8639f565b822020cdb43c011e1a72dc7b (patch)
treecb277bb2efe7bc51737db9784483c736a3a87937 /src/DisplayApp/Screens/Clock.cpp
parenta91c68c931cc8308e87acd796afb46ba70ae3dc2 (diff)
Display battery level and BLE connection status using icon on Clock screen.
Diffstat (limited to 'src/DisplayApp/Screens/Clock.cpp')
-rw-r--r--src/DisplayApp/Screens/Clock.cpp60
1 files changed, 37 insertions, 23 deletions
diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp
index abc4d627..00590777 100644
--- a/src/DisplayApp/Screens/Clock.cpp
+++ b/src/DisplayApp/Screens/Clock.cpp
@@ -5,11 +5,14 @@
#include <libs/lvgl/lvgl.h>
#include "Clock.h"
#include "../DisplayApp.h"
+#include "BatteryIcon.h"
+#include "BleIcon.h"
using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
+
static void event_handler(lv_obj_t * obj, lv_event_t event) {
Clock* screen = static_cast<Clock *>(obj->user_data);
screen->OnObjectEvent(obj, event);
@@ -26,30 +29,47 @@ Clock::Clock(DisplayApp* app,
displayedChar[3] = 0;
displayedChar[4] = 0;
- label_battery = lv_label_create(lv_scr_act(), NULL);
- lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 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);
+
+ 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_battery = lv_label_create(lv_scr_act(), NULL);
+// lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0);
+
+// labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN));
+// labelStyle->text.font = &jetbrains_mono_bold_20;
+//
+// lv_style_copy(&labelBigStyle, labelStyle);
+// labelBigStyle.text.font = &jetbrains_mono_extrabold_compressed;
+//
+// lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle);
+
+// label_ble = lv_label_create(lv_scr_act(), NULL);
- labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN));
+
+// lv_label_set_style(label_ble, LV_LABEL_STYLE_MAIN, labelStyle);
+// lv_obj_align(label_ble, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 0);
+
+ label_date = lv_label_create(lv_scr_act(), NULL);
+
+ lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
+
+ labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_date, LV_LABEL_STYLE_MAIN));
labelStyle->text.font = &jetbrains_mono_bold_20;
lv_style_copy(&labelBigStyle, labelStyle);
labelBigStyle.text.font = &jetbrains_mono_extrabold_compressed;
- lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle);
-
- label_ble = lv_label_create(lv_scr_act(), NULL);
- lv_label_set_style(label_ble, LV_LABEL_STYLE_MAIN, labelStyle);
- lv_obj_align(label_ble, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 0);
+ lv_label_set_style(label_date, LV_LABEL_STYLE_MAIN, labelStyle);
label_time = lv_label_create(lv_scr_act(), NULL);
lv_label_set_style(label_time, LV_LABEL_STYLE_MAIN, &labelBigStyle);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
-
- label_date = lv_label_create(lv_scr_act(), NULL);
- lv_label_set_style(label_date, LV_LABEL_STYLE_MAIN, labelStyle);
- lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
-
backgroundLabel = lv_label_create(lv_scr_act(), NULL);
backgroundLabel->user_data = this;
lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle);
@@ -68,22 +88,16 @@ Clock::~Clock() {
bool Clock::Refresh() {
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
- char batteryChar[11];
- auto newBatteryValue = batteryPercentRemaining.Get();
- newBatteryValue = (newBatteryValue > 100) ? 100 : newBatteryValue;
- newBatteryValue = (newBatteryValue < 0) ? 0 : newBatteryValue;
-
- sprintf(batteryChar, "BAT: %d%%", newBatteryValue);
- lv_label_set_text(label_battery, batteryChar);
+ auto batteryPercent = batteryPercentRemaining.Get();
+ lv_img_set_src(batteryIcon, BatteryIcon::GetIcon(batteryController.IsCharging() || batteryController.IsPowerPresent(), batteryPercent));
}
bleState = bleController.IsConnected();
if (bleState.IsUpdated()) {
if(bleState.Get() == true) {
- lv_obj_set_hidden(label_ble, false);
- lv_label_set_text(label_ble, "BLE");
+ lv_img_set_src(bleIcon, BleIcon::GetIcon(true));
} else {
- lv_obj_set_hidden(label_ble, true);
+ lv_img_set_src(bleIcon, BleIcon::GetIcon(false));
}
}