touchhandler: Remove LVGL dependency

Move LVGL specific code to the LittleVgl class
This commit is contained in:
Riku Isokoski 2023-02-23 13:28:04 +02:00
parent 6542f255cd
commit 7066ff5aba
7 changed files with 39 additions and 51 deletions

View file

@ -222,6 +222,7 @@ void DisplayApp::Refresh() {
if (state != States::Running) { if (state != States::Running) {
break; break;
} }
lvgl.SetNewTouchPoint(touchHandler.GetX(), touchHandler.GetY(), touchHandler.IsTouching());
auto gesture = touchHandler.GestureGet(); auto gesture = touchHandler.GestureGet();
if (gesture == TouchEvents::None) { if (gesture == TouchEvents::None) {
break; break;
@ -261,7 +262,7 @@ void DisplayApp::Refresh() {
LoadPreviousScreen(); LoadPreviousScreen();
} }
} else { } else {
touchHandler.CancelTap(); lvgl.CancelTap();
} }
} break; } break;
case Messages::ButtonPushed: case Messages::ButtonPushed:
@ -339,7 +340,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc
} }
void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) { void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
touchHandler.CancelTap(); lvgl.CancelTap();
ApplyBrightness(); ApplyBrightness();
currentScreen.reset(nullptr); currentScreen.reset(nullptr);

View file

@ -179,15 +179,34 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
lv_disp_flush_ready(&disp_drv); lv_disp_flush_ready(&disp_drv);
} }
void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) { void LittleVgl::SetNewTouchPoint(int16_t x, int16_t y, bool contact) {
tap_x = x; if (contact) {
tap_y = y; if (!isCancelled) {
tapped = contact; touchPoint = {x, y};
tapped = true;
}
} else {
if (isCancelled) {
touchPoint = {-1, -1};
tapped = false;
isCancelled = false;
} else {
touchPoint = {x, y};
tapped = false;
}
}
}
void LittleVgl::CancelTap() {
if (tapped) {
isCancelled = true;
touchPoint = {-1, -1};
}
} }
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) { bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
ptr->point.x = tap_x; ptr->point.x = touchPoint.x;
ptr->point.y = tap_y; ptr->point.y = touchPoint.y;
if (tapped) { if (tapped) {
ptr->state = LV_INDEV_STATE_PR; ptr->state = LV_INDEV_STATE_PR;
} else { } else {

View file

@ -23,7 +23,8 @@ namespace Pinetime {
void FlushDisplay(const lv_area_t* area, lv_color_t* color_p); void FlushDisplay(const lv_area_t* area, lv_color_t* color_p);
bool GetTouchPadInfo(lv_indev_data_t* ptr); bool GetTouchPadInfo(lv_indev_data_t* ptr);
void SetFullRefresh(FullRefreshDirections direction); void SetFullRefresh(FullRefreshDirections direction);
void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact); void SetNewTouchPoint(int16_t x, int16_t y, bool contact);
void CancelTap();
bool GetFullRefresh() { bool GetFullRefresh() {
bool returnValue = fullRefresh; bool returnValue = fullRefresh;
@ -58,9 +59,9 @@ namespace Pinetime {
uint16_t writeOffset = 0; uint16_t writeOffset = 0;
uint16_t scrollOffset = 0; uint16_t scrollOffset = 0;
uint16_t tap_x = 0; lv_point_t touchPoint = {0};
uint16_t tap_y = 0;
bool tapped = false; bool tapped = 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, lvgl); Pinetime::Controllers::TouchHandler touchHandler(touchPanel);
Pinetime::Controllers::ButtonHandler buttonHandler; Pinetime::Controllers::ButtonHandler buttonHandler;
Pinetime::Controllers::BrightnessController brightnessController {}; Pinetime::Controllers::BrightnessController brightnessController {};

View file

@ -343,10 +343,9 @@ void SystemTask::Work() {
break; break;
case Messages::OnTouchEvent: case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) { if (touchHandler.GetNewTouchInfo()) {
touchHandler.UpdateLvglTouchPoint();
}
ReloadIdleTimer(); ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
}
break; break;
case Messages::HandleButtonEvent: { case Messages::HandleButtonEvent: {
Controllers::ButtonActions action = Controllers::ButtonActions::None; Controllers::ButtonActions action = Controllers::ButtonActions::None;

View file

@ -1,9 +1,4 @@
#include "touchhandler/TouchHandler.h" #include "touchhandler/TouchHandler.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DummyLittleVgl.h"
#else
#include "displayapp/LittleVgl.h"
#endif
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
using namespace Pinetime::Applications; using namespace Pinetime::Applications;
@ -32,14 +27,7 @@ namespace {
} }
} }
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} { TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel) : touchPanel {touchPanel} {
}
void TouchHandler::CancelTap() {
if (info.touching) {
isCancelled = true;
lvgl.SetNewTouchPoint(-1, -1, true);
}
} }
Pinetime::Applications::TouchEvents TouchHandler::GestureGet() { Pinetime::Applications::TouchEvents TouchHandler::GestureGet() {
@ -55,6 +43,7 @@ bool TouchHandler::GetNewTouchInfo() {
return false; return false;
} }
// Only a single gesture per touch
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
if (gestureReleased) { if (gestureReleased) {
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
@ -78,18 +67,3 @@ bool TouchHandler::GetNewTouchInfo() {
return true; return true;
} }
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);
}
}
}

View file

@ -3,10 +3,6 @@
#include "displayapp/TouchEvents.h" #include "displayapp/TouchEvents.h"
namespace Pinetime { namespace Pinetime {
namespace Components {
class LittleVgl;
}
namespace Drivers { namespace Drivers {
class Cst816S; class Cst816S;
} }
@ -14,10 +10,9 @@ namespace Pinetime {
namespace Controllers { namespace Controllers {
class TouchHandler { class TouchHandler {
public: public:
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&); explicit TouchHandler(Drivers::Cst816S&);
void CancelTap();
bool GetNewTouchInfo(); bool GetNewTouchInfo();
void UpdateLvglTouchPoint();
bool IsTouching() const { bool IsTouching() const {
return info.touching; return info.touching;
@ -36,7 +31,6 @@ namespace Pinetime {
private: private:
Pinetime::Drivers::Cst816S::TouchInfos info; Pinetime::Drivers::Cst816S::TouchInfos info;
Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Applications::TouchEvents gesture; Pinetime::Applications::TouchEvents gesture;
bool isCancelled = false; bool isCancelled = false;
bool gestureReleased = true; bool gestureReleased = true;