Skip to content

Commit 969de9a

Browse files
authored
Merge pull request #492 from Riksu9000/new_touch_handler
New touch handler
2 parents df8ea7f + 85c9979 commit 969de9a

24 files changed

Lines changed: 239 additions & 151 deletions

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ list(APPEND SOURCE_FILES
495495
components/heartrate/Biquad.cpp
496496
components/heartrate/Ptagc.cpp
497497
components/heartrate/HeartRateController.cpp
498+
499+
touchhandler/TouchHandler.cpp
498500
)
499501

500502
list(APPEND RECOVERY_SOURCE_FILES
@@ -552,6 +554,7 @@ list(APPEND RECOVERY_SOURCE_FILES
552554
components/heartrate/Ptagc.cpp
553555
components/motor/MotorController.cpp
554556
components/fs/FS.cpp
557+
touchhandler/TouchHandler.cpp
555558
)
556559

557560
list(APPEND RECOVERYLOADER_SOURCE_FILES
@@ -660,6 +663,7 @@ set(INCLUDE_FILES
660663
components/heartrate/Ptagc.h
661664
components/heartrate/HeartRateController.h
662665
components/motor/MotorController.h
666+
touchhandler/TouchHandler.h
663667
)
664668

665669
include_directories(

src/displayapp/DisplayApp.cpp

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,26 @@ namespace {
5353
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
5454
}
5555

56-
TouchEvents Convert(Pinetime::Drivers::Cst816S::TouchInfos info) {
57-
if (info.isTouch) {
58-
switch (info.gesture) {
59-
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
60-
return TouchEvents::Tap;
61-
case Pinetime::Drivers::Cst816S::Gestures::LongPress:
62-
return TouchEvents::LongTap;
63-
case Pinetime::Drivers::Cst816S::Gestures::DoubleTap:
64-
return TouchEvents::DoubleTap;
65-
case Pinetime::Drivers::Cst816S::Gestures::SlideRight:
66-
return TouchEvents::SwipeRight;
67-
case Pinetime::Drivers::Cst816S::Gestures::SlideLeft:
68-
return TouchEvents::SwipeLeft;
69-
case Pinetime::Drivers::Cst816S::Gestures::SlideDown:
70-
return TouchEvents::SwipeDown;
71-
case Pinetime::Drivers::Cst816S::Gestures::SlideUp:
72-
return TouchEvents::SwipeUp;
73-
case Pinetime::Drivers::Cst816S::Gestures::None:
74-
default:
75-
return TouchEvents::None;
76-
}
56+
TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) {
57+
switch (gesture) {
58+
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
59+
return TouchEvents::Tap;
60+
case Pinetime::Drivers::Cst816S::Gestures::LongPress:
61+
return TouchEvents::LongTap;
62+
case Pinetime::Drivers::Cst816S::Gestures::DoubleTap:
63+
return TouchEvents::DoubleTap;
64+
case Pinetime::Drivers::Cst816S::Gestures::SlideRight:
65+
return TouchEvents::SwipeRight;
66+
case Pinetime::Drivers::Cst816S::Gestures::SlideLeft:
67+
return TouchEvents::SwipeLeft;
68+
case Pinetime::Drivers::Cst816S::Gestures::SlideDown:
69+
return TouchEvents::SwipeDown;
70+
case Pinetime::Drivers::Cst816S::Gestures::SlideUp:
71+
return TouchEvents::SwipeUp;
72+
case Pinetime::Drivers::Cst816S::Gestures::None:
73+
default:
74+
return TouchEvents::None;
7775
}
78-
return TouchEvents::None;
7976
}
8077
}
8178

@@ -91,7 +88,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
9188
Controllers::Settings& settingsController,
9289
Pinetime::Controllers::MotorController& motorController,
9390
Pinetime::Controllers::MotionController& motionController,
94-
Pinetime::Controllers::TimerController& timerController)
91+
Pinetime::Controllers::TimerController& timerController,
92+
Pinetime::Controllers::TouchHandler& touchHandler)
9593
: lcd {lcd},
9694
lvgl {lvgl},
9795
touchPanel {touchPanel},
@@ -104,7 +102,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
104102
settingsController {settingsController},
105103
motorController {motorController},
106104
motionController {motionController},
107-
timerController {timerController} {
105+
timerController {timerController},
106+
touchHandler {touchHandler} {
108107
}
109108

110109
void DisplayApp::Start() {
@@ -212,8 +211,7 @@ void DisplayApp::Refresh() {
212211
if (state != States::Running) {
213212
break;
214213
}
215-
auto info = touchPanel.GetTouchInfo();
216-
auto gesture = Convert(info);
214+
auto gesture = ConvertGesture(touchHandler.GestureGet());
217215
if (gesture == TouchEvents::None) {
218216
break;
219217
}
@@ -239,11 +237,9 @@ void DisplayApp::Refresh() {
239237
LoadApp(returnToApp, returnDirection);
240238
brightnessController.Set(settingsController.GetBrightness());
241239
brightnessController.Backup();
242-
} else if (touchMode == TouchModes::Gestures) {
243-
if (gesture == TouchEvents::Tap) {
244-
lvgl.SetNewTapEvent(info.x, info.y);
245-
}
246240
}
241+
} else {
242+
touchHandler.CancelTap();
247243
}
248244
} break;
249245
case Messages::ButtonPushed:
@@ -273,13 +269,8 @@ void DisplayApp::Refresh() {
273269
nextApp = Apps::None;
274270
}
275271

276-
if (state != States::Idle && touchMode == TouchModes::Polling) {
277-
auto info = touchPanel.GetTouchInfo();
278-
if (info.action == 2) { // 2 = contact
279-
if (!currentScreen->OnTouchEvent(info.x, info.y)) {
280-
lvgl.SetNewTapEvent(info.x, info.y);
281-
}
282-
}
272+
if (touchHandler.IsTouching()) {
273+
currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
283274
}
284275
}
285276

@@ -302,6 +293,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction
302293
}
303294

304295
void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
296+
touchHandler.CancelTap();
305297
currentScreen.reset(nullptr);
306298
SetFullRefresh(direction);
307299

@@ -467,10 +459,6 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
467459
}
468460
}
469461

