Skip to content

Commit 7066ff5

Browse files
committed
touchhandler: Remove LVGL dependency
Move LVGL specific code to the LittleVgl class
1 parent 6542f25 commit 7066ff5

File tree

7 files changed

+39
-51
lines changed

7 files changed

+39
-51
lines changed

src/displayapp/DisplayApp.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void DisplayApp::Refresh() {
222222
if (state != States::Running) {
223223
break;
224224
}
225+
lvgl.SetNewTouchPoint(touchHandler.GetX(), touchHandler.GetY(), touchHandler.IsTouching());
225226
auto gesture = touchHandler.GestureGet();
226227
if (gesture == TouchEvents::None) {
227228
break;
@@ -261,7 +262,7 @@ void DisplayApp::Refresh() {
261262
LoadPreviousScreen();
262263
}
263264
} else {
264-
touchHandler.CancelTap();
265+
lvgl.CancelTap();
265266
}
266267
} break;
267268
case Messages::ButtonPushed:
@@ -339,7 +340,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc
339340
}
340341

341342
void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
342-
touchHandler.CancelTap();
343+
lvgl.CancelTap();
343344
ApplyBrightness();
344345

345346
currentScreen.reset(nullptr);

src/displayapp/LittleVgl.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,34 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
179179
lv_disp_flush_ready(&disp_drv);
180180
}
181181

182-
void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) {
183-
tap_x = x;
184-
tap_y = y;
185-
tapped = contact;
182+
void LittleVgl::SetNewTouchPoint(int16_t x, int16_t y, bool contact) {
183+
if (contact) {
184+
if (!isCancelled) {
185+
touchPoint = {x, y};
186+
tapped = true;
187+
}
188+
} else {
189+
if (isCancelled) {
190+
touchPoint = {-1, -1};
191+
tapped = false;
192+
isCancelled = false;
193+
} else {
194+
touchPoint = {x, y};
195+
tapped = false;
196+
}
197+
}
198+
}
199+
200+
void LittleVgl::CancelTap() {
201+
if (tapped) {
202+
isCancelled = true;
203+
touchPoint = {-1, -1};
204+
}
186205
}
187206

188207
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
189-
ptr->point.x = tap_x;
190-
ptr->point.y = tap_y;
208+
ptr->point.x = touchPoint.x;
209+
ptr->point.y = touchPoint.y;
191210
if (tapped) {
192211
ptr->state = LV_INDEV_STATE_PR;
193212
} else {

src/displayapp/LittleVgl.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace Pinetime {
2323
void FlushDisplay(const lv_area_t* area, lv_color_t* color_p);
2424
bool GetTouchPadInfo(lv_indev_data_t* ptr);
2525
void SetFullRefresh(FullRefreshDirections direction);
26-
void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact);
26+
void SetNewTouchPoint(int16_t x, int16_t y, bool contact);
27+
void CancelTap();
2728

2829
bool GetFullRefresh() {
2930
bool returnValue = fullRefresh;
@@ -58,9 +59,9 @@ namespace Pinetime {
5859
uint16_t writeOffset = 0;
5960
uint16_t scrollOffset = 0;
6061

61-
uint16_t tap_x = 0;
62-
uint16_t tap_y = 0;
62+
lv_point_t touchPoint = {0};
6363
bool tapped = false;
64+
bool isCancelled = false;
6465
};
6566
}
6667
}

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Pinetime::Controllers::NotificationManager notificationManager;
111111
Pinetime::Controllers::MotionController motionController;
112112
Pinetime::Controllers::TimerController timerController;
113113
Pinetime::Controllers::AlarmController alarmController {dateTimeController};
114-
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
114+
Pinetime::Controllers::TouchHandler touchHandler(touchPanel);
115115
Pinetime::Controllers::ButtonHandler buttonHandler;
116116
Pinetime::Controllers::BrightnessController brightnessController {};
117117

src/systemtask/SystemTask.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,9 @@ void SystemTask::Work() {
343343
break;
344344
case Messages::OnTouchEvent:
345345
if (touchHandler.GetNewTouchInfo()) {
346-
touchHandler.UpdateLvglTouchPoint();
346+
ReloadIdleTimer();
347+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
347348
}
348-
ReloadIdleTimer();
349-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
350349
break;
351350
case Messages::HandleButtonEvent: {
352351
Controllers::ButtonActions action = Controllers::ButtonActions::None;

src/touchhandler/TouchHandler.cpp

+2-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#include "touchhandler/TouchHandler.h"
2-
#ifdef PINETIME_IS_RECOVERY
3-
#include "displayapp/DummyLittleVgl.h"
4-
#else
5-
#include "displayapp/LittleVgl.h"
6-
#endif
72

83
using namespace Pinetime::Controllers;
94
using namespace Pinetime::Applications;
@@ -32,14 +27,7 @@ namespace {
3227
}
3328
}
3429

35-
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} {
36-
}
37-
38-
void TouchHandler::CancelTap() {
39-
if (info.touching) {
40-
isCancelled = true;
41-
lvgl.SetNewTouchPoint(-1, -1, true);
42-
}
30+
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel) : touchPanel {touchPanel} {
4331
}
4432

4533
Pinetime::Applications::TouchEvents TouchHandler::GestureGet() {
@@ -55,6 +43,7 @@ bool TouchHandler::GetNewTouchInfo() {
5543
return false;
5644
}
5745

46+
// Only a single gesture per touch
5847
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
5948
if (gestureReleased) {
6049
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
@@ -78,18 +67,3 @@ bool TouchHandler::GetNewTouchInfo() {
7867

7968
return true;
8069
}
81-
82-
void TouchHandler::UpdateLvglTouchPoint() {
83-
if (info.touching) {
84-
if (!isCancelled) {
85-
lvgl.SetNewTouchPoint(info.x, info.y, true);
86-
}
87-
} else {
88-
if (isCancelled) {
89-
lvgl.SetNewTouchPoint(-1, -1, false);
90-
isCancelled = false;
91-
} else {
92-
lvgl.SetNewTouchPoint(info.x, info.y, false);
93-
}
94-
}
95-
}

src/touchhandler/TouchHandler.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
#include "displayapp/TouchEvents.h"
44

55
namespace Pinetime {
6-
namespace Components {
7-
class LittleVgl;
8-
}
9-
106
namespace Drivers {
117
class Cst816S;
128
}
139

1410
namespace Controllers {
1511
class TouchHandler {
1612
public:
17-
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
18-
void CancelTap();
13+
explicit TouchHandler(Drivers::Cst816S&);
14+
1915
bool GetNewTouchInfo();
20-
void UpdateLvglTouchPoint();
2116

2217
bool IsTouching() const {
2318
return info.touching;
@@ -36,7 +31,6 @@ namespace Pinetime {
3631
private:
3732
Pinetime::Drivers::Cst816S::TouchInfos info;
3833
Pinetime::Drivers::Cst816S& touchPanel;
39-
Pinetime::Components::LittleVgl& lvgl;
4034
Pinetime::Applications::TouchEvents gesture;
4135
bool isCancelled = false;
4236
bool gestureReleased = true;

0 commit comments

Comments
 (0)