TouchHandler: Do not store touch panel reference

This commit is contained in:
Riku Isokoski 2023-02-23 13:35:29 +02:00
parent 7066ff5aba
commit 1516b082fd
5 changed files with 17 additions and 22 deletions

View File

@ -59,7 +59,7 @@ namespace Pinetime {
uint16_t writeOffset = 0; uint16_t writeOffset = 0;
uint16_t scrollOffset = 0; uint16_t scrollOffset = 0;
lv_point_t touchPoint = {0}; lv_point_t touchPoint = {};
bool tapped = false; bool tapped = false;
bool isCancelled = false; bool isCancelled = false;
}; };

View File

@ -111,7 +111,7 @@ Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::MotionController motionController;
Pinetime::Controllers::TimerController timerController; Pinetime::Controllers::TimerController timerController;
Pinetime::Controllers::AlarmController alarmController {dateTimeController}; Pinetime::Controllers::AlarmController alarmController {dateTimeController};
Pinetime::Controllers::TouchHandler touchHandler(touchPanel); Pinetime::Controllers::TouchHandler touchHandler;
Pinetime::Controllers::ButtonHandler buttonHandler; Pinetime::Controllers::ButtonHandler buttonHandler;
Pinetime::Controllers::BrightnessController brightnessController {}; Pinetime::Controllers::BrightnessController brightnessController {};

View File

@ -250,7 +250,7 @@ void SystemTask::Work() {
isDimmed = false; isDimmed = false;
break; break;
case Messages::TouchWakeUp: { case Messages::TouchWakeUp: {
if (touchHandler.GetNewTouchInfo()) { if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
auto gesture = touchHandler.GestureGet(); auto gesture = touchHandler.GestureGet();
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep && if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep &&
gesture != Pinetime::Applications::TouchEvents::None && gesture != Pinetime::Applications::TouchEvents::None &&
@ -342,7 +342,7 @@ void SystemTask::Work() {
// TODO add intent of fs access icon or something // TODO add intent of fs access icon or something
break; break;
case Messages::OnTouchEvent: case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) { if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
ReloadIdleTimer(); ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
} }

View File

@ -27,18 +27,13 @@ namespace {
} }
} }
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel) : touchPanel {touchPanel} {
}
Pinetime::Applications::TouchEvents TouchHandler::GestureGet() { Pinetime::Applications::TouchEvents TouchHandler::GestureGet() {
auto returnGesture = gesture; auto returnGesture = gesture;
gesture = Pinetime::Applications::TouchEvents::None; gesture = Pinetime::Applications::TouchEvents::None;
return returnGesture; return returnGesture;
} }
bool TouchHandler::GetNewTouchInfo() { bool TouchHandler::ProcessTouchInfo(Drivers::Cst816S::TouchInfos info) {
info = touchPanel.GetTouchInfo();
if (!info.isValid) { if (!info.isValid) {
return false; return false;
} }
@ -65,5 +60,7 @@ bool TouchHandler::GetNewTouchInfo() {
gestureReleased = true; gestureReleased = true;
} }
currentTouchPoint = {info.x, info.y, info.touching};
return true; return true;
} }

View File

@ -3,36 +3,34 @@
#include "displayapp/TouchEvents.h" #include "displayapp/TouchEvents.h"
namespace Pinetime { namespace Pinetime {
namespace Drivers {
class Cst816S;
}
namespace Controllers { namespace Controllers {
class TouchHandler { class TouchHandler {
public: public:
explicit TouchHandler(Drivers::Cst816S&); struct TouchPoint {
int x;
int y;
bool touching;
};
bool GetNewTouchInfo(); bool ProcessTouchInfo(Drivers::Cst816S::TouchInfos info);
bool IsTouching() const { bool IsTouching() const {
return info.touching; return currentTouchPoint.touching;
} }
uint8_t GetX() const { uint8_t GetX() const {
return info.x; return currentTouchPoint.x;
} }
uint8_t GetY() const { uint8_t GetY() const {
return info.y; return currentTouchPoint.y;
} }
Pinetime::Applications::TouchEvents GestureGet(); Pinetime::Applications::TouchEvents GestureGet();
private: private:
Pinetime::Drivers::Cst816S::TouchInfos info;
Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Applications::TouchEvents gesture; Pinetime::Applications::TouchEvents gesture;
bool isCancelled = false; TouchPoint currentTouchPoint = {};
bool gestureReleased = true; bool gestureReleased = true;
}; };
} }