summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/battery/BatteryController.cpp11
-rw-r--r--src/components/battery/BatteryController.h7
-rw-r--r--src/components/settings/Settings.h2
-rw-r--r--src/displayapp/DisplayApp.cpp6
-rw-r--r--src/displayapp/Messages.h1
-rw-r--r--src/displayapp/screens/BatteryInfo.cpp2
-rw-r--r--src/displayapp/screens/Notifications.cpp3
-rw-r--r--src/displayapp/screens/Notifications.h8
-rw-r--r--src/displayapp/screens/settings/Settings.cpp4
-rw-r--r--src/main.cpp9
-rw-r--r--src/systemtask/Messages.h4
-rw-r--r--src/systemtask/SystemTask.cpp35
-rw-r--r--src/systemtask/SystemTask.h6
13 files changed, 45 insertions, 53 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index cabf101b..4ef20a24 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -10,10 +10,7 @@ Battery* Battery::instance = nullptr;
Battery::Battery() {
instance = this;
-}
-
-void Battery::Init() {
- nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
+ nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
}
void Battery::Update() {
@@ -76,5 +73,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
nrfx_saadc_uninit();
isReading = false;
+
+ systemTask->PushMessage(System::Messages::BatteryMeasurementDone);
}
}
+
+void Battery::Register(Pinetime::System::SystemTask* systemTask) {
+ this->systemTask = systemTask;
+}
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index f33b05ef..8af27ea8 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -1,8 +1,7 @@
#pragma once
#include <cstdint>
#include <drivers/include/nrfx_saadc.h>
-#include <array>
-#include <numeric>
+#include <systemtask/SystemTask.h>
namespace Pinetime {
namespace Controllers {
@@ -11,8 +10,8 @@ namespace Pinetime {
public:
Battery();
- void Init();
void Update();
+ void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const {
return percentRemaining;
@@ -47,6 +46,8 @@ namespace Pinetime {
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
bool isReading = false;
+
+ Pinetime::System::SystemTask* systemTask = nullptr;
};
}
}
diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index a294ab78..a54ba976 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -114,7 +114,7 @@ namespace Pinetime {
};
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
- if (!isWakeUpModeOn(wakeUp)) {
+ if (enabled != isWakeUpModeOn(wakeUp)) {
settingsChanged = true;
}
settings.wakeUpMode.set(static_cast<size_t>(wakeUp), enabled);
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index d6100ece..5e74baa0 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -136,9 +136,6 @@ void DisplayApp::InitHw() {
brightnessController.Set(settingsController.GetBrightness());
}
-uint32_t acc = 0;
-uint32_t count = 0;
-bool toggle = true;
void DisplayApp::Refresh() {
TickType_t queueTimeout;
TickType_t delta;
@@ -194,9 +191,6 @@ void DisplayApp::Refresh() {
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
// Screens::Clock::BleConnectionStates::NotConnected);
break;
- case Messages::UpdateBatteryLevel:
- batteryController.Update();
- break;
case Messages::NewNotification:
LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break;
diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h
index 322505e6..8e4884db 100644
--- a/src/displayapp/Messages.h
+++ b/src/displayapp/Messages.h
@@ -7,7 +7,6 @@ namespace Pinetime {
GoToRunning,
UpdateDateTime,
UpdateBleConnection,
- UpdateBatteryLevel,
TouchEvent,
ButtonPushed,
NewNotification,
diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp
index 91c26512..ad9af153 100644
--- a/src/displayapp/screens/BatteryInfo.cpp
+++ b/src/displayapp/screens/BatteryInfo.cpp
@@ -55,8 +55,6 @@ BatteryInfo::~BatteryInfo() {
void BatteryInfo::Refresh() {
- batteryController.Update();
-
batteryPercent = batteryController.PercentRemaining();
batteryVoltage = batteryController.Voltage();
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index fd0b86da..417dff00 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -73,7 +73,6 @@ void Notifications::Refresh() {
timeoutLinePoints[1].x = pos;
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
}
- running = currentItem->IsRunning();
}
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
@@ -153,7 +152,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
uint8_t notifNb,
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
- : notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
+ : mode {mode}, alertNotificationService {alertNotificationService} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h
index f6f8b4c3..0b5271e7 100644
--- a/src/displayapp/screens/Notifications.h
+++ b/src/displayapp/screens/Notifications.h
@@ -43,21 +43,13 @@ namespace Pinetime {
void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
private:
- uint8_t notifNr = 0;
- uint8_t notifNb = 0;
- char pageText[4];
-
lv_obj_t* container1;
- lv_obj_t* t1;
- lv_obj_t* l1;
- lv_obj_t* l2;
lv_obj_t* bt_accept;
lv_obj_t* bt_mute;
lv_obj_t* bt_reject;
lv_obj_t* label_accept;
lv_obj_t* label_mute;
lv_obj_t* label_reject;
- lv_obj_t* bottomPlaceholder;
Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
bool running = true;
diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp
index f82b03c1..e3319f03 100644
--- a/src/displayapp/screens/settings/Settings.cpp
+++ b/src/displayapp/screens/settings/Settings.cpp
@@ -50,8 +50,8 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::array<Screens::List::Applications, 4> applications {{
{Symbols::shoe, "Steps", Apps::SettingSteps},
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
+ {Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
{Symbols::check, "Firmware", Apps::FirmwareValidation},
- {Symbols::list, "About", Apps::SysInfo},
}};
return std::make_unique<Screens::List>(1, 3, app, settingsController, applications);
@@ -60,7 +60,7 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
std::unique_ptr<Screen> Settings::CreateScreen3() {
std::array<Screens::List::Applications, 4> applications {{
- {Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
+ {Symbols::list, "About", Apps::SysInfo},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
{Symbols::none, "None", Apps::None},
diff --git a/src/main.cpp b/src/main.cpp
index 441fbd95..0d4ba42f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,16 +81,13 @@ static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000};
Pinetime::Drivers::TwiMaster twiMaster {NRF_TWIM1, MaxTwiFrequencyWithoutHardwareBug, Pinetime::PinMap::TwiSda, Pinetime::PinMap::TwiScl};
Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
#ifdef PINETIME_IS_RECOVERY
-static constexpr bool isFactory = true;
#include "displayapp/DummyLittleVgl.h"
#include "displayapp/DisplayAppRecovery.h"
-Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#else
-static constexpr bool isFactory = false;
#include "displayapp/LittleVgl.h"
#include "displayapp/DisplayApp.h"
-Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
#endif
+Pinetime::Components::LittleVgl lvgl {lcd, touchPanel};
Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress};
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
@@ -99,8 +96,8 @@ TimerHandle_t debounceTimer;
TimerHandle_t debounceChargeTimer;
Pinetime::Controllers::Battery batteryController;
Pinetime::Controllers::Ble bleController;
-void ble_manager_set_ble_connection_callback(void (*connection)());
-void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
+static constexpr uint8_t pinTouchIrq = Pinetime::PinMap::Cst816sIrq;
+static constexpr uint8_t pinPowerPresentIrq = Pinetime::PinMap::PowerPresent;
Pinetime::Controllers::HeartRateController heartRateController;
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController);
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h
index 3a195e2d..ebe6a2b1 100644
--- a/src/systemtask/Messages.h
+++ b/src/systemtask/Messages.h
@@ -20,7 +20,9 @@ namespace Pinetime {
EnableSleeping,
DisableSleeping,
OnNewDay,
- OnChargingEvent
+ OnChargingEvent,
+ MeasureBatteryTimerExpired,
+ BatteryMeasurementDone,
};
}
}
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index d48b559a..18f5ecbf 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -49,6 +49,11 @@ void IdleTimerCallback(TimerHandle_t xTimer) {
sysTask->OnIdle();
}
+void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
+ auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
+ sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
+}
+
SystemTask::SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
@@ -129,7 +134,8 @@ void SystemTask::Work() {
twiMaster.Init();
touchPanel.Init();
dateTimeController.Register(this);
- batteryController.Init();
+ batteryController.Register(this);
+ batteryController.Update();
motorController.Init();
motionSensor.SoftReset();
timerController.Register(this);
@@ -146,8 +152,6 @@ void SystemTask::Work() {
displayApp.Register(this);
displayApp.Start();
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
-
heartRateSensor.Init();
heartRateSensor.Disable();
heartRateApp.Start();
@@ -190,7 +194,9 @@ void SystemTask::Work() {
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
+ measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
xTimerStart(dimTimer, 0);
+ xTimerStart(measureBatteryTimer, portMAX_DELAY);
// Suppress endless loop diagnostic
#pragma clang diagnostic push
@@ -200,11 +206,6 @@ void SystemTask::Work() {
uint8_t msg;
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
-
- batteryController.Update();
- // the battery does not emit events when changing charge levels, so we piggyback
- // on any system event to read and update the current values
-
Messages message = static_cast<Messages>(msg);
switch (message) {
case Messages::EnableSleeping:
@@ -234,7 +235,6 @@ void SystemTask::Work() {
lcd.Wakeup();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp);
isSleeping = false;
@@ -329,8 +329,18 @@ void SystemTask::Work() {
stepCounterMustBeReset = true;
break;
case Messages::OnChargingEvent:
+ batteryController.Update();
motorController.RunForDuration(15);
- // Battery level is updated on every message - there's no need to do anything
+ break;
+ case Messages::MeasureBatteryTimerExpired:
+ sendBatteryNotification = true;
+ batteryController.Update();
+ break;
+ case Messages::BatteryMeasurementDone:
+ if (sendBatteryNotification) {
+ sendBatteryNotification = false;
+ nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
+ }
break;
default:
@@ -349,11 +359,6 @@ void SystemTask::Work() {
}
}
- if (xTaskGetTickCount() - batteryNotificationTick > batteryNotificationPeriod) {
- nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
- batteryNotificationTick = xTaskGetTickCount();
- }
-
monitor.Process();
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
dateTimeController.UpdateTime(systick_counter);
diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h
index 3bf72acd..1f8be75f 100644
--- a/src/systemtask/SystemTask.h
+++ b/src/systemtask/SystemTask.h
@@ -128,13 +128,15 @@ namespace Pinetime {
uint8_t bleDiscoveryTimer = 0;
TimerHandle_t dimTimer;
TimerHandle_t idleTimer;
+ TimerHandle_t measureBatteryTimer;
+ bool sendBatteryNotification = false;
bool doNotGoToSleep = false;
void GoToRunning();
void UpdateMotion();
bool stepCounterMustBeReset = false;
- static constexpr TickType_t batteryNotificationPeriod = 1000 * 60 * 10; // 1 tick ~= 1ms. 1ms * 60 * 10 = 10 minutes
- TickType_t batteryNotificationTick = 0;
+ static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000);
+ TickType_t lastBatteryNotificationTime = 0;
#if configUSE_TRACE_FACILITY == 1
SystemMonitor<FreeRtosMonitor> monitor;