mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-12-01 07:02:02 +03:00
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 <date/date.h>
|
||||
#include <libraries/log/nrf_log.h>
|
||||
#include <systemtask/SystemTask.h>
|
||||
|
||||
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,
|
||||
uint8_t second, uint32_t systickCounter) {
|
||||
@ -62,6 +67,14 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
|
||||
hour = time.hours().count();
|
||||
minute = time.minutes().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() {
|
||||
|
@ -4,12 +4,17 @@
|
||||
#include <chrono>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
}
|
||||
namespace Controllers {
|
||||
class DateTime {
|
||||
public:
|
||||
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};
|
||||
|
||||
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 UpdateTime(uint32_t systickCounter);
|
||||
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::seconds Uptime() const { return uptime; }
|
||||
private:
|
||||
System::SystemTask& systemTask;
|
||||
uint16_t year = 0;
|
||||
Months month = Months::Unknown;
|
||||
uint8_t day = 0;
|
||||
@ -43,6 +49,8 @@ namespace Pinetime {
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
|
||||
std::chrono::seconds uptime {0};
|
||||
|
||||
bool isMidnightAlreadyNotified = false;
|
||||
|
||||
static char const *DaysString[];
|
||||
static char const *DaysStringShort[];
|
||||
static char const *DaysStringLow[];
|
||||
|
@ -105,3 +105,7 @@ Bma421::Values Bma421::Process() {
|
||||
bool Bma421::IsOk() const {
|
||||
return isOk;
|
||||
}
|
||||
|
||||
void Bma421::ResetStepCounter() {
|
||||
bma423_reset_step_counter(&bma);
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ namespace Pinetime {
|
||||
Bma421& operator=(Bma421&&) = delete;
|
||||
|
||||
void Init();
|
||||
void Reset();
|
||||
Values Process();
|
||||
void ResetStepCounter();
|
||||
|
||||
void Read(uint8_t registerAddress, uint8_t *buffer, size_t size);
|
||||
void Write(uint8_t registerAddress, const uint8_t *data, size_t size);
|
||||
@ -28,6 +28,8 @@ namespace Pinetime {
|
||||
bool IsOk() const;
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
|
||||
TwiMaster& twiMaster;
|
||||
uint8_t deviceAddress = 0x18;
|
||||
struct bma4_dev bma;
|
||||
|
@ -107,7 +107,6 @@ Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress
|
||||
TimerHandle_t debounceTimer;
|
||||
Pinetime::Controllers::Battery batteryController;
|
||||
Pinetime::Controllers::Ble bleController;
|
||||
Pinetime::Controllers::DateTime dateTimeController;
|
||||
void ble_manager_set_ble_connection_callback(void (*connection)());
|
||||
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
||||
static constexpr uint8_t pinTouchIrq = 28;
|
||||
@ -259,7 +258,7 @@ int main(void) {
|
||||
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
|
||||
|
||||
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();
|
||||
nimble_port_init();
|
||||
|
||||
|
@ -40,7 +40,6 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
||||
Components::LittleVgl &lvgl,
|
||||
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
||||
Controllers::DateTime &dateTimeController,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
||||
Pinetime::Drivers::Bma421& motionSensor,
|
||||
@ -48,7 +47,7 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
|
||||
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
|
||||
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
|
||||
heartRateController{*this},
|
||||
bleController{bleController}, dateTimeController{dateTimeController},
|
||||
bleController{bleController}, dateTimeController{*this},
|
||||
watchdog{}, watchdogView{watchdog},
|
||||
motorController{motorController}, heartRateSensor{heartRateSensor}, motionSensor{motionSensor},
|
||||
settingsController{settingsController},
|
||||
@ -210,6 +209,11 @@ void SystemTask::Work() {
|
||||
isSleeping = true;
|
||||
isGoingToSleep = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -239,6 +243,12 @@ void SystemTask::UpdateMotion() {
|
||||
|
||||
if(isSleeping)
|
||||
twiMaster.Wakeup();
|
||||
|
||||
if(stepCounterMustBeReset) {
|
||||
motionSensor.ResetStepCounter();
|
||||
stepCounterMustBeReset = false;
|
||||
}
|
||||
|
||||
auto motionValues = motionSensor.Process();
|
||||
if(isSleeping)
|
||||
twiMaster.Sleep();
|
||||
|
@ -40,7 +40,8 @@ namespace Pinetime {
|
||||
class SystemTask {
|
||||
public:
|
||||
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,
|
||||
@ -48,7 +49,6 @@ namespace Pinetime {
|
||||
Drivers::TwiMaster& twiMaster, Drivers::Cst816S &touchPanel,
|
||||
Components::LittleVgl &lvgl,
|
||||
Controllers::Battery &batteryController, Controllers::Ble &bleController,
|
||||
Controllers::DateTime &dateTimeController,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Drivers::Hrs3300& heartRateSensor,
|
||||
Pinetime::Drivers::Bma421& motionSensor,
|
||||
@ -80,7 +80,7 @@ namespace Pinetime {
|
||||
std::unique_ptr<Pinetime::Applications::HeartRateTask> heartRateApp;
|
||||
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Controllers::DateTime& dateTimeController;
|
||||
Pinetime::Controllers::DateTime dateTimeController;
|
||||
QueueHandle_t systemTasksMsgQueue;
|
||||
std::atomic<bool> isSleeping{false};
|
||||
std::atomic<bool> isGoingToSleep{false};
|
||||
@ -115,6 +115,7 @@ namespace Pinetime {
|
||||
|
||||
void GoToRunning();
|
||||
void UpdateMotion();
|
||||
bool stepCounterMustBeReset = false;
|
||||
|
||||
#if configUSE_TRACE_FACILITY == 1
|
||||
SystemMonitor<FreeRtosMonitor> monitor;
|
||||
|
Loading…
Reference in New Issue
Block a user