From 2607c3d79947e900ce4c5ded296f649677511a34 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Sun, 16 Jan 2022 23:37:15 +0100 Subject: Let TouchHandler return TouchEvents instead of driver specific enum Let the TouchHandler::GestureGet() function return a TouchEvent instead of the touchpanel-driver specific enum. This helps to move the driver specific helper function `ConvertGesture` from `DisplayApp` into `TouchHandler`. diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 9ce29da..3228061 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -60,28 +60,6 @@ namespace { static inline bool in_isr(void) { return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0; } - - TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) { - switch (gesture) { - case Pinetime::Drivers::Cst816S::Gestures::SingleTap: - return TouchEvents::Tap; - case Pinetime::Drivers::Cst816S::Gestures::LongPress: - return TouchEvents::LongTap; - case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: - return TouchEvents::DoubleTap; - case Pinetime::Drivers::Cst816S::Gestures::SlideRight: - return TouchEvents::SwipeRight; - case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: - return TouchEvents::SwipeLeft; - case Pinetime::Drivers::Cst816S::Gestures::SlideDown: - return TouchEvents::SwipeDown; - case Pinetime::Drivers::Cst816S::Gestures::SlideUp: - return TouchEvents::SwipeUp; - case Pinetime::Drivers::Cst816S::Gestures::None: - default: - return TouchEvents::None; - } - } } DisplayApp::DisplayApp(Drivers::St7789& lcd, @@ -227,7 +205,7 @@ void DisplayApp::Refresh() { if (state != States::Running) { break; } - auto gesture = ConvertGesture(touchHandler.GestureGet()); + auto gesture = touchHandler.GestureGet(); if (gesture == TouchEvents::None) { break; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 77cf411..38c728f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -6,6 +6,7 @@ #include "BootloaderVersion.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" +#include "displayapp/TouchEvents.h" #include "drivers/Cst816s.h" #include "drivers/St7789.h" #include "drivers/InternalFlash.h" @@ -265,10 +266,10 @@ void SystemTask::Work() { case Messages::TouchWakeUp: { if (touchHandler.GetNewTouchInfo()) { auto gesture = touchHandler.GestureGet(); - if (gesture != Pinetime::Drivers::Cst816S::Gestures::None and - ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + if (gesture != Pinetime::Applications::TouchEvents::None and + ((gesture == Pinetime::Applications::TouchEvents::DoubleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or - (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and + (gesture == Pinetime::Applications::TouchEvents::Tap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { GoToRunning(); } diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 0be3347..0e4fb54 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -1,6 +1,36 @@ #include "touchhandler/TouchHandler.h" +#ifdef PINETIME_IS_RECOVERY + #include "displayapp/DummyLittleVgl.h" +#else + #include "displayapp/LittleVgl.h" +#endif using namespace Pinetime::Controllers; +using namespace Pinetime::Applications; + +namespace { + TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) { + switch (gesture) { + case Pinetime::Drivers::Cst816S::Gestures::SingleTap: + return TouchEvents::Tap; + case Pinetime::Drivers::Cst816S::Gestures::LongPress: + return TouchEvents::LongTap; + case Pinetime::Drivers::Cst816S::Gestures::DoubleTap: + return TouchEvents::DoubleTap; + case Pinetime::Drivers::Cst816S::Gestures::SlideRight: + return TouchEvents::SwipeRight; + case Pinetime::Drivers::Cst816S::Gestures::SlideLeft: + return TouchEvents::SwipeLeft; + case Pinetime::Drivers::Cst816S::Gestures::SlideDown: + return TouchEvents::SwipeDown; + case Pinetime::Drivers::Cst816S::Gestures::SlideUp: + return TouchEvents::SwipeUp; + case Pinetime::Drivers::Cst816S::Gestures::None: + default: + return TouchEvents::None; + } + } +} TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} { } @@ -12,9 +42,9 @@ void TouchHandler::CancelTap() { } } -Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { +Pinetime::Applications::TouchEvents TouchHandler::GestureGet() { auto returnGesture = gesture; - gesture = Drivers::Cst816S::Gestures::None; + gesture = Pinetime::Applications::TouchEvents::None; return returnGesture; } @@ -33,11 +63,11 @@ bool TouchHandler::GetNewTouchInfo() { info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight || info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) { if (info.touching) { - gesture = info.gesture; + gesture = ConvertGesture(info.gesture); gestureReleased = false; } } else { - gesture = info.gesture; + gesture = ConvertGesture(info.gesture); } } } diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index ed452b3..fb3d265 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -1,6 +1,6 @@ #pragma once #include "drivers/Cst816s.h" -#include "systemtask/SystemTask.h" +#include "displayapp/TouchEvents.h" namespace Pinetime { namespace Components { @@ -26,13 +26,13 @@ namespace Pinetime { uint8_t GetY() const { return info.y; } - Drivers::Cst816S::Gestures GestureGet(); + Pinetime::Applications::TouchEvents GestureGet(); private: Pinetime::Drivers::Cst816S::TouchInfos info; Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Components::LittleVgl& lvgl; - Pinetime::Drivers::Cst816S::Gestures gesture; + Pinetime::Applications::TouchEvents gesture; bool isCancelled = false; bool gestureReleased = true; }; -- cgit v0.10.2 From 6e1bddcd639da1501d0eed8eba87cc8b69586e2f Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Fri, 15 Apr 2022 10:59:32 +0200 Subject: Test code for missed alarm diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 28b328d..46baa02 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -27,9 +27,11 @@ using namespace std::chrono_literals; AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { } -APP_TIMER_DEF(alarmAppTimer); - namespace { + void SetOffAlarmCallback(TimerHandle_t xTimer) { + auto controller = static_cast(pvTimerGetTimerID(xTimer)); + controller->SetOffAlarmNow(); + } void SetOffAlarm(void* p_context) { auto* controller = static_cast(p_context); if (controller != nullptr) { @@ -39,7 +41,8 @@ namespace { } void AlarmController::Init(System::SystemTask* systemTask) { - app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm); + // app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm); + alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarmCallback); this->systemTask = systemTask; } @@ -50,7 +53,7 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { void AlarmController::ScheduleAlarm() { // Determine the next time the alarm needs to go off and set the app_timer - app_timer_stop(alarmAppTimer); + xTimerStop(alarmAppTimer, 0); auto now = dateTimeController.CurrentDateTime(); alarmTime = now; @@ -81,7 +84,9 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); auto mSecToAlarm = std::chrono::duration_cast(alarmTime - now).count(); - app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this); + // app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this, SetOffAlarm); + xTimerChangePeriod(alarmAppTimer, pdMS_TO_TICKS(mSecToAlarm), 0); + xTimerStart(alarmAppTimer, 0); state = AlarmState::Set; } @@ -91,7 +96,7 @@ uint32_t AlarmController::SecondsToAlarm() { } void AlarmController::DisableAlarm() { - app_timer_stop(alarmAppTimer); + xTimerStop(alarmAppTimer, 0); state = AlarmState::Not_Set; } diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h index f39fbde..fb33edb 100644 --- a/src/components/alarm/AlarmController.h +++ b/src/components/alarm/AlarmController.h @@ -17,6 +17,8 @@ */ #pragma once +#include +#include #include #include "components/datetime/DateTimeController.h" @@ -57,6 +59,7 @@ namespace Pinetime { private: Controllers::DateTime& dateTimeController; System::SystemTask* systemTask = nullptr; + TimerHandle_t alarmAppTimer; uint8_t hours = 7; uint8_t minutes = 0; std::chrono::time_point alarmTime; diff --git a/src/sdk_config.h b/src/sdk_config.h index 7634dca..f6896c3 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -6818,9 +6818,9 @@ // system latency. If queue size is too small app_timer calls // will fail. -#ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 -#endif +// #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE +#define APP_TIMER_CONFIG_OP_QUEUE_SIZE 15 +// #endif // APP_TIMER_CONFIG_USE_SCHEDULER - Enable scheduling app_timer events to app_scheduler -- cgit v0.10.2 From db6d7291ee0f2107a8573df91ce1117914051a2f Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Fri, 15 Apr 2022 22:48:16 +0200 Subject: Refine previous commit diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 46baa02..4c65fcb 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -28,21 +28,15 @@ AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : da } namespace { - void SetOffAlarmCallback(TimerHandle_t xTimer) { + void SetOffAlarm(TimerHandle_t xTimer) { auto controller = static_cast(pvTimerGetTimerID(xTimer)); controller->SetOffAlarmNow(); } - void SetOffAlarm(void* p_context) { - auto* controller = static_cast(p_context); - if (controller != nullptr) { - controller->SetOffAlarmNow(); - } - } } void AlarmController::Init(System::SystemTask* systemTask) { // app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm); - alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarmCallback); + alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm); this->systemTask = systemTask; } diff --git a/src/sdk_config.h b/src/sdk_config.h index f6896c3..7634dca 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -6818,9 +6818,9 @@ // system latency. If queue size is too small app_timer calls // will fail. -// #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE -#define APP_TIMER_CONFIG_OP_QUEUE_SIZE 15 -// #endif +#ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE + #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 +#endif // APP_TIMER_CONFIG_USE_SCHEDULER - Enable scheduling app_timer events to app_scheduler -- cgit v0.10.2 From 83d1b6de1366d66de14cadfb398b9ba4891bfe56 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Fri, 15 Apr 2022 23:30:13 +0200 Subject: Further refine previous commits diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 4c65fcb..33a58fe 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -35,7 +35,6 @@ namespace { } void AlarmController::Init(System::SystemTask* systemTask) { - // app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm); alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm); this->systemTask = systemTask; } @@ -78,7 +77,6 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); auto mSecToAlarm = std::chrono::duration_cast(alarmTime - now).count(); - // app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this, SetOffAlarm); xTimerChangePeriod(alarmAppTimer, pdMS_TO_TICKS(mSecToAlarm), 0); xTimerStart(alarmAppTimer, 0); -- cgit v0.10.2 From 59f59c5f9c929307ed42abafb30f7b7e2b4081f0 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Fri, 15 Apr 2022 23:40:22 +0200 Subject: Mirror changes for timer App diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 79e44d6..1988094 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -4,32 +4,30 @@ #include "components/timer/TimerController.h" #include "systemtask/SystemTask.h" -#include "app_timer.h" #include "task.h" using namespace Pinetime::Controllers; -APP_TIMER_DEF(timerAppTimer); - namespace { - void TimerEnd(void* p_context) { - auto* controller = static_cast (p_context); - if(controller != nullptr) - controller->OnTimerEnd(); + void TimerEnd(TimerHandle_t xTimer) { + auto controller = static_cast(pvTimerGetTimerID(xTimer)); + controller->OnTimerEnd(); } } void TimerController::Init() { - app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, TimerEnd); + timerAppTimer = xTimerCreate("timerAppTm", 1, pdFALSE, this, TimerEnd); } void TimerController::StartTimer(uint32_t duration) { - app_timer_stop(timerAppTimer); + xTimerStop(timerAppTimer,0); auto currentTicks = xTaskGetTickCount(); - app_timer_start(timerAppTimer, APP_TIMER_TICKS(duration), this); - endTicks = currentTicks + APP_TIMER_TICKS(duration); + TickType_t durationTicks = pdMS_TO_TICKS(duration); + xTimerChangePeriod(timerAppTimer, durationTicks, 0); + xTimerStart(timerAppTimer, 0); + endTicks = currentTicks + durationTicks; timerRunning = true; } @@ -51,7 +49,7 @@ uint32_t TimerController::GetTimeRemaining() { } void TimerController::StopTimer() { - app_timer_stop(timerAppTimer); + xTimerStop(timerAppTimer, 0); timerRunning = false; } diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h index fa7bc90..e44d3d9 100644 --- a/src/components/timer/TimerController.h +++ b/src/components/timer/TimerController.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include "app_timer.h" #include "portmacro_cmsis.h" @@ -30,6 +32,7 @@ namespace Pinetime { private: System::SystemTask* systemTask = nullptr; + TimerHandle_t timerAppTimer; TickType_t endTicks; bool timerRunning = false; }; -- cgit v0.10.2 From c92fdb2e8cec3c581124c5efcfb5297ac4cfdcb5 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sat, 16 Apr 2022 00:54:15 +0200 Subject: Switch motorController to FreeRTOS timers. diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index c794a02..a02c037 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -12,32 +12,39 @@ using namespace Pinetime::Controllers; void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); - app_timer_init(); - app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor); - app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring); + shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); + longVibTimer = xTimerCreate("longVibTm", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } -void MotorController::Ring(void* p_context) { - auto* motorController = static_cast(p_context); +void MotorController::Ring(TimerHandle_t xTimer) { + auto motorController = static_cast(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); } void MotorController::RunForDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(PinMap::Motor); - app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr); + if (xTimerChangePeriod(shortVibTimer, pdMS_TO_TICKS(motorDuration), 0) == pdPASS + && xTimerStart(shortVibTimer, 0) == pdPASS) { + return; + } + if (xTimerChangePeriodFromISR(shortVibTimer, pdMS_TO_TICKS(motorDuration), NULL) == pdPASS + && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) { + return; + } + nrf_gpio_pin_set(PinMap::Motor); } void MotorController::StartRinging() { Ring(this); - app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); + xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { - app_timer_stop(longVibTimer); + xTimerStop(longVibTimer, 0); nrf_gpio_pin_set(PinMap::Motor); } -void MotorController::StopMotor(void* p_context) { +void MotorController::StopMotor(TimerHandle_t xTimer) { nrf_gpio_pin_set(PinMap::Motor); } diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index b5a592b..3c6cbd2 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include namespace Pinetime { @@ -15,8 +17,10 @@ namespace Pinetime { void StopRinging(); private: - static void Ring(void* p_context); - static void StopMotor(void* p_context); + static void Ring(TimerHandle_t xTimer); + static void StopMotor(TimerHandle_t xTimer); + TimerHandle_t shortVibTimer; + TimerHandle_t longVibTimer; }; } } -- cgit v0.10.2 From 1d48a97f09104e6b26159622d1631c781498e6f3 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sat, 16 Apr 2022 07:19:28 +0200 Subject: replace pdMS_TO_TICKS with APP_TIMER_TICKS; more tweaks diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 33a58fe..cea679f 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -77,7 +77,7 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); auto mSecToAlarm = std::chrono::duration_cast(alarmTime - now).count(); - xTimerChangePeriod(alarmAppTimer, pdMS_TO_TICKS(mSecToAlarm), 0); + xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0); xTimerStart(alarmAppTimer, 0); state = AlarmState::Set; diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index a02c037..5ff549e 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -14,7 +14,7 @@ void MotorController::Init() { nrf_gpio_pin_set(PinMap::Motor); shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); - longVibTimer = xTimerCreate("longVibTm", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); + longVibTimer = xTimerCreate("longVibTm", APP_TIMER_TICKS(1000), pdTRUE, this, Ring); } void MotorController::Ring(TimerHandle_t xTimer) { @@ -24,11 +24,11 @@ void MotorController::Ring(TimerHandle_t xTimer) { void MotorController::RunForDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(PinMap::Motor); - if (xTimerChangePeriod(shortVibTimer, pdMS_TO_TICKS(motorDuration), 0) == pdPASS + if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { return; } - if (xTimerChangePeriodFromISR(shortVibTimer, pdMS_TO_TICKS(motorDuration), NULL) == pdPASS + if (xTimerChangePeriodFromISR(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL) == pdPASS && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) { return; } @@ -36,8 +36,11 @@ void MotorController::RunForDuration(uint8_t motorDuration) { } void MotorController::StartRinging() { + if (xTimerChangePeriod(longVibTimer, APP_TIMER_TICKS(1000), 0) == pdPASS + && xTimerStart(longVibTimer, 0) == pdPASS) { + return; + } Ring(this); - xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 1988094..115aa27 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -24,7 +24,7 @@ void TimerController::Init() { void TimerController::StartTimer(uint32_t duration) { xTimerStop(timerAppTimer,0); auto currentTicks = xTaskGetTickCount(); - TickType_t durationTicks = pdMS_TO_TICKS(duration); + TickType_t durationTicks = APP_TIMER_TICKS(duration); xTimerChangePeriod(timerAppTimer, durationTicks, 0); xTimerStart(timerAppTimer, 0); endTicks = currentTicks + durationTicks; -- cgit v0.10.2 From c9808e29f1bbfbd1396d7b83212f6d223d52f99d Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sat, 16 Apr 2022 13:31:57 +0200 Subject: Run ScheduleAlarm from System task events only. diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index cea679f..a08bfbd 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -99,6 +99,12 @@ void AlarmController::SetOffAlarmNow() { void AlarmController::StopAlerting() { systemTask->PushMessage(System::Messages::StopRinging); +} + +void AlarmController::OnStopRinging() { + if (state != AlarmState::Alerting) { + return; + } // Alarm state is off unless this is a recurring alarm if (recurrence == RecurType::None) { diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h index fb33edb..3c66775 100644 --- a/src/components/alarm/AlarmController.h +++ b/src/components/alarm/AlarmController.h @@ -38,6 +38,7 @@ namespace Pinetime { void SetOffAlarmNow(); uint32_t SecondsToAlarm(); void StopAlerting(); + void OnStopRinging(); enum class AlarmState { Not_Set, Set, Alerting }; enum class RecurType { None, Daily, Weekdays }; uint8_t Hours() const { diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 38c728f..c7e0f38 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -319,6 +319,7 @@ void SystemTask::Work() { break; case Messages::StopRinging: motorController.StopRinging(); + alarmController.OnStopRinging(); break; case Messages::BleConnected: ReloadIdleTimer(); -- cgit v0.10.2