Reset the step count every day at midnight.
This commit is contained in:
parent
52a90288fd
commit
1d7576de64
|
@ -1,9 +1,14 @@
|
||||||
#include "DateTimeController.h"
|
#include "DateTimeController.h"
|
||||||
#include <date/date.h>
|
#include <date/date.h>
|
||||||
#include <libraries/log/nrf_log.h>
|
#include <libraries/log/nrf_log.h>
|
||||||
|
#include <systemtask/SystemTask.h>
|
||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
|
DateTime::DateTime(System::SystemTask& systemTask) : systemTask{systemTask} {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute,
|
void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute,
|
||||||
uint8_t second, uint32_t systickCounter) {
|
uint8_t second, uint32_t systickCounter) {
|
||||||
|
@ -62,6 +67,14 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
|
||||||
hour = time.hours().count();
|
hour = time.hours().count();
|
||||||
minute = time.minutes().count();
|
minute = time.minutes().count();
|
||||||
second = time.seconds().count();
|
second = time.seconds().count();
|
||||||
|
|
||||||
|
// Notify new day to SystemTask
|
||||||
|
if(hour == 0 and not isMidnightAlreadyNotified) {
|
||||||
|
isMidnightAlreadyNotified = true;
|
||||||
|
systemTask.PushMessage(System::SystemTask::Messages::OnNewDay);
|
||||||
|
} else if (hour != 0) {
|
||||||
|
isMidnightAlreadyNotified = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *DateTime::MonthShortToString() {
|
const char *DateTime::MonthShortToString() {
|
||||||
|
|
|
@ -4,12 +4,17 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
namespace System {
|
||||||
|
class SystemTask;
|
||||||
|
}
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
class DateTime {
|
class DateTime {
|
||||||
public:
|
public:
|
||||||
enum class Days : uint8_t {Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
|
enum class Days : uint8_t {Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
|
||||||
enum class Months : uint8_t {Unknown, January, February, March, April, May, June, July, August, September, October, November, December};
|
enum class Months : uint8_t {Unknown, January, February, March, April, May, June, July, August, September, October, November, December};
|
||||||
|
|
||||||
|
DateTime(System::SystemTask& systemTask);
|
||||||
|
|
||||||
void SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter);
|
void SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter);
|
||||||
void UpdateTime(uint32_t systickCounter);
|
void UpdateTime(uint32_t systickCounter);
|
||||||
uint16_t Year() const { return year; }
|
uint16_t Year() const { return year; }
|
||||||
|
@ -31,6 +36,7 @@ namespace Pinetime {
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
|
||||||
std::chrono::seconds Uptime() const { return uptime; }
|
std::chrono::seconds Uptime() const { return uptime; }
|
||||||
private:
|
private:
|
||||||
|
System::SystemTask& systemTask;
|
||||||
uint16_t year = 0;
|
uint16_t year = 0;
|
||||||
Months month = Months::Unknown;
|
Months month = Months::Unknown;
|
||||||
uint8_t day = 0;
|
uint8_t day = 0;
|
||||||
|
@ -43,6 +49,8 @@ namespace Pinetime {
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
|
||||||
std::chrono::seconds uptime {0};
|
std::chrono::seconds uptime {0};
|
||||||
|
|
||||||
|
bool isMidnightAlreadyNotified = false;
|
||||||
|
|
||||||
static char const *DaysString[];
|
static char const *DaysString[];
|
||||||
static char const *DaysStringShort[];
|
static char const *DaysStringShort[];
|
||||||
static char const *DaysStringLow[];
|
static char const *DaysStringLow[];
|
||||||
|
|
|
@ -105,3 +105,7 @@ Bma421::Values Bma421::Process() {
|
||||||
bool Bma421::IsOk() const {
|
bool Bma421::IsOk() const {
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bma421::ResetStepCounter() {
|
||||||
|
bma423_reset_step_counter(&bma);
|
||||||
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace Pinetime {
|
||||||
Bma421& operator=(Bma421&&) = delete;
|
Bma421& operator=(Bma421&&) = delete;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Reset();
|
|
||||||
Values Process();
|
Values Process();
|
||||||
|
void ResetStepCounter();
|
||||||
|
|
||||||
void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
|
void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
|
||||||
void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
|
void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
|
||||||
|
@ -28,6 +28,8 @@ namespace Pinetime {
|
||||||
bool IsOk() const;
|
bool IsOk() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Reset();
|
||||||
|
|
||||||
TwiMaster& twiMaster;
|
TwiMaster& twiMaster;
|
||||||
uint8_t deviceAddress = 0x18;
|
uint8_t deviceAddress = 0x18;
|
||||||
struct bma4_dev bma;
|
struct bma4_dev bma;
|
||||||
|
|
|
@ -107,7 +107,6 @@ Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress
|
||||||
TimerHandle_t debounceTimer;
|
TimerHandle_t debounceTimer;
|
||||||
Pinetime::Controllers::Battery batteryController;
|
Pinetime::Controllers::Battery batteryController;
|
||||||
Pinetime::Controllers::Ble bleController;
|
Pinetime::Controllers::Ble bleController;
|
||||||
Pinetime::Controllers::DateTime dateTimeController;
|
|
||||||
void ble_manager_set_ble_connection_callback(void (*connection)());
|
void ble_manager_set_ble_connection_callback(void (*connection)());
|
||||||
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
||||||
static constexpr uint8_t pinTouchIrq = 28;
|
static constexpr uint8_t pinTouchIrq = 28;
|
||||||
|
@ -259,7 +258,7 @@ int main(void) {
|
||||||
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
|
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
|
||||||
|
|
||||||
systemTask = std::make_unique<Pinetime::System::SystemTask>(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController,
|
systemTask = std::make_unique<Pinetime::System::SystemTask>(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController,
|
||||||
dateTimeController, motorController, heartRateSensor, motionSensor, settingsController);
|
motorController, heartRateSensor, motionSensor, settingsController);
|
||||||
systemTask->Start();
|
systemTask->Start();
|
||||||
nimble_port_init();
|
nimble_port_init();
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||||
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
||||||
Components::LittleVgl &lvgl,
|
Components::LittleVgl &lvgl,
|
||||||
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
||||||
Controllers::DateTime &dateTimeController,
|
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
||||||
Pinetime::Drivers::Bma421& motionSensor,
|
Pinetime::Drivers::Bma421& motionSensor,
|
||||||
|
@ -48,7 +47,7 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||||
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
|
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
|
||||||
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
|
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
|
||||||
heartRateController{*this},
|
heartRateController{*this},
|
||||||
bleController{bleController}, dateTimeController{dateTimeController},
|
bleController{bleController}, dateTimeController{*this},
|
||||||
watchdog{}, watchdogView{watchdog},
|
watchdog{}, watchdogView{watchdog},
|
||||||
motorController{motorController}, heartRateSensor{heartRateSensor}, motionSensor{motionSensor},
|
motorController{motorController}, heartRateSensor{heartRateSensor}, motionSensor{motionSensor},
|
||||||
settingsController{settingsController},
|
settingsController{settingsController},
|
||||||
|
@ -210,6 +209,11 @@ void SystemTask::Work() {
|
||||||
isSleeping = true;
|
isSleeping = true;
|
||||||
isGoingToSleep = false;
|
isGoingToSleep = false;
|
||||||
break;
|
break;
|
||||||
|
case Messages::OnNewDay:
|
||||||
|
// We might be sleeping (with TWI device disabled.
|
||||||
|
// Remember we'll have to reset the counter next time we're awake
|
||||||
|
stepCounterMustBeReset = true;
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,6 +243,12 @@ void SystemTask::UpdateMotion() {
|
||||||
|
|
||||||
if(isSleeping)
|
if(isSleeping)
|
||||||
twiMaster.Wakeup();
|
twiMaster.Wakeup();
|
||||||
|
|
||||||
|
if(stepCounterMustBeReset) {
|
||||||
|
motionSensor.ResetStepCounter();
|
||||||
|
stepCounterMustBeReset = false;
|
||||||
|
}
|
||||||
|
|
||||||
auto motionValues = motionSensor.Process();
|
auto motionValues = motionSensor.Process();
|
||||||
if(isSleeping)
|
if(isSleeping)
|
||||||
twiMaster.Sleep();
|
twiMaster.Sleep();
|
||||||
|
|
|
@ -40,7 +40,8 @@ namespace Pinetime {
|
||||||
class SystemTask {
|
class SystemTask {
|
||||||
public:
|
public:
|
||||||
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, OnNewCall, BleConnected,
|
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, OnNewCall, BleConnected,
|
||||||
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
|
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping,
|
||||||
|
OnNewDay
|
||||||
};
|
};
|
||||||
|
|
||||||
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||||
|
@ -48,7 +49,6 @@ namespace Pinetime {
|
||||||
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
||||||
Components::LittleVgl &lvgl,
|
Components::LittleVgl &lvgl,
|
||||||
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
||||||
Controllers::DateTime &dateTimeController,
|
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
||||||
Pinetime::Drivers::Bma421& motionSensor,
|
Pinetime::Drivers::Bma421& motionSensor,
|
||||||
|
@ -80,7 +80,7 @@ namespace Pinetime {
|
||||||
std::unique_ptr<Pinetime::Applications::HeartRateTask> heartRateApp;
|
std::unique_ptr<Pinetime::Applications::HeartRateTask> heartRateApp;
|
||||||
|
|
||||||
Pinetime::Controllers::Ble& bleController;
|
Pinetime::Controllers::Ble& bleController;
|
||||||
Pinetime::Controllers::DateTime& dateTimeController;
|
Pinetime::Controllers::DateTime dateTimeController;
|
||||||
QueueHandle_t systemTasksMsgQueue;
|
QueueHandle_t systemTasksMsgQueue;
|
||||||
std::atomic<bool> isSleeping{false};
|
std::atomic<bool> isSleeping{false};
|
||||||
std::atomic<bool> isGoingToSleep{false};
|
std::atomic<bool> isGoingToSleep{false};
|
||||||
|
@ -115,6 +115,7 @@ namespace Pinetime {
|
||||||
|
|
||||||
void GoToRunning();
|
void GoToRunning();
|
||||||
void UpdateMotion();
|
void UpdateMotion();
|
||||||
|
bool stepCounterMustBeReset = false;
|
||||||
|
|
||||||
#if configUSE_TRACE_FACILITY == 1
|
#if configUSE_TRACE_FACILITY == 1
|
||||||
SystemMonitor<FreeRtosMonitor> monitor;
|
SystemMonitor<FreeRtosMonitor> monitor;
|
||||||
|
|
Loading…
Reference in a new issue