Display battery level and BLE connection status using icon on Clock screen.
This commit is contained in:
62
src/DisplayApp/Screens/BatteryIcon.cpp
Normal file
62
src/DisplayApp/Screens/BatteryIcon.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "BatteryIcon.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
|
||||
extern lv_img_dsc_t os_battery_error;
|
||||
extern lv_img_dsc_t os_batterycharging_100;
|
||||
extern lv_img_dsc_t os_batterycharging_090;
|
||||
extern lv_img_dsc_t os_batterycharging_080;
|
||||
extern lv_img_dsc_t os_batterycharging_070;
|
||||
extern lv_img_dsc_t os_batterycharging_060;
|
||||
extern lv_img_dsc_t os_batterycharging_050;
|
||||
extern lv_img_dsc_t os_batterycharging_040;
|
||||
extern lv_img_dsc_t os_batterycharging_030;
|
||||
extern lv_img_dsc_t os_batterycharging_020;
|
||||
extern lv_img_dsc_t os_batterycharging_010;
|
||||
extern lv_img_dsc_t os_batterycharging_005;
|
||||
|
||||
extern lv_img_dsc_t os_battery_100;
|
||||
extern lv_img_dsc_t os_battery_090;
|
||||
extern lv_img_dsc_t os_battery_080;
|
||||
extern lv_img_dsc_t os_battery_070;
|
||||
extern lv_img_dsc_t os_battery_060;
|
||||
extern lv_img_dsc_t os_battery_050;
|
||||
extern lv_img_dsc_t os_battery_040;
|
||||
extern lv_img_dsc_t os_battery_030;
|
||||
extern lv_img_dsc_t os_battery_020;
|
||||
extern lv_img_dsc_t os_battery_010;
|
||||
extern lv_img_dsc_t os_battery_005;
|
||||
|
||||
|
||||
lv_img_dsc_t *BatteryIcon::GetIcon(bool isCharging, float batteryPercent) {
|
||||
if(isCharging) {
|
||||
if(batteryPercent > 90.0f) return &os_batterycharging_100;
|
||||
else if(batteryPercent > 80.0f) return &os_batterycharging_090;
|
||||
else if(batteryPercent > 70.0f) return &os_batterycharging_080;
|
||||
else if(batteryPercent > 60.0f) return &os_batterycharging_070;
|
||||
else if(batteryPercent > 50.0f) return &os_batterycharging_060;
|
||||
else if(batteryPercent > 40.0f) return &os_batterycharging_050;
|
||||
else if(batteryPercent > 30.0f) return &os_batterycharging_040;
|
||||
else if(batteryPercent > 20.0f) return &os_batterycharging_030;
|
||||
else if(batteryPercent > 10.0f) return &os_batterycharging_020;
|
||||
else if(batteryPercent > 5.0f) return &os_batterycharging_010;
|
||||
else return &os_batterycharging_005;
|
||||
} else {
|
||||
if(batteryPercent > 90.0f) return &os_battery_100;
|
||||
else if(batteryPercent > 80.0f) return &os_battery_090;
|
||||
else if(batteryPercent > 70.0f) return &os_battery_080;
|
||||
else if(batteryPercent > 60.0f) return &os_battery_070;
|
||||
else if(batteryPercent > 50.0f) return &os_battery_060;
|
||||
else if(batteryPercent > 40.0f) return &os_battery_050;
|
||||
else if(batteryPercent > 30.0f) return &os_battery_040;
|
||||
else if(batteryPercent > 20.0f) return &os_battery_030;
|
||||
else if(batteryPercent > 10.0f) return &os_battery_020;
|
||||
else if(batteryPercent > 5.0f) return &os_battery_010;
|
||||
else return &os_battery_005;
|
||||
}
|
||||
}
|
||||
|
||||
lv_img_dsc_t *BatteryIcon::GetUnknownIcon() {
|
||||
return &os_battery_error;
|
||||
}
|
15
src/DisplayApp/Screens/BatteryIcon.h
Normal file
15
src/DisplayApp/Screens/BatteryIcon.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <libs/lvgl/src/lv_draw/lv_img_decoder.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class BatteryIcon {
|
||||
public:
|
||||
static lv_img_dsc_t* GetUnknownIcon();
|
||||
static lv_img_dsc_t* GetIcon(bool isCharging, float batteryPercent);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
12
src/DisplayApp/Screens/BleIcon.cpp
Normal file
12
src/DisplayApp/Screens/BleIcon.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "BleIcon.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
|
||||
extern lv_img_dsc_t os_bt_connected;
|
||||
extern lv_img_dsc_t os_bt_disconnected;
|
||||
|
||||
lv_img_dsc_t *BleIcon::GetIcon(bool isConnected) {
|
||||
if(isConnected) return &os_bt_connected;
|
||||
else return &os_bt_disconnected;
|
||||
}
|
14
src/DisplayApp/Screens/BleIcon.h
Normal file
14
src/DisplayApp/Screens/BleIcon.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <libs/lvgl/src/lv_draw/lv_img_decoder.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class BleIcon {
|
||||
public:
|
||||
static lv_img_dsc_t* GetIcon(bool isConnected);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
||||
labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN));
|
||||
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);
|
||||
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -76,6 +76,9 @@ namespace Pinetime {
|
||||
lv_obj_t* label_version;
|
||||
lv_obj_t* backgroundLabel;
|
||||
|
||||
lv_obj_t * batteryIcon;
|
||||
lv_obj_t * bleIcon;
|
||||
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Controllers::Battery& batteryController;
|
||||
Controllers::Ble& bleController;
|
||||
|
Reference in New Issue
Block a user