2021-10-13 22:08:35 +02:00
|
|
|
#include "touchhandler/TouchHandler.h"
|
2021-07-15 14:11:27 +03:00
|
|
|
|
|
|
|
using namespace Pinetime::Controllers;
|
2022-01-16 23:37:15 +01:00
|
|
|
using namespace Pinetime::Applications;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 14:11:27 +03:00
|
|
|
|
2022-01-16 23:37:15 +01:00
|
|
|
Pinetime::Applications::TouchEvents TouchHandler::GestureGet() {
|
2021-07-15 14:11:27 +03:00
|
|
|
auto returnGesture = gesture;
|
2022-01-16 23:37:15 +01:00
|
|
|
gesture = Pinetime::Applications::TouchEvents::None;
|
2021-07-15 14:11:27 +03:00
|
|
|
return returnGesture;
|
|
|
|
}
|
|
|
|
|
2023-02-23 13:35:29 +02:00
|
|
|
bool TouchHandler::ProcessTouchInfo(Drivers::Cst816S::TouchInfos info) {
|
2021-08-10 22:03:34 +03:00
|
|
|
if (!info.isValid) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-07-16 02:17:17 +03:00
|
|
|
|
2023-02-23 13:28:04 +02:00
|
|
|
// Only a single gesture per touch
|
2021-08-10 22:03:34 +03:00
|
|
|
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
|
2021-08-11 18:31:40 +03:00
|
|
|
if (gestureReleased) {
|
2021-08-10 22:03:34 +03:00
|
|
|
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
|
|
|
|
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
|
|
|
|
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
|
2021-08-11 18:31:40 +03:00
|
|
|
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight ||
|
|
|
|
info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) {
|
2021-07-18 12:32:46 +03:00
|
|
|
if (info.touching) {
|
2022-01-16 23:37:15 +01:00
|
|
|
gesture = ConvertGesture(info.gesture);
|
2021-08-11 18:31:40 +03:00
|
|
|
gestureReleased = false;
|
2021-07-16 00:07:55 +03:00
|
|
|
}
|
2021-08-10 22:03:34 +03:00
|
|
|
} else {
|
2022-01-16 23:37:15 +01:00
|
|
|
gesture = ConvertGesture(info.gesture);
|
2021-07-15 14:11:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 22:03:34 +03:00
|
|
|
if (!info.touching) {
|
2021-08-11 18:31:40 +03:00
|
|
|
gestureReleased = true;
|
2021-08-10 22:03:34 +03:00
|
|
|
}
|
|
|
|
|
2023-02-23 13:35:29 +02:00
|
|
|
currentTouchPoint = {info.x, info.y, info.touching};
|
|
|
|
|
2021-08-10 22:03:34 +03:00
|
|
|
return true;
|
2021-07-15 14:11:27 +03:00
|
|
|
}
|