From 2a3e1263906d1145d6b539ff019362f0077d8097 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 16 Jul 2021 00:07:55 +0300 Subject: [PATCH] Fix most issues --- src/displayapp/DisplayApp.cpp | 11 ++--------- src/displayapp/DisplayApp.h | 4 ---- src/displayapp/LittleVgl.cpp | 2 +- src/displayapp/LittleVgl.h | 2 +- src/displayapp/screens/InfiniPaint.cpp | 3 --- src/displayapp/screens/Metronome.cpp | 2 +- src/displayapp/screens/Paddle.cpp | 4 ---- src/displayapp/screens/Screen.h | 1 + src/drivers/Cst816s.cpp | 26 +++++++++----------------- src/drivers/Cst816s.h | 26 ++++++++++++-------------- src/systemtask/SystemTask.cpp | 2 +- src/touchhandler/TouchHandler.cpp | 20 ++++++++++++-------- 12 files changed, 40 insertions(+), 63 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index ca7e390f..945f182a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -226,9 +226,7 @@ void DisplayApp::Refresh() { } } - if (touchMode == TouchModes::Polling) { - currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); - } + currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY()); if (nextApp != Apps::None) { LoadApp(nextApp, nextDirection); @@ -367,6 +365,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::Metronome: currentScreen = std::make_unique(this, motorController, *systemTask); + ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None); break; case Apps::Motion: currentScreen = std::make_unique(this, motionController); @@ -397,10 +396,8 @@ void DisplayApp::PushMessage(Messages msg) { TouchEvents DisplayApp::GetGesture() { auto gesture = touchHandler.GestureGet(); 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: @@ -445,10 +442,6 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { } } -void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) { - touchMode = mode; -} - void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) { if(systemTask != nullptr) systemTask->PushMessage(message); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 74fc4456..96951d1c 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -43,7 +43,6 @@ namespace Pinetime { public: enum class States { Idle, Running }; enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim }; - enum class TouchModes { Gestures, Polling }; DisplayApp(Drivers::St7789& lcd, Components::LittleVgl& lvgl, @@ -65,7 +64,6 @@ namespace Pinetime { void StartApp(Apps app, DisplayApp::FullRefreshDirections direction); void SetFullRefresh(FullRefreshDirections direction); - void SetTouchMode(TouchModes mode); void Register(Pinetime::System::SystemTask* systemTask); @@ -104,8 +102,6 @@ namespace Pinetime { FullRefreshDirections returnDirection = FullRefreshDirections::None; TouchEvents returnTouchEvent = TouchEvents::None; - TouchModes touchMode = TouchModes::Gestures; - TouchEvents GetGesture(); void RunningState(); void IdleState(); diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp index d0c6161e..b5669713 100644 --- a/src/displayapp/LittleVgl.cpp +++ b/src/displayapp/LittleVgl.cpp @@ -166,7 +166,7 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) { lv_disp_flush_ready(&disp_drv); } -void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y, bool contact) { +void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) { tap_x = x; tap_y = y; tapped = contact; diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h index 8d1ed56f..1f8a3d79 100644 --- a/src/displayapp/LittleVgl.h +++ b/src/displayapp/LittleVgl.h @@ -24,7 +24,7 @@ namespace Pinetime { void FlushDisplay(const lv_area_t* area, lv_color_t* color_p); bool GetTouchPadInfo(lv_indev_data_t* ptr); void SetFullRefresh(FullRefreshDirections direction); - void SetNewTapEvent(uint16_t x, uint16_t y, bool contact); + void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact); private: void InitDisplay(); diff --git a/src/displayapp/screens/InfiniPaint.cpp b/src/displayapp/screens/InfiniPaint.cpp index 32240084..58bfa558 100644 --- a/src/displayapp/screens/InfiniPaint.cpp +++ b/src/displayapp/screens/InfiniPaint.cpp @@ -5,13 +5,10 @@ using namespace Pinetime::Applications::Screens; InfiniPaint::InfiniPaint(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} { - app->SetTouchMode(DisplayApp::TouchModes::Polling); std::fill(b, b + bufferSize, selectColor); } InfiniPaint::~InfiniPaint() { - // Reset the touchmode - app->SetTouchMode(DisplayApp::TouchModes::Gestures); lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp index 15916b62..3e3f478e 100644 --- a/src/displayapp/screens/Metronome.cpp +++ b/src/displayapp/screens/Metronome.cpp @@ -91,7 +91,7 @@ Metronome::~Metronome() { } bool Metronome::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - return true; + return false; } bool Metronome::Refresh() { diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 5a939ac7..79e0c3d3 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -5,8 +5,6 @@ using namespace Pinetime::Applications::Screens; Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl {lvgl} { - app->SetTouchMode(DisplayApp::TouchModes::Polling); - background = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_size(background, LV_HOR_RES + 1, LV_VER_RES); lv_obj_set_pos(background, -1, 0); @@ -32,8 +30,6 @@ Paddle::Paddle(Pinetime::Applications::DisplayApp* app, Pinetime::Components::Li } Paddle::~Paddle() { - // Reset the touchmode - app->SetTouchMode(DisplayApp::TouchModes::Gestures); lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/Screen.h b/src/displayapp/screens/Screen.h index 8e49c9de..6567a20c 100644 --- a/src/displayapp/screens/Screen.h +++ b/src/displayapp/screens/Screen.h @@ -60,6 +60,7 @@ namespace Pinetime { } /** @return false if the event hasn't been handled by the app, true if it has been handled */ + // Returning true will cancel lvgl tap virtual bool OnTouchEvent(TouchEvents event) { return false; } diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 127fe1ec..b8f8e45d 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -56,32 +56,24 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); - if (ret != TwiMaster::ErrorCodes::NoError) - return {}; + if (ret != TwiMaster::ErrorCodes::NoError) { + info.isValid = false; + return info; + } auto nbTouchPoints = touchData[2] & 0x0f; - uint8_t i = 0; - - uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4; - if (nbTouchPoints == 0 && pointId == lastTouchId) - return info; - - info.isTouch = true; - - auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f; - auto xLow = touchData[touchXLowIndex + (touchStep * i)]; + auto xHigh = touchData[touchXHighIndex] & 0x0f; + auto xLow = touchData[touchXLowIndex]; uint16_t x = (xHigh << 8) | xLow; - auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f; - auto yLow = touchData[touchYLowIndex + (touchStep * i)]; + auto yHigh = touchData[touchYHighIndex] & 0x0f; + auto yLow = touchData[touchYLowIndex]; uint16_t y = (yHigh << 8) | yLow; - auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ - info.x = x; info.y = y; - info.finger = nbTouchPoints; + info.touching = (nbTouchPoints > 0); info.gesture = static_cast(touchData[gestureIndex]); return info; diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 14c296ea..26bdf4e0 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -19,12 +19,9 @@ namespace Pinetime { struct TouchInfos { uint16_t x = 0; uint16_t y = 0; - uint8_t action = 0; - uint8_t finger = 0; - uint8_t pressure = 0; - uint8_t area = 0; Gestures gesture = Gestures::None; - bool isTouch = false; + bool touching = false; + bool isValid = false; }; Cst816S(TwiMaster& twiMaster, uint8_t twiAddress); @@ -41,23 +38,24 @@ namespace Pinetime { private: static constexpr uint8_t pinIrq = 28; static constexpr uint8_t pinReset = 10; - static constexpr uint8_t lastTouchId = 0x0f; + + // Unused/Unavailable commented out + static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t touchPointNumIndex = 2; - static constexpr uint8_t touchMiscIndex = 8; - static constexpr uint8_t touchXYIndex = 7; - static constexpr uint8_t touchEventIndex = 3; + //static constexpr uint8_t touchEventIndex = 3; static constexpr uint8_t touchXHighIndex = 3; static constexpr uint8_t touchXLowIndex = 4; + //static constexpr uint8_t touchIdIndex = 5; static constexpr uint8_t touchYHighIndex = 5; static constexpr uint8_t touchYLowIndex = 6; - static constexpr uint8_t touchIdIndex = 5; - static constexpr uint8_t touchStep = 6; - static constexpr uint8_t gestureIndex = 1; + //static constexpr uint8_t touchStep = 6; + //static constexpr uint8_t touchXYIndex = 7; + //static constexpr uint8_t touchMiscIndex = 8; - uint8_t touchData[10]; + uint8_t touchData[7]; TwiMaster& twiMaster; uint8_t twiAddress; }; } -} \ No newline at end of file +} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f6aee785..7277fc93 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -231,7 +231,7 @@ void SystemTask::Work() { twiMaster.Wakeup(); auto touchInfo = touchPanel.GetTouchInfo(); twiMaster.Sleep(); - if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp index 90b4d6da..c6f8629f 100644 --- a/src/touchhandler/TouchHandler.cpp +++ b/src/touchhandler/TouchHandler.cpp @@ -9,7 +9,7 @@ TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& void TouchHandler::CancelTap() { isCancelled = true; - lvgl.SetNewTapEvent(-1, -1, false); + lvgl.SetNewTouchPoint(-1, -1, true); } Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { @@ -19,7 +19,7 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() { } void TouchHandler::Start() { - if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 80, this, 0, &taskHandle)) { + if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } } @@ -39,13 +39,9 @@ void TouchHandler::Work() { } else { x = info.x; y = info.y; - if (info.finger == 0) { - lvgl.SetNewTapEvent(info.x, info.y, false); - prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; - isCancelled = false; - } else if (info.finger == 1) { + if (info.touching) { if (!isCancelled) { - lvgl.SetNewTapEvent(info.x, info.y, true); + lvgl.SetNewTouchPoint(info.x, info.y, true); } if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { if (prevGesture != info.gesture) { @@ -53,6 +49,14 @@ void TouchHandler::Work() { gesture = info.gesture; } } + } else { + if (isCancelled) { + lvgl.SetNewTouchPoint(-1, -1, false); + isCancelled = false; + } else { + lvgl.SetNewTouchPoint(info.x, info.y, false); + } + prevGesture = Pinetime::Drivers::Cst816S::Gestures::None; } systemTask->OnTouchEvent(); }