summaryrefslogtreecommitdiff
path: root/src/systemtask
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemtask')
-rw-r--r--src/systemtask/Messages.h3
-rw-r--r--src/systemtask/SystemTask.cpp86
-rw-r--r--src/systemtask/SystemTask.h15
3 files changed, 80 insertions, 24 deletions
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h
index 5aa218d2..b7142704 100644
--- a/src/systemtask/Messages.h
+++ b/src/systemtask/Messages.h
@@ -15,7 +15,8 @@ namespace Pinetime {
BleFirmwareUpdateStarted,
BleFirmwareUpdateFinished,
OnTouchEvent,
- OnButtonEvent,
+ HandleButtonEvent,
+ HandleButtonTimerEvent,
OnDisplayTaskSleeping,
EnableSleeping,
DisableSleeping,
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index e0a5907a..1120b80d 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -1,4 +1,4 @@
-#include "SystemTask.h"
+#include "systemtask/SystemTask.h"
#define min // workaround: nimble's min/max macros conflict with libstdc++
#define max
#include <host/ble_gap.h>
@@ -25,7 +25,6 @@
#include "main.h"
#include "BootErrors.h"
-
#include <memory>
using namespace Pinetime::System;
@@ -77,7 +76,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
Pinetime::Controllers::FS& fs,
- Pinetime::Controllers::TouchHandler& touchHandler)
+ Pinetime::Controllers::TouchHandler& touchHandler,
+ Pinetime::Controllers::ButtonHandler& buttonHandler)
: spi {spi},
lcd {lcd},
spiNorFlash {spiNorFlash},
@@ -101,8 +101,15 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
heartRateApp(heartRateApp),
fs {fs},
touchHandler {touchHandler},
- nimbleController(*this, bleController, dateTimeController, notificationManager,
- batteryController, spiNorFlash, heartRateController, motionController) {
+ buttonHandler {buttonHandler},
+ nimbleController(*this,
+ bleController,
+ dateTimeController,
+ notificationManager,
+ batteryController,
+ spiNorFlash,
+ heartRateController,
+ motionController) {
}
void SystemTask::Start() {
@@ -137,9 +144,15 @@ void SystemTask::Work() {
lcd.Init();
twiMaster.Init();
+ /*
+ * TODO We disable this warning message until we ensure it won't be displayed
+ * on legitimate PineTime equipped with a compatible touch controller.
+ * (some users reported false positive). See https://github.com/InfiniTimeOrg/InfiniTime/issues/763
if (!touchPanel.Init()) {
bootError = BootErrors::TouchController;
}
+ */
+ touchPanel.Init();
dateTimeController.Register(this);
batteryController.Register(this);
motorController.Init();
@@ -163,6 +176,8 @@ void SystemTask::Work() {
heartRateSensor.Disable();
heartRateApp.Start();
+ buttonHandler.Init(this);
+
// Button
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
@@ -326,10 +341,25 @@ void SystemTask::Work() {
ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
- case Messages::OnButtonEvent:
- ReloadIdleTimer();
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
- break;
+ case Messages::HandleButtonEvent: {
+ Controllers::ButtonActions action;
+ if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
+ action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
+ } else {
+ action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
+ // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
+ if (IsSleeping()) {
+ fastWakeUpDone = true;
+ GoToRunning();
+ break;
+ }
+ }
+ HandleButtonAction(action);
+ } break;
+ case Messages::HandleButtonTimerEvent: {
+ auto action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Timer);
+ HandleButtonAction(action);
+ } break;
case Messages::OnDisplayTaskSleeping:
if (BootloaderVersion::IsValid()) {
// First versions of the bootloader do not expose their version and cannot initialize the SPI NOR FLASH
@@ -414,18 +444,36 @@ void SystemTask::UpdateMotion() {
}
}
-void SystemTask::OnButtonPushed() {
- if (isGoingToSleep)
+void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
+ if (IsSleeping()) {
return;
- if (!isSleeping) {
- NRF_LOG_INFO("[systemtask] Button pushed");
- PushMessage(Messages::OnButtonEvent);
- } else {
- if (!isWakingUp) {
- NRF_LOG_INFO("[systemtask] Button pushed, waking up");
- GoToRunning();
- }
}
+
+ ReloadIdleTimer();
+
+ using Actions = Controllers::ButtonActions;
+
+ switch (action) {
+ case Actions::Click:
+ // If the first action after fast wakeup is a click, it should be ignored.
+ if (!fastWakeUpDone && !isGoingToSleep) {
+ displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
+ }
+ break;
+ case Actions::DoubleClick:
+ displayApp.PushMessage(Applications::Display::Messages::ButtonDoubleClicked);
+ break;
+ case Actions::LongPress:
+ displayApp.PushMessage(Applications::Display::Messages::ButtonLongPressed);
+ break;
+ case Actions::LongerPress:
+ displayApp.PushMessage(Applications::Display::Messages::ButtonLongerPressed);
+ break;
+ default:
+ return;
+ }
+
+ fastWakeUpDone = false;
}
void SystemTask::GoToRunning() {
diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h
index 879c1be8..e2e6de7f 100644
--- a/src/systemtask/SystemTask.h
+++ b/src/systemtask/SystemTask.h
@@ -11,7 +11,7 @@
#include <drivers/PinMap.h>
#include <components/motion/MotionController.h>
-#include "SystemMonitor.h"
+#include "systemtask/SystemMonitor.h"
#include "components/battery/BatteryController.h"
#include "components/ble/NimbleController.h"
#include "components/ble/NotificationManager.h"
@@ -20,6 +20,8 @@
#include "components/alarm/AlarmController.h"
#include "components/fs/FS.h"
#include "touchhandler/TouchHandler.h"
+#include "buttonhandler/ButtonHandler.h"
+#include "buttonhandler/ButtonActions.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h"
@@ -31,7 +33,7 @@
#endif
#include "drivers/Watchdog.h"
-#include "Messages.h"
+#include "systemtask/Messages.h"
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
namespace Pinetime {
@@ -45,6 +47,7 @@ namespace Pinetime {
}
namespace Controllers {
class TouchHandler;
+ class ButtonHandler;
}
namespace System {
class SystemTask {
@@ -71,12 +74,12 @@ namespace Pinetime {
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
Pinetime::Controllers::FS& fs,
- Pinetime::Controllers::TouchHandler& touchHandler);
+ Pinetime::Controllers::TouchHandler& touchHandler,
+ Pinetime::Controllers::ButtonHandler& buttonHandler);
void Start();
void PushMessage(Messages msg);
- void OnButtonPushed();
void OnTouchEvent();
void OnIdle();
@@ -123,6 +126,7 @@ namespace Pinetime {
Pinetime::Applications::HeartRateTask& heartRateApp;
Pinetime::Controllers::FS& fs;
Pinetime::Controllers::TouchHandler& touchHandler;
+ Pinetime::Controllers::ButtonHandler& buttonHandler;
Pinetime::Controllers::NimbleController nimbleController;
static void Process(void* instance);
@@ -135,6 +139,9 @@ namespace Pinetime {
TimerHandle_t measureBatteryTimer;
bool doNotGoToSleep = false;
+ void HandleButtonAction(Controllers::ButtonActions action);
+ bool fastWakeUpDone = false;
+
void GoToRunning();
void UpdateMotion();
bool stepCounterMustBeReset = false;