aboutsummaryrefslogtreecommitdiffstats
path: root/src/systemtask
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemtask')
-rw-r--r--src/systemtask/Messages.h4
-rw-r--r--src/systemtask/SystemTask.cpp32
-rw-r--r--src/systemtask/SystemTask.h3
3 files changed, 27 insertions, 12 deletions
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h
index 7a46e060..b7fee8a5 100644
--- a/src/systemtask/Messages.h
+++ b/src/systemtask/Messages.h
@@ -1,8 +1,9 @@
#pragma once
+#include <cstdint>
namespace Pinetime {
namespace System {
- enum class Messages {
+ enum class Messages : uint8_t {
GoToSleep,
GoToRunning,
TouchWakeUp,
@@ -29,6 +30,7 @@ namespace Pinetime {
StopRinging,
MeasureBatteryTimerExpired,
BatteryPercentageUpdated,
+ LowBattery,
StartFileTransfer,
StopFileTransfer,
BleRadioEnableToggle
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index ef631af7..73f573fa 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -18,6 +18,8 @@
#include "BootErrors.h"
#include <memory>
+#include <algorithm>
+#include <cstring>
using namespace Pinetime::System;
@@ -30,14 +32,14 @@ namespace {
void DimTimerCallback(TimerHandle_t xTimer) {
NRF_LOG_INFO("DimTimerCallback");
- auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
+ auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
sysTask->OnDim();
}
void IdleTimerCallback(TimerHandle_t xTimer) {
NRF_LOG_INFO("IdleTimerCallback");
- auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
+ auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
sysTask->OnIdle();
}
@@ -208,10 +210,9 @@ void SystemTask::Work() {
while (true) {
UpdateMotion();
- uint8_t msg;
- if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
- Messages message = static_cast<Messages>(msg);
- switch (message) {
+ Messages msg;
+ if (xQueueReceive(systemTasksMsgQueue, &msg, 100) == pdTRUE) {
+ switch (msg) {
case Messages::EnableSleeping:
// Make sure that exiting an app doesn't enable sleeping,
// if the exiting was caused by a firmware update
@@ -348,7 +349,7 @@ void SystemTask::Work() {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::HandleButtonEvent: {
- Controllers::ButtonActions action;
+ Controllers::ButtonActions action = Controllers::ButtonActions::None;
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
} else {
@@ -425,6 +426,16 @@ void SystemTask::Work() {
case Messages::BatteryPercentageUpdated:
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
break;
+ case Messages::LowBattery: {
+ Pinetime::Controllers::NotificationManager::Notification notif;
+ constexpr char message[] = "Low Battery\0Charge your watch to prevent data loss.\0";
+ constexpr size_t messageSize = std::min(sizeof(message), Pinetime::Controllers::NotificationManager::MaximumMessageSize());
+ std::memcpy(notif.message.data(), message, messageSize);
+ notif.size = messageSize;
+ notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
+ notificationManager.Push(std::move(notif));
+ PushMessage(Messages::OnNewNotification);
+ } break;
case Messages::OnPairing:
if (state == SystemTaskState::Sleeping) {
GoToRunning();
@@ -459,7 +470,7 @@ void SystemTask::Work() {
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
dateTimeController.UpdateTime(systick_counter);
NoInit_BackUpTime = dateTimeController.CurrentDateTime();
- if (!nrf_gpio_pin_read(PinMap::Button)) {
+ if (nrf_gpio_pin_read(PinMap::Button) == 0) {
watchdog.Kick();
}
}
@@ -552,10 +563,9 @@ void SystemTask::PushMessage(System::Messages msg) {
}
if (in_isr()) {
- BaseType_t xHigherPriorityTaskWoken;
- xHigherPriorityTaskWoken = pdFALSE;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
- if (xHigherPriorityTaskWoken) {
+ if (xHigherPriorityTaskWoken == pdTRUE) {
/* Actual macro used here is port specific. */
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h
index d1e4a004..9c43b9b2 100644
--- a/src/systemtask/SystemTask.h
+++ b/src/systemtask/SystemTask.h
@@ -36,6 +36,7 @@
#include "systemtask/Messages.h"
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
+
namespace Pinetime {
namespace Drivers {
class Cst816S;
@@ -45,11 +46,13 @@ namespace Pinetime {
class TwiMaster;
class Hrs3300;
}
+
namespace Controllers {
class Battery;
class TouchHandler;
class ButtonHandler;
}
+
namespace System {
class SystemTask {
public: