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 all 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
70 changes: 29 additions & 41 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,26 @@ namespace {
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;
}
TouchEvents ConvertGesture(Pinetime::Drivers::Cst816S::Gestures gesture) {
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;
}
}

Expand All @@ -91,7 +88,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 +102,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 @@ -212,8 +211,7 @@ void DisplayApp::Refresh() {
if (state != States::Running) {
break;
}
auto info = touchPanel.GetTouchInfo();
auto gesture = Convert(info);
auto gesture = ConvertGesture(touchHandler.GestureGet());
if (gesture == TouchEvents::None) {
break;
}
Expand All @@ -239,11 +237,9 @@ void DisplayApp::Refresh() {
LoadApp(returnToApp, returnDirection);
brightnessController.Set(settingsController.GetBrightness());
brightnessController.Backup();
} else if (touchMode == TouchModes::Gestures) {
if (gesture == TouchEvents::Tap) {
lvgl.SetNewTapEvent(info.x, info.y);
}
}
} else {
touchHandler.CancelTap();
}
} break;
case Messages::ButtonPushed:
Expand Down Expand Up @@ -273,13 +269,8 @@ void DisplayApp::Refresh() {
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);
}
}
if (touchHandler.IsTouching()) {
currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
}
}

Expand All @@ -302,6 +293,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 @@ -467,10 +459,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
4 changes: 2 additions & 2 deletions src/displayapp/screens/FirmwareValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,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 @@ -104,7 +104,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
3 changes: 0 additions & 3 deletions src/displayapp/screens/Metronome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
lv_obj_set_size(playPause, 115, 50);
lv_obj_align(playPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
lv_obj_set_style_local_value_str(playPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Symbols::play);

app->SetTouchMode(DisplayApp::TouchModes::Polling);
}

Metronome::~Metronome() {
app->SetTouchMode(DisplayApp::TouchModes::Gestures);
systemTask.PushMessage(System::Messages::EnableSleeping);
lv_obj_clean(lv_scr_act());
}
Expand Down
4 changes: 0 additions & 4 deletions src/displayapp/screens/Paddle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/ScreenList.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ namespace Pinetime {
};
}
}
}
}
4 changes: 2 additions & 2 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool StopWatch::Refresh() {
}

void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
if (event != LV_EVENT_PRESSED) {
if (event != LV_EVENT_CLICKED) {
return;
}
if (currentState == States::Init) {
Expand All @@ -174,7 +174,7 @@ void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
}

void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
if (event != LV_EVENT_PRESSED) {
if (event != LV_EVENT_CLICKED) {
return;
}
// If running, then this button is used to save laps
Expand Down
6 changes: 3 additions & 3 deletions src/displayapp/screens/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool SystemInfo::sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
}

std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
TaskStatus_t tasksStatus[7];
TaskStatus_t tasksStatus[10];
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL);
lv_table_set_col_cnt(infoTask, 4);
lv_table_set_row_cnt(infoTask, 8);
Expand All @@ -222,9 +222,9 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
lv_table_set_cell_value(infoTask, 0, 3, "Free");
lv_table_set_col_width(infoTask, 3, 90);

auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr);
auto nb = uxTaskGetSystemState(tasksStatus, sizeof(tasksStatus) / sizeof(tasksStatus[0]), nullptr);
std::sort(tasksStatus, tasksStatus + nb, sortById);
for (uint8_t i = 0; i < nb; i++) {
for (uint8_t i = 0; i < nb && i < 7; i++) {

lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
char state[2] = {0};
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Tile::Tile(uint8_t screenID,
lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 10);

for (uint8_t i = 0; i < 6; i++) {
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG);
if (applications[i].application == Apps::None) {
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED);
}
Expand Down
Loading