470-
void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) {
471-
touchMode = mode;
472-
}
473-
474462
void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
475463
if (systemTask != nullptr)
476464
systemTask->PushMessage(message);

src/displayapp/DisplayApp.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "components/settings/Settings.h"
1515
#include "displayapp/screens/Screen.h"
1616
#include "components/timer/TimerController.h"
17+
#include "touchhandler/TouchHandler.h"
1718
#include "Messages.h"
1819

1920
namespace Pinetime {
@@ -31,6 +32,7 @@ namespace Pinetime {
3132
class NotificationManager;
3233
class HeartRateController;
3334
class MotionController;
35+
class TouchHandler;
3436
}
3537

3638
namespace System {
@@ -41,7 +43,6 @@ namespace Pinetime {
4143
public:
4244
enum class States { Idle, Running };
4345
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
44-
enum class TouchModes { Gestures, Polling };
4546

4647
DisplayApp(Drivers::St7789& lcd,
4748
Components::LittleVgl& lvgl,
@@ -55,14 +56,14 @@ namespace Pinetime {
5556
Controllers::Settings& settingsController,
5657
Pinetime::Controllers::MotorController& motorController,
5758
Pinetime::Controllers::MotionController& motionController,
58-
Pinetime::Controllers::TimerController& timerController);
59+
Pinetime::Controllers::TimerController& timerController,
60+
Pinetime::Controllers::TouchHandler& touchHandler);
5961
void Start();
6062
void PushMessage(Display::Messages msg);
6163

6264
void StartApp(Apps app, DisplayApp::FullRefreshDirections direction);
6365

6466
void SetFullRefresh(FullRefreshDirections direction);
65-
void SetTouchMode(TouchModes mode);
6667

6768
void Register(Pinetime::System::SystemTask* systemTask);
6869

@@ -81,6 +82,7 @@ namespace Pinetime {
8182
Pinetime::Controllers::MotorController& motorController;
8283
Pinetime::Controllers::MotionController& motionController;
8384
Pinetime::Controllers::TimerController& timerController;
85+
Pinetime::Controllers::TouchHandler& touchHandler;
8486

8587
Pinetime::Controllers::FirmwareValidator validator;
8688
Controllers::BrightnessController brightnessController;
@@ -100,8 +102,7 @@ namespace Pinetime {
100102
FullRefreshDirections returnDirection = FullRefreshDirections::None;
101103
TouchEvents returnTouchEvent = TouchEvents::None;
102104

103-
TouchModes touchMode = TouchModes::Gestures;
104-
105+
TouchEvents GetGesture();
105106
void RunningState();
106107
void IdleState();
107108
static void Process(void* instance);

src/displayapp/LittleVgl.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,43 +166,21 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
166166
lv_disp_flush_ready(&disp_drv);
167167
}
168168

169-
void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y) {
169+
void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) {
170170
tap_x = x;
171171
tap_y = y;
172-
tapped = true;
172+
tapped = contact;
173173
}
174174

175175
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
176+
ptr->point.x = tap_x;
177+
ptr->point.y = tap_y;
176178
if (tapped) {
177-
ptr->point.x = tap_x;
178-
ptr->point.y = tap_y;
179179
ptr->state = LV_INDEV_STATE_PR;
180-
tapped = false;
181180
} else {
182181
ptr->state = LV_INDEV_STATE_REL;
183182
}
184183
return false;
185-
/*
186-
auto info = touchPanel.GetTouchInfo();
187-
188-
if((previousClick.x != info.x || previousClick.y != info.y) &&
189-
(info.gesture == Drivers::Cst816S::Gestures::SingleTap)) {
190-
// TODO For an unknown reason, the first touch is taken twice into account.
191-
// 'firstTouch' is a quite'n'dirty workaound until I find a better solution
192-
if(firstTouch) ptr->state = LV_INDEV_STATE_REL;
193-
else ptr->state = LV_INDEV_STATE_PR;
194-
firstTouch = false;
195-
previousClick.x = info.x;
196-
previousClick.y = info.y;
197-
}
198-
else {
199-
ptr->state = LV_INDEV_STATE_REL;
200-
}
201-
202-
ptr->point.x = info.x;
203-
ptr->point.y = info.y;
204-
return false;
205-
*/
206184
}
207185

208186
void LittleVgl::InitTheme() {

src/displayapp/LittleVgl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Pinetime {
2424
void FlushDisplay(const lv_area_t* area, lv_color_t* color_p);
2525
bool GetTouchPadInfo(lv_indev_data_t* ptr);
2626
void SetFullRefresh(FullRefreshDirections direction);
27-
void SetNewTapEvent(uint16_t x, uint16_t y);
27+
void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact);
2828

2929
private:
3030
void InitDisplay();

src/displayapp/screens/FirmwareValidation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ bool FirmwareValidation::Refresh() {
6868
}
6969

7070
void FirmwareValidation::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
71-
if (object == buttonValidate && event == LV_EVENT_PRESSED) {
71+
if (object == buttonValidate && event == LV_EVENT_CLICKED) {
7272
validator.Validate();
7373
running = false;
74-
} else if (object == buttonReset && event == LV_EVENT_PRESSED) {
74+
} else if (object == buttonReset && event == LV_EVENT_CLICKED) {
7575
validator.Reset();
7676
}
7777
}

src/displayapp/screens/InfiniPaint.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
using namespace Pinetime::Applications::Screens;
66

77
InfiniPaint::InfiniPaint(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} {
8-
app->SetTouchMode(DisplayApp::TouchModes::Polling);
98
std::fill(b, b + bufferSize, selectColor);
109
}
1110

1211
InfiniPaint::~InfiniPaint() {
13-
// Reset the touchmode
14-
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
1512
lv_obj_clean(lv_scr_act());
1613
}
1714

src/displayapp/screens/List.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bool List::Refresh() {
104104
}
105105

106106
void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
107-
if (event == LV_EVENT_RELEASED) {
107+
if (event == LV_EVENT_CLICKED) {
108108
for (int i = 0; i < MAXLISTITEMS; i++) {
109109
if (apps[i] != Apps::None && object == itemApps[i]) {
110110
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up);

src/displayapp/screens/Metronome.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
6666
lv_obj_set_size(playPause, 115, 50);
6767
lv_obj_align(playPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
6868
lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);
69-
70-
app->SetTouchMode(DisplayApp::TouchModes::Polling);
7169
}
7270

7371
Metronome::~Metronome() {
74-
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
7572
systemTask.PushMessage(System::Messages::EnableSleeping);
7673
lv_obj_clean(lv_scr_act());
7774
}

src/displayapp/screens/Paddle.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using namespace Pinetime::Applications::Screens;
66

77
Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} {
8-
app->SetTouchMode(DisplayApp::TouchModes::Polling);
9-
108
background = lv_obj_create(lv_scr_act(), nullptr);
119
lv_obj_set_size(background, LV_HOR_RES + 1, LV_VER_RES);
1210
lv_obj_set_pos(background, -1, 0);
@@ -32,8 +30,6 @@ Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::Li
3230
}
3331

3432
Paddle::~Paddle() {
35-
// Reset the touchmode
36-
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
3733
lv_obj_clean(lv_scr_act());
3834
}
3935

0 commit comments

Comments
 (0)