summaryrefslogtreecommitdiff
path: root/src/touchhandler
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-08-10 19:03:34 (GMT)
committerRiku Isokoski <riksu9000@gmail.com>2021-08-10 19:03:34 (GMT)
commit8a694adb0979339664da0af6d51c480d26c5527b (patch)
tree89c0deb381b34d3060edfcee249a9e5177244e67 /src/touchhandler
parent7e92577c14895f57f5adda27ad54adbbc4b7ffe9 (diff)
Rework TouchHandler into not a task
Diffstat (limited to 'src/touchhandler')
-rw-r--r--src/touchhandler/TouchHandler.cpp80
-rw-r--r--src/touchhandler/TouchHandler.h9
2 files changed, 36 insertions, 53 deletions
diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp
index 187aa69..c1a3c0d 100644
--- a/src/touchhandler/TouchHandler.cpp
+++ b/src/touchhandler/TouchHandler.cpp
@@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
return returnGesture;
}
-void TouchHandler::Start() {
- if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, 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() {
- bool slideReleased = true;
- while (true) {
- vTaskSuspend(taskHandle);
+bool TouchHandler::GetNewTouchInfo() {
+ info = touchPanel.GetTouchInfo();
- info = touchPanel.GetTouchInfo();
-
- if (info.isValid) {
- if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
- if (slideReleased) {
- if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
- slideReleased = false;
- }
- gesture = info.gesture;
- }
- }
+ if (!info.isValid) {
+ return false;
+ }
- if (!systemTask->IsSleeping()) {
+ if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
+ if (slideReleased) {
+ if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
if (info.touching) {
- if (!isCancelled) {
- lvgl.SetNewTouchPoint(info.x, info.y, true);
- }
- } else {
- if (isCancelled) {
- lvgl.SetNewTouchPoint(-1, -1, false);
- isCancelled = false;
- } else {
- lvgl.SetNewTouchPoint(info.x, info.y, false);
- }
- slideReleased = true;
+ gesture = info.gesture;
+ slideReleased = false;
}
+ } else {
+ gesture = info.gesture;
}
- systemTask->OnTouchEvent();
}
}
-}
-void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
- this->systemTask = systemTask;
+ if (!info.touching) {
+ slideReleased = true;
+ }
+
+ return true;
}
-void TouchHandler::WakeUp() {
- vTaskResume(taskHandle);
+void TouchHandler::UpdateLvglTouchPoint() {
+ if (info.touching) {
+ if (!isCancelled) {
+ lvgl.SetNewTouchPoint(info.x, info.y, true);
+ }
+ } else {
+ if (isCancelled) {
+ lvgl.SetNewTouchPoint(-1, -1, false);
+ isCancelled = false;
+ } else {
+ lvgl.SetNewTouchPoint(info.x, info.y, false);
+ }
+ }
}
diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h
index 6b8189f..38cb36c 100644
--- a/src/touchhandler/TouchHandler.h
+++ b/src/touchhandler/TouchHandler.h
@@ -19,9 +19,9 @@ namespace Pinetime {
public:
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
void CancelTap();
+ bool GetNewTouchInfo();
+ void UpdateLvglTouchPoint();
void Register(Pinetime::System::SystemTask* systemTask);
- void Start();
- void WakeUp();
bool IsTouching() const {
return info.touching;
@@ -34,16 +34,13 @@ namespace Pinetime {
}
Drivers::Cst816S::Gestures GestureGet();
private:
- static void Process(void* instance);
- void Work();
Pinetime::Drivers::Cst816S::TouchInfos info;
- Pinetime::System::SystemTask* systemTask = nullptr;
- TaskHandle_t taskHandle;
Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Drivers::Cst816S::Gestures gesture;
bool isCancelled = false;
+ bool slideReleased = true;
};
}
}