Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New touch handler #492

Merged
merged 22 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ list(APPEND SOURCE_FILES
components/heartrate/Biquad.cpp
components/heartrate/Ptagc.cpp
components/heartrate/HeartRateController.cpp

touchhandler/TouchHandler.cpp
)

list(APPEND RECOVERY_SOURCE_FILES
Expand Down Expand Up @@ -552,6 +554,7 @@ list(APPEND RECOVERY_SOURCE_FILES
components/heartrate/Ptagc.cpp
components/motor/MotorController.cpp
components/fs/FS.cpp
touchhandler/TouchHandler.cpp
)

list(APPEND RECOVERYLOADER_SOURCE_FILES
Expand Down Expand Up @@ -660,6 +663,7 @@ set(INCLUDE_FILES
components/heartrate/Ptagc.h
components/heartrate/HeartRateController.h
components/motor/MotorController.h
touchhandler/TouchHandler.h
)

include_directories(
Expand Down
142 changes: 64 additions & 78 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,6 @@ namespace {
static inline bool in_isr(void) {
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
}

TouchEvents Convert(Pinetime::Drivers::Cst816S::TouchInfos info) {
if (info.isTouch) {
switch (info.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;
}
}
return TouchEvents::None;
}
}

DisplayApp::DisplayApp(Drivers::St7789& lcd,
Expand All @@ -91,7 +66,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController)
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::TouchHandler& touchHandler)
: lcd {lcd},
lvgl {lvgl},
touchPanel {touchPanel},
Expand All @@ -104,7 +80,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
settingsController {settingsController},
motorController {motorController},
motionController {motionController},
timerController {timerController} {
timerController {timerController},
touchHandler {touchHandler} {
}

void DisplayApp::Start() {
Expand Down Expand Up @@ -208,44 +185,6 @@ void DisplayApp::Refresh() {
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
}
break;
case Messages::TouchEvent: {
if (state != States::Running) {
break;
}
auto info = touchPanel.GetTouchInfo();
auto gesture = Convert(info);
if (gesture == TouchEvents::None) {
break;
}
if (!currentScreen->OnTouchEvent(gesture)) {
if (currentApp == Apps::Clock) {
switch (gesture) {
case TouchEvents::SwipeUp:
LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
break;
case TouchEvents::SwipeDown:
LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
break;
case TouchEvents::SwipeRight:
LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
break;
case TouchEvents::DoubleTap:
PushMessageToSystemTask(System::Messages::GoToSleep);
break;
default:
break;
}
} else if (returnTouchEvent == gesture) {
LoadApp(returnToApp, returnDirection);
brightnessController.Set(settingsController.GetBrightness());
brightnessController.Backup();
} else if (touchMode == TouchModes::Gestures) {
if (gesture == TouchEvents::Tap) {
lvgl.SetNewTapEvent(info.x, info.y);
}
}
}
} break;
case Messages::ButtonPushed:
if (currentApp == Apps::Clock) {
PushMessageToSystemTask(System::Messages::GoToSleep);
Expand All @@ -268,19 +207,44 @@ void DisplayApp::Refresh() {
}
}

auto gesture = GetGesture();
if (gesture != TouchEvents::None) {
if (!currentScreen->OnTouchEvent(gesture)) {
if (currentApp == Apps::Clock) {
switch (gesture) {
case TouchEvents::SwipeUp:
LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
break;
case TouchEvents::SwipeDown:
LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
break;
case TouchEvents::SwipeRight:
LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
break;
case TouchEvents::DoubleTap:
PushMessageToSystemTask(System::Messages::GoToSleep);
break;
default:
break;
}
} else if (returnTouchEvent == gesture) {
LoadApp(returnToApp, returnDirection);
brightnessController.Set(settingsController.GetBrightness());
brightnessController.Backup();
}
} else {
touchHandler.CancelTap();
}
}

if (touchHandler.IsTouching()) {
currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
}

if (nextApp != Apps::None) {
LoadApp(nextApp, nextDirection);
nextApp = Apps::None;
}

if (state != States::Idle && touchMode == TouchModes::Polling) {
auto info = touchPanel.GetTouchInfo();
if (info.action == 2) { // 2 = contact
if (!currentScreen->OnTouchEvent(info.x, info.y)) {
lvgl.SetNewTapEvent(info.x, info.y);
}
}
}
}

void DisplayApp::RunningState() {
Expand All @@ -302,6 +266,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction
}

void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
touchHandler.CancelTap();
currentScreen.reset(nullptr);
SetFullRefresh(direction);

Expand Down Expand Up @@ -414,6 +379,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
break;
case Apps::Metronome:
currentScreen = std::make_unique<Screens::Metronome>(this, motorController, *systemTask);
ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::Motion:
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
Expand Down Expand Up @@ -441,6 +407,30 @@ 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:
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;
}
return TouchEvents::None;
}

void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
switch (direction) {
case DisplayApp::FullRefreshDirections::Down:
Expand All @@ -466,10 +456,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);
Expand Down
11 changes: 6 additions & 5 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "components/timer/TimerController.h"
#include "touchhandler/TouchHandler.h"
#include "Messages.h"

namespace Pinetime {
Expand All @@ -31,6 +32,7 @@ namespace Pinetime {
class NotificationManager;
class HeartRateController;
class MotionController;
class TouchHandler;
}

namespace System {
Expand All @@ -41,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,
Expand All @@ -55,14 +56,14 @@ namespace Pinetime {
Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController);
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::TouchHandler& touchHandler);
void Start();
void PushMessage(Display::Messages msg);

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

void SetFullRefresh(FullRefreshDirections direction);
void SetTouchMode(TouchModes mode);

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

Expand All @@ -81,6 +82,7 @@ namespace Pinetime {
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::MotionController& motionController;
Pinetime::Controllers::TimerController& timerController;
Pinetime::Controllers::TouchHandler& touchHandler;

Pinetime::Controllers::FirmwareValidator validator;
Controllers::BrightnessController brightnessController;
Expand All @@ -100,8 +102,7 @@ namespace Pinetime {
FullRefreshDirections returnDirection = FullRefreshDirections::None;
TouchEvents returnTouchEvent = TouchEvents::None;

TouchModes touchMode = TouchModes::Gestures;

TouchEvents GetGesture();
void RunningState();
void IdleState();
static void Process(void* instance);
Expand Down
30 changes: 4 additions & 26 deletions src/displayapp/LittleVgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,21 @@ 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) {
void LittleVgl::SetNewTouchPoint(uint16_t x, uint16_t y, bool contact) {
tap_x = x;
tap_y = y;
tapped = true;
tapped = contact;
}

bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
ptr->point.x = tap_x;
ptr->point.y = tap_y;
if (tapped) {
ptr->point.x = tap_x;
ptr->point.y = tap_y;
ptr->state = LV_INDEV_STATE_PR;
tapped = false;
} else {
ptr->state = LV_INDEV_STATE_REL;
}
return false;
/*
auto info = touchPanel.GetTouchInfo();

if((previousClick.x != info.x || previousClick.y != info.y) &&
(info.gesture == Drivers::Cst816S::Gestures::SingleTap)) {
// TODO For an unknown reason, the first touch is taken twice into account.
// 'firstTouch' is a quite'n'dirty workaound until I find a better solution
if(firstTouch) ptr->state = LV_INDEV_STATE_REL;
else ptr->state = LV_INDEV_STATE_PR;
firstTouch = false;
previousClick.x = info.x;
previousClick.y = info.y;
}
else {
ptr->state = LV_INDEV_STATE_REL;
}

ptr->point.x = info.x;
ptr->point.y = info.y;
return false;
*/
}

void LittleVgl::InitTheme() {
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/LittleVgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact);

private:
void InitDisplay();
Expand Down
1 change: 0 additions & 1 deletion src/displayapp/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Pinetime {
UpdateDateTime,
UpdateBleConnection,
UpdateBatteryLevel,
TouchEvent,
ButtonPushed,
NewNotification,
TimerDone,
Expand Down
4 changes: 2 additions & 2 deletions src/displayapp/screens/FirmwareValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ bool FirmwareValidation::Refresh() {
}

void FirmwareValidation::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
if (object == buttonValidate && event == LV_EVENT_PRESSED) {
if (object == buttonValidate && event == LV_EVENT_CLICKED) {
validator.Validate();
running = false;
} else if (object == buttonReset && event == LV_EVENT_PRESSED) {
} else if (object == buttonReset && event == LV_EVENT_CLICKED) {
validator.Reset();
}
}
3 changes: 0 additions & 3 deletions src/displayapp/screens/InfiniPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool List::Refresh() {
}

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