added message, changed UI
This commit is contained in:
parent
59ee0ad1aa
commit
cad58f190f
4 changed files with 12 additions and 8 deletions
|
@ -96,13 +96,12 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
|
||||||
lastPercentRemaining = percentRemaining;
|
lastPercentRemaining = percentRemaining;
|
||||||
percentRemaining = newPercent;
|
percentRemaining = newPercent;
|
||||||
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
|
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
|
||||||
}
|
|
||||||
|
|
||||||
// warn at 20% battery (wrt. rescaling above)
|
// warn at 20% battery (wrt. rescaling above)
|
||||||
constexpr uint8_t lowBatteryThreshold {20};
|
if (!isPowerPresent && BatteryIsLow() && lastPercentRemaining > lowBatteryThreshold) {
|
||||||
if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) {
|
|
||||||
systemTask->PushMessage(System::Messages::LowBattery);
|
systemTask->PushMessage(System::Messages::LowBattery);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nrfx_saadc_uninit();
|
nrfx_saadc_uninit();
|
||||||
isReading = false;
|
isReading = false;
|
||||||
|
|
|
@ -17,6 +17,9 @@ namespace Pinetime {
|
||||||
uint8_t PercentRemaining() const {
|
uint8_t PercentRemaining() const {
|
||||||
return percentRemaining;
|
return percentRemaining;
|
||||||
}
|
}
|
||||||
|
bool BatteryIsLow() const {
|
||||||
|
return percentRemaining <= lowBatteryThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t Voltage() const {
|
uint16_t Voltage() const {
|
||||||
return voltage;
|
return voltage;
|
||||||
|
@ -51,6 +54,8 @@ namespace Pinetime {
|
||||||
void SaadcEventHandler(nrfx_saadc_evt_t const* p_event);
|
void SaadcEventHandler(nrfx_saadc_evt_t const* p_event);
|
||||||
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
|
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
|
||||||
|
|
||||||
|
static constexpr uint8_t lowBatteryThreshold {20};
|
||||||
|
|
||||||
bool isReading = false;
|
bool isReading = false;
|
||||||
|
|
||||||
Pinetime::System::SystemTask* systemTask = nullptr;
|
Pinetime::System::SystemTask* systemTask = nullptr;
|
||||||
|
|
|
@ -59,7 +59,7 @@ void BatteryInfo::Refresh() {
|
||||||
} else if (batteryPercent == 100) {
|
} else if (batteryPercent == 100) {
|
||||||
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 (batteryController.BatteryIsLow()) {
|
||||||
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
||||||
lv_label_set_text_static(status, "Battery low");
|
lv_label_set_text_static(status, "Battery low");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -426,9 +426,9 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::LowBattery: {
|
case Messages::LowBattery: {
|
||||||
Pinetime::Controllers::NotificationManager::Notification notif;
|
Pinetime::Controllers::NotificationManager::Notification notif;
|
||||||
std::array<char, 101> message {"Low Battery\0Low Battery\0"};
|
std::array<char, 101> message {"Low Battery\0Charge your watch to prevent data loss\0"};
|
||||||
notif.message = message;
|
notif.message = message;
|
||||||
notif.size = 25;
|
notif.size = 52;
|
||||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
||||||
notificationManager.Push(std::move(notif));
|
notificationManager.Push(std::move(notif));
|
||||||
PushMessage(Messages::OnNewNotification);
|
PushMessage(Messages::OnNewNotification);
|
||||||
|
|
Loading…
Reference in a new issue