summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/displayapp/DisplayApp.cpp124
-rw-r--r--src/displayapp/DisplayApp.h8
-rw-r--r--src/displayapp/LittleVgl.cpp9
-rw-r--r--src/displayapp/LittleVgl.h2
-rw-r--r--src/displayapp/Messages.h3
-rw-r--r--src/displayapp/screens/FirmwareValidation.cpp4
-rw-r--r--src/displayapp/screens/List.cpp2
-rw-r--r--src/displayapp/screens/Metronome.cpp3
-rw-r--r--src/displayapp/screens/ScreenList.h2
-rw-r--r--src/displayapp/screens/StopWatch.cpp4
-rw-r--r--src/displayapp/screens/SystemInfo.cpp6
-rw-r--r--src/displayapp/screens/Tile.cpp10
-rw-r--r--src/displayapp/screens/Tile.h2
-rw-r--r--src/displayapp/screens/settings/QuickSettings.cpp6
-rw-r--r--src/displayapp/screens/settings/SettingDisplay.cpp4
-rw-r--r--src/drivers/Cst816s.cpp12
-rw-r--r--src/main.cpp11
-rw-r--r--src/systemtask/SystemTask.cpp1
-rw-r--r--src/touchhandler/TouchHandler.cpp70
-rw-r--r--src/touchhandler/TouchHandler.h45
21 files changed, 230 insertions, 102 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 40e1f2a5..cbc8cadc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -495,6 +495,8 @@ list(APPEND SOURCE_FILES
components/heartrate/Biquad.cpp
components/heartrate/Ptagc.cpp
components/heartrate/HeartRateController.cpp
+
+ touchhandler/TouchHandler.cpp
)
list(APPEND RECOVERY_SOURCE_FILES
@@ -552,6 +554,7 @@ list(APPEND RECOVERY_SOURCE_FILES
components/heartrate/Ptagc.cpp
components/motor/MotorController.cpp
components/fs/FS.cpp
+ touchhandler/TouchHandler.cpp
)
list(APPEND RECOVERYLOADER_SOURCE_FILES
@@ -660,6 +663,7 @@ set(INCLUDE_FILES
components/heartrate/Ptagc.h
components/heartrate/HeartRateController.h
components/motor/MotorController.h
+ touchhandler/TouchHandler.h
)
include_directories(
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 071af0c8..ca7e390f 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -66,7 +66,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController,
- Pinetime::Controllers::TimerController& timerController)
+ Pinetime::Controllers::TimerController& timerController,
+ Pinetime::Controllers::TouchHandler& touchHandler)
: lcd {lcd},
lvgl {lvgl},
touchPanel {touchPanel},
@@ -79,7 +80,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
settingsController {settingsController},
motorController {motorController},
motionController {motionController},
- timerController {timerController} {
+ timerController {timerController},
+ touchHandler {touchHandler} {
}
void DisplayApp::Start() {
@@ -176,33 +178,6 @@ void DisplayApp::Refresh() {
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
}
break;
- case Messages::TouchEvent: {
- if (state != States::Running)
- break;
- auto gesture = OnTouchEvent();
- if (!currentScreen->OnTouchEvent(gesture)) {
- if (currentApp == Apps::Clock) {
- switch (gesture) {
- case TouchEvents::SwipeUp:
- LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
- break;
- case TouchEvents::SwipeDown:
- LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
- break;
- case TouchEvents::SwipeRight:
- LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
- break;
- case TouchEvents::DoubleTap:
- PushMessageToSystemTask(System::Messages::GoToSleep);
- break;
- default:
- break;
- }
- } else if (returnTouchEvent == gesture) {
- LoadApp(returnToApp, returnDirection);
- }
- }
- } break;
case Messages::ButtonPushed:
if (currentApp == Apps::Clock) {
PushMessageToSystemTask(System::Messages::GoToSleep);
@@ -223,19 +198,42 @@ void DisplayApp::Refresh() {
}
}
- if(nextApp != Apps::None) {
- LoadApp(nextApp, nextDirection);
- nextApp = Apps::None;
- }
-
- if (state != States::Idle && touchMode == TouchModes::Polling) {
- auto info = touchPanel.GetTouchInfo();
- if (info.action == 2) { // 2 = contact
- if (!currentScreen->OnTouchEvent(info.x, info.y)) {
- lvgl.SetNewTapEvent(info.x, info.y);
+ auto gesture = GetGesture();
+ if (gesture != TouchEvents::None) {
+ if (!currentScreen->OnTouchEvent(gesture)) {
+ if (currentApp == Apps::Clock) {
+ switch (gesture) {
+ case TouchEvents::SwipeUp:
+ LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
+ break;
+ case TouchEvents::SwipeDown:
+ LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
+ break;
+ case TouchEvents::SwipeRight:
+ LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
+ break;
+ case TouchEvents::DoubleTap:
+ PushMessageToSystemTask(System::Messages::GoToSleep);
+ break;
+ default:
+ break;
+ }
+ } else if (returnTouchEvent == gesture) {
+ LoadApp(returnToApp, returnDirection);
}
+ } else {
+ touchHandler.CancelTap();
}
}
+
+ if (touchMode == TouchModes::Polling) {
+ currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
+ }
+
+ if (nextApp != Apps::None) {
+ LoadApp(nextApp, nextDirection);
+ nextApp = Apps::None;
+ }
}
void DisplayApp::RunningState() {
@@ -257,6 +255,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction
}
void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
+ touchHandler.CancelTap();
currentScreen.reset(nullptr);
SetFullRefresh(direction);
@@ -395,31 +394,28 @@ void DisplayApp::PushMessage(Messages msg) {
}
}
-TouchEvents DisplayApp::OnTouchEvent() {
- auto info = touchPanel.GetTouchInfo();
- if (info.isTouch) {
- switch (info.gesture) {
- case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
- if (touchMode == TouchModes::Gestures) {
- lvgl.SetNewTapEvent(info.x, info.y);
- }
- 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;
- }
+TouchEvents DisplayApp::GetGesture() {
+ auto gesture = touchHandler.GestureGet();
+ 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;
}
return TouchEvents::None;
}
diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h
index f4573ab7..74fc4456 100644
--- a/src/displayapp/DisplayApp.h
+++ b/src/displayapp/DisplayApp.h
@@ -14,6 +14,7 @@
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "components/timer/TimerController.h"
+#include "touchhandler/TouchHandler.h"
#include "Messages.h"
namespace Pinetime {
@@ -31,6 +32,7 @@ namespace Pinetime {
class NotificationManager;
class HeartRateController;
class MotionController;
+ class TouchHandler;
}
namespace System {
@@ -55,7 +57,8 @@ namespace Pinetime {
Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController,
- Pinetime::Controllers::TimerController& timerController);
+ Pinetime::Controllers::TimerController& timerController,
+ Pinetime::Controllers::TouchHandler& touchHandler);
void Start();
void PushMessage(Display::Messages msg);
@@ -81,6 +84,7 @@ namespace Pinetime {
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::MotionController& motionController;
Pinetime::Controllers::TimerController& timerController;
+ Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::FirmwareValidator validator;
Controllers::BrightnessController brightnessController;
@@ -102,7 +106,7 @@ namespace Pinetime {
TouchModes touchMode = TouchModes::Gestures;
- TouchEvents OnTouchEvent();
+ TouchEvents GetGesture();
void RunningState();
void IdleState();
static void Process(void* instance);
diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp
index c069afa2..d0c6161e 100644
--- a/src/displayapp/LittleVgl.cpp
+++ b/src/displayapp/LittleVgl.cpp
@@ -166,18 +166,17 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
lv_disp_flush_ready(&disp_drv);
}
-void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y) {
+void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y, bool contact) {
tap_x = x;
tap_y = y;
- tapped = true;
+ tapped = contact;
}
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
+ ptr->point.x = tap_x;
+ ptr->point.y = tap_y;
if (tapped) {
- ptr->point.x = tap_x;
- ptr->point.y = tap_y;
ptr->state = LV_INDEV_STATE_PR;
- tapped = false;
} else {
ptr->state = LV_INDEV_STATE_REL;
}
diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h
index 41f934a7..8d1ed56f 100644
--- a/src/displayapp/LittleVgl.h
+++ b/src/displayapp/LittleVgl.h
@@ -24,7 +24,7 @@ namespace Pinetime {
void FlushDisplay(const lv_area_t* area, lv_color_t* color_p);
bool GetTouchPadInfo(lv_indev_data_t* ptr);
void SetFullRefresh(FullRefreshDirections direction);
- void SetNewTapEvent(uint16_t x, uint16_t y);
+ void SetNewTapEvent(uint16_t x, uint16_t y, bool contact);
private:
void InitDisplay();
diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h
index ce65f846..3b8bad27 100644
--- a/src/displayapp/Messages.h
+++ b/src/displayapp/Messages.h
@@ -8,7 +8,6 @@ namespace Pinetime {
UpdateDateTime,
UpdateBleConnection,
UpdateBatteryLevel,
- TouchEvent,
ButtonPushed,
NewNotification,
TimerDone,
@@ -17,4 +16,4 @@ namespace Pinetime {
};
}
}
-} \ No newline at end of file
+}
diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp
index 1d05be8d..5bacb4e8 100644
--- a/src/displayapp/screens/FirmwareValidation.cpp
+++ b/src/displayapp/screens/FirmwareValidation.cpp
@@ -66,10 +66,10 @@ bool FirmwareValidation::Refresh() {
}
void FirmwareValidation::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
- if (object == buttonValidate && event == LV_EVENT_PRESSED) {
+ if (object == buttonValidate && event == LV_EVENT_CLICKED) {
validator.Validate();
running = false;
- } else if (object == buttonReset && event == LV_EVENT_PRESSED) {
+ } else if (object == buttonReset && event == LV_EVENT_CLICKED) {
validator.Reset();
}
}
diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp
index b4f4d2cf..1f92634a 100644
--- a/src/displayapp/screens/List.cpp
+++ b/src/displayapp/screens/List.cpp
@@ -108,7 +108,7 @@ bool List::Refresh() {
}
void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
- if (event == LV_EVENT_RELEASED) {
+ if (event == LV_EVENT_CLICKED) {
for (int i = 0; i < MAXLISTITEMS; i++) {
if (apps[i] != Apps::None && object == itemApps[i]) {
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up);
diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp
index 7bfbccb7..15916b62 100644
--- a/src/displayapp/screens/Metronome.cpp
+++ b/src/displayapp/screens/Metronome.cpp
@@ -83,12 +83,9 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
lv_obj_set_height(playPause, 39);
playPauseLabel = lv_label_create(playPause, nullptr);
lv_label_set_text(playPauseLabel, Symbols::play);
-
- app->SetTouchMode(DisplayApp::TouchModes::Polling);
}
Metronome::~Metronome() {
- app->SetTouchMode(DisplayApp::TouchModes::Gestures);
systemTask.PushMessage(System::Messages::EnableSleeping);
lv_obj_clean(lv_scr_act());
}
diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h
index ea66bfb2..50d66328 100644
--- a/src/displayapp/screens/ScreenList.h
+++ b/src/displayapp/screens/ScreenList.h
@@ -110,4 +110,4 @@ namespace Pinetime {
};
}
}
-} \ No newline at end of file
+}
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
index f4db5d6e..e3db6299 100644
--- a/src/displayapp/screens/StopWatch.cpp
+++ b/src/displayapp/screens/StopWatch.cpp
@@ -161,7 +161,7 @@ bool StopWatch::Refresh() {
}
void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
- if (event != LV_EVENT_PRESSED) {
+ if (event != LV_EVENT_CLICKED) {
return;
}
if (currentState == States::Init) {
@@ -174,7 +174,7 @@ void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
}
void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
- if (event != LV_EVENT_PRESSED) {
+ if (event != LV_EVENT_CLICKED) {
return;
}
// If running, then this button is used to save laps
diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp
index f5bf0cc9..47a49180 100644
--- a/src/displayapp/screens/SystemInfo.cpp
+++ b/src/displayapp/screens/SystemInfo.cpp
@@ -210,7 +210,7 @@ bool SystemInfo::sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
}
std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
- TaskStatus_t tasksStatus[7];
+ TaskStatus_t tasksStatus[10];
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL);
lv_table_set_col_cnt(infoTask, 3);
lv_table_set_row_cnt(infoTask, 8);
@@ -223,9 +223,9 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
lv_table_set_cell_value(infoTask, 0, 2, "Free");
lv_table_set_col_width(infoTask, 2, 90);
- auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr);
+ auto nb = uxTaskGetSystemState(tasksStatus, sizeof(tasksStatus) / sizeof(tasksStatus[0]), nullptr);
std::sort(tasksStatus, tasksStatus + nb, sortById);
- for (uint8_t i = 0; i < nb; i++) {
+ for (uint8_t i = 0; i < nb && i < 7; i++) {
lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName);
diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp
index 3eb127cc..5a40e915 100644
--- a/src/displayapp/screens/Tile.cpp
+++ b/src/displayapp/screens/Tile.cpp
@@ -12,9 +12,7 @@ namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
Tile* screen = static_cast<Tile*>(obj->user_data);
- uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data();
- uint32_t eventData = *eventDataPtr;
- screen->OnObjectEvent(obj, event, eventData);
+ screen->OnObjectEvent(obj, event);
}
}
@@ -124,9 +122,9 @@ bool Tile::Refresh() {
return running;
}
-void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) {
- if (event == LV_EVENT_VALUE_CHANGED) {
- app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
+void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event) {
+ if (event == LV_EVENT_CLICKED) {
+ app->StartApp(apps[lv_btnmatrix_get_active_btn(obj)], DisplayApp::FullRefreshDirections::Up);
running = false;
}
}
diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h
index 4ebd81cd..91ce9d01 100644
--- a/src/displayapp/screens/Tile.h
+++ b/src/displayapp/screens/Tile.h
@@ -32,7 +32,7 @@ namespace Pinetime {
bool Refresh() override;
void UpdateScreen();
- void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId);
+ void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
private:
Pinetime::Controllers::Battery& batteryController;
diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp
index acc2a27a..2da5ca27 100644
--- a/src/displayapp/screens/settings/QuickSettings.cpp
+++ b/src/displayapp/screens/settings/QuickSettings.cpp
@@ -125,12 +125,12 @@ void QuickSettings::UpdateScreen() {
}
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
- if (object == btn2 && event == LV_EVENT_PRESSED) {
+ if (object == btn2 && event == LV_EVENT_CLICKED) {
running = false;
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None);
- } else if (object == btn1 && event == LV_EVENT_PRESSED) {
+ } else if (object == btn1 && event == LV_EVENT_CLICKED) {
brightness.Step();
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
@@ -147,7 +147,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
}
- } else if (object == btn4 && event == LV_EVENT_PRESSED) {
+ } else if (object == btn4 && event == LV_EVENT_CLICKED) {
running = false;
settingsController.SetSettingsMenu(0);
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp
index 4954185d..aaf6a9f0 100644
--- a/src/displayapp/screens/settings/SettingDisplay.cpp
+++ b/src/displayapp/screens/settings/SettingDisplay.cpp
@@ -85,7 +85,7 @@ bool SettingDisplay::Refresh() {
}
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
- if (event == LV_EVENT_VALUE_CHANGED) {
+ if (event == LV_EVENT_CLICKED) {
for (int i = 0; i < optionsTotal; i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
@@ -110,4 +110,4 @@ void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index fd9792b3..adb984e0 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -40,6 +40,16 @@ void Cst816S::Init() {
*/
static constexpr uint8_t motionMask = 0b00000101;
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
+
+ /*
+ [7] EnTest - Interrupt pin to test, enable automatic periodic issued after a low pulse.
+ [6] EnTouch - When a touch is detected, a periodic pulsed Low.
+ [5] EnChange - Upon detecting a touch state changes, pulsed Low.
+ [4] EnMotion - When the detected gesture is pulsed Low.
+ [0] OnceWLP - Press gesture only issue a pulse signal is low.
+ */
+ static constexpr uint8_t irqCtl = 0b01110000;
+ twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
}
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
@@ -90,4 +100,4 @@ void Cst816S::Sleep() {
void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
-} \ No newline at end of file
+}
diff --git a/src/main.cpp b/src/main.cpp
index ffbba5e7..f427db40 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,6 +43,7 @@
#include "drivers/TwiMaster.h"
#include "drivers/Cst816s.h"
#include "systemtask/SystemTask.h"
+#include "touchhandler/TouchHandler.h"
#if NRF_LOG_ENABLED
#include "logging/NrfLogger.h"
@@ -118,6 +119,7 @@ Pinetime::Drivers::WatchdogView watchdogView(watchdog);
Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotionController motionController;
Pinetime::Controllers::TimerController timerController;
+Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
Pinetime::Controllers::FS fs {spiNorFlash};
Pinetime::Controllers::Settings settingsController {fs};
@@ -136,7 +138,8 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
settingsController,
motorController,
motionController,
- timerController);
+ timerController,
+ touchHandler);
Pinetime::System::SystemTask systemTask(spi,
lcd,
@@ -162,7 +165,7 @@ Pinetime::System::SystemTask systemTask(spi,
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) {
- systemTask.OnTouchEvent();
+ touchHandler.WakeUp();
return;
}
@@ -309,6 +312,10 @@ int main(void) {
lvgl.Init();
systemTask.Start();
+
+ touchHandler.Register(&systemTask);
+ touchHandler.Start();
+
nimble_port_init();
vTaskStartScheduler();
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index d8b965b1..f6aee785 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -397,7 +397,6 @@ void SystemTask::OnTouchEvent() {
return;
if (!isSleeping) {
PushMessage(Messages::OnTouchEvent);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
} else if (!isWakingUp) {
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp
new file mode 100644
index 00000000..a13d1af3
--- /dev/null
+++ b/src/touchhandler/TouchHandler.cpp
@@ -0,0 +1,70 @@
+#include "TouchHandler.h"
+
+using namespace Pinetime::Controllers;
+
+TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl)
+ : touchPanel {touchPanel},
+ lvgl {lvgl} {
+}
+
+void TouchHandler::CancelTap() {
+ isCancelled = true;
+ lvgl.SetNewTapEvent(-1, -1, false);
+}
+
+Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
+ auto returnGesture = gesture;
+ gesture = Drivers::Cst816S::Gestures::None;
+ return returnGesture;
+}
+
+void TouchHandler::Start() {
+ if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 80, this, 0, &taskHandle)) {
+ APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
+ }
+}
+
+void TouchHandler::Process(void* instance) {
+ auto* app = static_cast<TouchHandler*>(instance);
+ app->Work();
+}
+
+void TouchHandler::Work() {
+ Pinetime::Drivers::Cst816S::TouchInfos info;
+ while (true) {
+ vTaskSuspend(taskHandle);
+ info = touchPanel.GetTouchInfo();
+ if (systemTask->IsSleeping()) {
+ systemTask->PushMessage(System::Messages::TouchWakeUp);
+ } else {
+ x = info.x;
+ y = info.y;
+ if (info.action == 0) {
+ lvgl.SetNewTapEvent(info.x, info.y, true);
+ } else if (info.action == 1) {
+ lvgl.SetNewTapEvent(info.x, info.y, false);
+ prevGesture = Pinetime::Drivers::Cst816S::Gestures::None;
+ isCancelled = false;
+ } else if (info.action == 2) {
+ if (!isCancelled) {
+ lvgl.SetNewTapEvent(info.x, info.y, true);
+ }
+ if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
+ if (prevGesture != info.gesture) {
+ prevGesture = info.gesture;
+ gesture = info.gesture;
+ }
+ }
+ }
+ systemTask->OnTouchEvent();
+ }
+ }
+}
+
+void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
+ this->systemTask = systemTask;
+}
+
+void TouchHandler::WakeUp() {
+ vTaskResume(taskHandle);
+}
diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h
new file mode 100644
index 00000000..7999e00a
--- /dev/null
+++ b/src/touchhandler/TouchHandler.h
@@ -0,0 +1,45 @@
+#pragma once
+#include "drivers/Cst816s.h"
+#include "systemtask/SystemTask.h"
+#include <FreeRTOS.h>
+#include <task.h>
+
+namespace Pinetime {
+ namespace Components {
+ class LittleVgl;
+ }
+ namespace Drivers {
+ class Cst816S;
+ }
+ namespace System {
+ class SystemTask;
+ }
+ namespace Controllers {
+ class TouchHandler {
+ public:
+ explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
+ void CancelTap();
+ void Register(Pinetime::System::SystemTask* systemTask);
+ void Start();
+ void WakeUp();
+ uint8_t GetX() const {
+ return x;
+ }
+ uint8_t GetY() const {
+ return y;
+ }
+ Drivers::Cst816S::Gestures GestureGet();
+ private:
+ static void Process(void* instance);
+ void Work();
+ Pinetime::System::SystemTask* systemTask = nullptr;
+ TaskHandle_t taskHandle;
+ Pinetime::Drivers::Cst816S& touchPanel;
+ Pinetime::Components::LittleVgl& lvgl;
+ Pinetime::Drivers::Cst816S::Gestures gesture;
+ Pinetime::Drivers::Cst816S::Gestures prevGesture;
+ bool isCancelled = false;
+ uint8_t x, y;
+ };
+ }
+}