Detect full charge and improve watchface display
This commit is contained in:
parent
6f9f0e8b0e
commit
fd52ca8fe6
|
@ -19,6 +19,12 @@ void Battery::Update() {
|
||||||
isCharging = !nrf_gpio_pin_read(chargingPin);
|
isCharging = !nrf_gpio_pin_read(chargingPin);
|
||||||
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
|
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
|
||||||
|
|
||||||
|
if (isPowerPresent && !isCharging) {
|
||||||
|
isFull = true;
|
||||||
|
} else if (!isPowerPresent) {
|
||||||
|
isFull = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isReading) {
|
if (isReading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -65,12 +71,12 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
|
||||||
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
|
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
|
||||||
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
|
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
|
||||||
|
|
||||||
if (voltage > battery_max) {
|
if (isFull) {
|
||||||
percentRemaining = 100;
|
percentRemaining = 100;
|
||||||
} else if (voltage < battery_min) {
|
} else if (voltage < battery_min) {
|
||||||
percentRemaining = 0;
|
percentRemaining = 0;
|
||||||
} else {
|
} else {
|
||||||
percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
|
percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
nrfx_saadc_uninit();
|
nrfx_saadc_uninit();
|
||||||
|
|
|
@ -23,13 +23,19 @@ namespace Pinetime {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCharging() const {
|
bool IsCharging() const {
|
||||||
return isCharging;
|
// isCharging will go up and down when fully charged
|
||||||
|
// isFull makes sure this returns false while fully charged.
|
||||||
|
return isCharging && !isFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPowerPresent() const {
|
bool IsPowerPresent() const {
|
||||||
return isPowerPresent;
|
return isPowerPresent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsFull() const {
|
||||||
|
return isFull;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Battery* instance;
|
static Battery* instance;
|
||||||
nrf_saadc_value_t saadc_value;
|
nrf_saadc_value_t saadc_value;
|
||||||
|
@ -40,6 +46,7 @@ namespace Pinetime {
|
||||||
uint16_t voltage = 0;
|
uint16_t voltage = 0;
|
||||||
uint8_t percentRemaining = 0;
|
uint8_t percentRemaining = 0;
|
||||||
|
|
||||||
|
bool isFull = false;
|
||||||
bool isCharging = false;
|
bool isCharging = false;
|
||||||
bool isPowerPresent = false;
|
bool isPowerPresent = false;
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,10 @@ void BatteryInfo::Refresh() {
|
||||||
batteryPercent = batteryController.PercentRemaining();
|
batteryPercent = batteryController.PercentRemaining();
|
||||||
batteryVoltage = batteryController.Voltage();
|
batteryVoltage = batteryController.Voltage();
|
||||||
|
|
||||||
if (batteryController.IsCharging() and batteryPercent < 100) {
|
if (batteryController.IsCharging()) {
|
||||||
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
lv_label_set_text_static(status, "Charging");
|
lv_label_set_text_static(status, "Charging");
|
||||||
} else if (batteryPercent == 100) {
|
} else if (batteryController.IsFull()) {
|
||||||
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
|
||||||
lv_label_set_text_static(status, "Fully charged");
|
lv_label_set_text_static(status, "Fully charged");
|
||||||
} else if (batteryPercent < 10) {
|
} else if (batteryPercent < 10) {
|
||||||
|
|
|
@ -100,10 +100,7 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
|
||||||
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
||||||
lv_label_set_text(batteryIcon, Symbols::batteryFull);
|
lv_label_set_text(batteryIcon, Symbols::batteryFull);
|
||||||
lv_obj_align(batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2);
|
lv_obj_align(batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2);
|
||||||
|
lv_obj_set_auto_realign(batteryIcon, true);
|
||||||
batteryPlug = lv_label_create(lv_scr_act(), nullptr);
|
|
||||||
lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
|
||||||
lv_obj_align(batteryPlug, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2);
|
|
||||||
|
|
||||||
bleIcon = lv_label_create(lv_scr_act(), nullptr);
|
bleIcon = lv_label_create(lv_scr_act(), nullptr);
|
||||||
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
||||||
|
@ -205,18 +202,24 @@ PineTimeStyle::~PineTimeStyle() {
|
||||||
lv_obj_clean(lv_scr_act());
|
lv_obj_clean(lv_scr_act());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PineTimeStyle::SetBatteryIcon() {
|
||||||
|
auto batteryPercent = batteryPercentRemaining.Get();
|
||||||
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
||||||
|
}
|
||||||
|
|
||||||
void PineTimeStyle::Refresh() {
|
void PineTimeStyle::Refresh() {
|
||||||
batteryPercentRemaining = batteryController.PercentRemaining();
|
isCharging = batteryController.IsCharging();
|
||||||
if (batteryPercentRemaining.IsUpdated()) {
|
if (isCharging.IsUpdated()) {
|
||||||
auto batteryPercent = batteryPercentRemaining.Get();
|
if (isCharging.Get()) {
|
||||||
if (batteryController.IsCharging()) {
|
lv_label_set_text(batteryIcon, Symbols::plug);
|
||||||
auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent();
|
|
||||||
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
|
|
||||||
lv_obj_realign(batteryPlug);
|
|
||||||
lv_label_set_text(batteryIcon, "");
|
|
||||||
} else {
|
} else {
|
||||||
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
SetBatteryIcon();
|
||||||
lv_label_set_text(batteryPlug, "");
|
}
|
||||||
|
}
|
||||||
|
if (!isCharging.Get()) {
|
||||||
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
||||||
|
if (batteryPercentRemaining.IsUpdated()) {
|
||||||
|
SetBatteryIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Pinetime {
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
|
DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<bool> bleState {};
|
DirtyValue<bool> bleState {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
DirtyValue<bool> motionSensorOk {};
|
||||||
|
@ -58,7 +59,6 @@ namespace Pinetime {
|
||||||
lv_obj_t* backgroundLabel;
|
lv_obj_t* backgroundLabel;
|
||||||
lv_obj_t* batteryIcon;
|
lv_obj_t* batteryIcon;
|
||||||
lv_obj_t* bleIcon;
|
lv_obj_t* bleIcon;
|
||||||
lv_obj_t* batteryPlug;
|
|
||||||
lv_obj_t* calendarOuter;
|
lv_obj_t* calendarOuter;
|
||||||
lv_obj_t* calendarInner;
|
lv_obj_t* calendarInner;
|
||||||
lv_obj_t* calendarBar1;
|
lv_obj_t* calendarBar1;
|
||||||
|
@ -76,6 +76,8 @@ namespace Pinetime {
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
Controllers::MotionController& motionController;
|
Controllers::MotionController& motionController;
|
||||||
|
|
||||||
|
void SetBatteryIcon();
|
||||||
|
|
||||||
lv_task_t* taskRefresh;
|
lv_task_t* taskRefresh;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,11 +176,31 @@ void WatchFaceAnalog::UpdateClock() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WatchFaceAnalog::SetBatteryIcon() {
|
||||||
|
auto batteryPercent = batteryPercentRemaining.Get();
|
||||||
|
if (batteryPercent == 100) {
|
||||||
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
|
}
|
||||||
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
||||||
|
}
|
||||||
|
|
||||||
void WatchFaceAnalog::Refresh() {
|
void WatchFaceAnalog::Refresh() {
|
||||||
batteryPercentRemaining = batteryController.PercentRemaining();
|
isCharging = batteryController.IsCharging();
|
||||||
if (batteryPercentRemaining.IsUpdated()) {
|
if (isCharging.IsUpdated()) {
|
||||||
auto batteryPercent = batteryPercentRemaining.Get();
|
if (isCharging.Get()) {
|
||||||
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
|
lv_label_set_text(batteryIcon, Symbols::plug);
|
||||||
|
} else {
|
||||||
|
SetBatteryIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isCharging.Get()) {
|
||||||
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
||||||
|
if (batteryPercentRemaining.IsUpdated()) {
|
||||||
|
SetBatteryIcon();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationState = notificationManager.AreNewNotificationsAvailable();
|
notificationState = notificationManager.AreNewNotificationsAvailable();
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace Pinetime {
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {0};
|
DirtyValue<uint8_t> batteryPercentRemaining {0};
|
||||||
|
DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
|
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
|
||||||
DirtyValue<bool> notificationState {false};
|
DirtyValue<bool> notificationState {false};
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ namespace Pinetime {
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
|
|
||||||
void UpdateClock();
|
void UpdateClock();
|
||||||
|
void SetBatteryIcon();
|
||||||
|
|
||||||
lv_task_t* taskRefresh;
|
lv_task_t* taskRefresh;
|
||||||
};
|
};
|
||||||
|
|
|
@ -102,12 +102,20 @@ WatchFaceDigital::~WatchFaceDigital() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFaceDigital::Refresh() {
|
void WatchFaceDigital::Refresh() {
|
||||||
|
isCharging = batteryController.IsCharging();
|
||||||
|
if (isCharging.IsUpdated()) {
|
||||||
|
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging.Get()));
|
||||||
|
}
|
||||||
|
|
||||||
batteryPercentRemaining = batteryController.PercentRemaining();
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
||||||
if (batteryPercentRemaining.IsUpdated()) {
|
if (batteryPercentRemaining.IsUpdated()) {
|
||||||
auto batteryPercent = batteryPercentRemaining.Get();
|
auto batteryPercent = batteryPercentRemaining.Get();
|
||||||
|
if (batteryPercent == 100) {
|
||||||
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
|
}
|
||||||
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
||||||
auto isCharging = batteryController.IsCharging() or batteryController.IsPowerPresent();
|
|
||||||
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bleState = bleController.IsConnected();
|
bleState = bleController.IsConnected();
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace Pinetime {
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
|
DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<bool> bleState {};
|
DirtyValue<bool> bleState {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
DirtyValue<bool> motionSensorOk {};
|
||||||
|
|
Loading…
Reference in a new issue