summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-04-16 11:43:58 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-04-16 12:12:52 (GMT)
commit2e367ec0aea857a1aee7306a2de893f96a60f2df (patch)
tree86439281fb0ed810b83161cb36985f2a731b22bc
parentebf3859407adba9da7acbc77b1ebabfd39d80a37 (diff)
parentc9808e29f1bbfbd1396d7b83212f6d223d52f99d (diff)
Merge branch 'alarm-fix-work' into edge
# Conflicts: # src/components/timer/TimerController.cpp
-rw-r--r--src/components/alarm/AlarmController.cpp30
-rw-r--r--src/components/alarm/AlarmController.h4
-rw-r--r--src/components/motor/MotorController.cpp28
-rw-r--r--src/components/motor/MotorController.h8
-rw-r--r--src/components/timer/TimerController.cpp22
-rw-r--r--src/components/timer/TimerController.h3
-rw-r--r--src/displayapp/DisplayApp.cpp24
-rw-r--r--src/systemtask/SystemTask.cpp8
-rw-r--r--src/touchhandler/TouchHandler.cpp38
-rw-r--r--src/touchhandler/TouchHandler.h6
10 files changed, 102 insertions, 69 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index 3330ed7..6e93f6d 100644
--- a/src/components/alarm/AlarmController.cpp
+++ b/src/components/alarm/AlarmController.cpp
@@ -27,19 +27,15 @@ using namespace std::chrono_literals;
AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
}
-APP_TIMER_DEF(alarmAppTimer);
-
namespace {
- void SetOffAlarm(void* p_context) {
- auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(p_context);
- if (controller != nullptr) {
- controller->SetOffAlarmNow();
- }
+ void SetOffAlarm(TimerHandle_t xTimer) {
+ auto controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer));
+ controller->SetOffAlarmNow();
}
}
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;
}
@@ -52,20 +48,21 @@ void AlarmController::RescheduleAlarm() {
if (state != AlarmState::Set) { return; }
- app_timer_stop(alarmAppTimer);
+ xTimerStop(alarmAppTimer, 0);
auto now = dateTimeController.CurrentDateTime();
alarmTime = now;
auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
if (mSecToAlarm < 0) { mSecToAlarm = 0; }
- app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
+ xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
+ xTimerStart(alarmAppTimer, 0);
}
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;
@@ -96,7 +93,8 @@ 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<std::chrono::milliseconds>(alarmTime - now).count();
- app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
+ xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
+ xTimerStart(alarmAppTimer, 0);
state = AlarmState::Set;
}
@@ -106,7 +104,7 @@ uint32_t AlarmController::SecondsToAlarm() {
}
void AlarmController::DisableAlarm() {
- app_timer_stop(alarmAppTimer);
+ xTimerStop(alarmAppTimer, 0);
state = AlarmState::Not_Set;
}
@@ -117,6 +115,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 fca4287..df65c63 100644
--- a/src/components/alarm/AlarmController.h
+++ b/src/components/alarm/AlarmController.h
@@ -17,6 +17,8 @@
*/
#pragma once
+#include <FreeRTOS.h>
+#include <timers.h>
#include <cstdint>
#include "components/datetime/DateTimeController.h"
@@ -37,6 +39,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 {
@@ -58,6 +61,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<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index c794a02..5ff549e 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -12,32 +12,42 @@ 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", APP_TIMER_TICKS(1000), pdTRUE, this, Ring);
}
-void MotorController::Ring(void* p_context) {
- auto* motorController = static_cast<MotorController*>(p_context);
+void MotorController::Ring(TimerHandle_t xTimer) {
+ auto motorController = static_cast<MotorController*>(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, APP_TIMER_TICKS(motorDuration), 0) == pdPASS
+ && xTimerStart(shortVibTimer, 0) == pdPASS) {
+ return;
+ }
+ if (xTimerChangePeriodFromISR(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL) == pdPASS
+ && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) {
+ return;
+ }
+ nrf_gpio_pin_set(PinMap::Motor);
}
void MotorController::StartRinging() {
+ if (xTimerChangePeriod(longVibTimer, APP_TIMER_TICKS(1000), 0) == pdPASS
+ && xTimerStart(longVibTimer, 0) == pdPASS) {
+ return;
+ }
Ring(this);
- app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
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 <FreeRTOS.h>
+#include <timers.h>
#include <cstdint>
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;
};
}
}
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp
index d6f8ffd..35e3512 100644
--- a/src/components/timer/TimerController.cpp
+++ b/src/components/timer/TimerController.cpp
@@ -4,30 +4,28 @@
#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<Pinetime::Controllers::TimerController*>(p_context);
- if (controller != nullptr)
- controller->OnTimerEnd();
+ void TimerEnd(TimerHandle_t xTimer) {
+ auto controller = static_cast<Pinetime::Controllers::TimerController*>(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 = APP_TIMER_TICKS(duration);
+ xTimerChangePeriod(timerAppTimer, durationTicks, 0);
+ xTimerStart(timerAppTimer, 0);
+ endTicks = currentTicks + durationTicks;
timerRunning = true;
overtime = false;
}
@@ -44,7 +42,7 @@ int32_t TimerController::GetSecondsRemaining() {
}
void TimerController::StopTimer() {
- app_timer_stop(timerAppTimer);
+ xTimerStop(timerAppTimer, 0);
timerRunning = false;
overtime = false;
}
diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h
index dbc9863..8542987 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/TimerController.h
@@ -1,5 +1,7 @@
#pragma once
+#include <FreeRTOS.h>
+#include <timers.h>
#include <cstdint>
#include "app_timer.h"
#include "portmacro_cmsis.h"
@@ -32,6 +34,7 @@ namespace Pinetime {
private:
System::SystemTask* systemTask = nullptr;
+ TimerHandle_t timerAppTimer;
TickType_t endTicks;
bool timerRunning = false;
bool overtime = false;
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 9c0af35..fc3519f 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -61,28 +61,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,
@@ -228,7 +206,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 4daddf8..c1fd3c1 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"
@@ -271,10 +272,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();
}
@@ -322,6 +323,7 @@ void SystemTask::Work() {
break;
case Messages::StopRinging:
motorController.StopRinging();
+ alarmController.OnStopRinging();
break;
case Messages::BleConnected:
ReloadIdleTimer();
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;
};