From 1516b082fd75a1c68d98862199bd349175d37a8f Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 23 Feb 2023 13:35:29 +0200 Subject: [PATCH] TouchHandler: Do not store touch panel reference --- src/displayapp/LittleVgl.h | 2 +- src/main.cpp | 2 +- src/systemtask/SystemTask.cpp | 4 ++-- src/touchhandler/TouchHandler.cpp | 9 +++------ src/touchhandler/TouchHandler.h | 22 ++++++++++------------ 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h index e36d1545..38f1f00e 100644 --- a/src/displayapp/LittleVgl.h +++ b/src/displayapp/LittleVgl.h @@ -59,7 +59,7 @@ namespace Pinetime { uint16_t writeOffset = 0; uint16_t scrollOffset = 0; - lv_point_t touchPoint = {0}; + lv_point_t touchPoint = {}; bool tapped = false; bool isCancelled = false; }; diff --git a/src/main.cpp b/src/main.cpp index 4204842d..0053c5e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,7 +111,7 @@ Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::TimerController timerController; Pinetime::Controllers::AlarmController alarmController {dateTimeController}; -Pinetime::Controllers::TouchHandler touchHandler(touchPanel); +Pinetime::Controllers::TouchHandler touchHandler; Pinetime::Controllers::ButtonHandler buttonHandler; Pinetime::Controllers::BrightnessController brightnessController {}; diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 38bba1a5..2f29dc7a 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -250,7 +250,7 @@ void SystemTask::Work() { isDimmed = false; break; case Messages::TouchWakeUp: { - if (touchHandler.GetNewTouchInfo()) { + if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) { auto gesture = touchHandler.GestureGet(); if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep && gesture != Pinetime::Applications::TouchEvents::None && @@ -342,7 +342,7 @@ void SystemTask::Work() { // TODO add intent of fs access icon or something break; case Messages::OnTouchEvent: - if (touchHandler.GetNewTouchInfo()) { + if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) { ReloadIdleTimer(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); } diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index d98d2577..b29f951f 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -27,18 +27,13 @@ namespace { } } -TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel) : touchPanel {touchPanel} { -} - Pinetime::Applications::TouchEvents TouchHandler::GestureGet() { auto returnGesture = gesture; gesture = Pinetime::Applications::TouchEvents::None; return returnGesture; } -bool TouchHandler::GetNewTouchInfo() { - info = touchPanel.GetTouchInfo(); - +bool TouchHandler::ProcessTouchInfo(Drivers::Cst816S::TouchInfos info) { if (!info.isValid) { return false; } @@ -65,5 +60,7 @@ bool TouchHandler::GetNewTouchInfo() { gestureReleased = true; } + currentTouchPoint = {info.x, info.y, info.touching}; + return true; } diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h index 9afaa247..a4482255 100644 --- a/src/touchhandler/TouchHandler.h +++ b/src/touchhandler/TouchHandler.h @@ -3,36 +3,34 @@ #include "displayapp/TouchEvents.h" namespace Pinetime { - namespace Drivers { - class Cst816S; - } - namespace Controllers { class TouchHandler { public: - explicit TouchHandler(Drivers::Cst816S&); + struct TouchPoint { + int x; + int y; + bool touching; + }; - bool GetNewTouchInfo(); + bool ProcessTouchInfo(Drivers::Cst816S::TouchInfos info); bool IsTouching() const { - return info.touching; + return currentTouchPoint.touching; } uint8_t GetX() const { - return info.x; + return currentTouchPoint.x; } uint8_t GetY() const { - return info.y; + return currentTouchPoint.y; } Pinetime::Applications::TouchEvents GestureGet(); private: - Pinetime::Drivers::Cst816S::TouchInfos info; - Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Applications::TouchEvents gesture; - bool isCancelled = false; + TouchPoint currentTouchPoint = {}; bool gestureReleased = true; }; }