New touch handler, with issues
This commit is contained in:
parent
57b3397078
commit
fe64176e7b
21 changed files with 230 additions and 102 deletions
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -660,6 +663,7 @@ set(INCLUDE_FILES
|
|||
components/heartrate/Ptagc.h
|
||||
components/heartrate/HeartRateController.h
|
||||
components/motor/MotorController.h
|
||||
touchhandler/TouchHandler.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
|
|
@ -66,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},
|
||||
|
@ -79,7 +80,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
|||
settingsController {settingsController},
|
||||
motorController {motorController},
|
||||
motionController {motionController},
|
||||
timerController {timerController} {
|
||||
timerController {timerController},
|
||||
touchHandler {touchHandler} {
|
||||
}
|
||||
|
||||
void DisplayApp::Start() {
|
||||
|
@ -176,33 +178,6 @@ void DisplayApp::Refresh() {
|
|||
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
|
||||
}
|
||||
break;
|
||||
case Messages::TouchEvent: {
|
||||
if (state != States::Running)
|
||||
break;
|
||||
auto gesture = OnTouchEvent();
|
||||
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);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case Messages::ButtonPushed:
|
||||
if (currentApp == Apps::Clock) {
|
||||
PushMessageToSystemTask(System::Messages::GoToSleep);
|
||||
|
@ -223,18 +198,41 @@ void DisplayApp::Refresh() {
|
|||
}
|
||||
}
|
||||
|
||||
if(nextApp != Apps::None) {
|
||||
LoadApp(nextApp, nextDirection);
|
||||
nextApp = Apps::None;
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
touchHandler.CancelTap();
|
||||
}
|
||||
}
|
||||
|
||||
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 (touchMode == TouchModes::Polling) {
|
||||
currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
|
||||
}
|
||||
|
||||
if (nextApp != Apps::None) {
|
||||
LoadApp(nextApp, nextDirection);
|
||||
nextApp = Apps::None;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,6 +255,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction
|
|||
}
|
||||
|
||||
void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
|
||||
touchHandler.CancelTap();
|
||||
currentScreen.reset(nullptr);
|
||||
SetFullRefresh(direction);
|
||||
|
||||
|
@ -395,31 +394,28 @@ void DisplayApp::PushMessage(Messages msg) {
|
|||
}
|
||||
}
|
||||
|
||||
TouchEvents DisplayApp::OnTouchEvent() {
|
||||
auto info = touchPanel.GetTouchInfo();
|
||||
if (info.isTouch) {
|
||||
switch (info.gesture) {
|
||||
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
|
||||
if (touchMode == TouchModes::Gestures) {
|
||||
lvgl.SetNewTapEvent(info.x, info.y);
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -31,6 +32,7 @@ namespace Pinetime {
|
|||
class NotificationManager;
|
||||
class HeartRateController;
|
||||
class MotionController;
|
||||
class TouchHandler;
|
||||
}
|
||||
|
||||
namespace System {
|
||||
|
@ -55,7 +57,8 @@ 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);
|
||||
|
||||
|
@ -81,6 +84,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;
|
||||
|
@ -102,7 +106,7 @@ namespace Pinetime {
|
|||
|
||||
TouchModes touchMode = TouchModes::Gestures;
|
||||
|
||||
TouchEvents OnTouchEvent();
|
||||
TouchEvents GetGesture();
|
||||
void RunningState();
|
||||
void IdleState();
|
||||
static void Process(void* instance);
|
||||
|
|
|
@ -166,18 +166,17 @@ 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::SetNewTapEvent(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;
|
||||
}
|
||||
|
|
|
@ -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 SetNewTapEvent(uint16_t x, uint16_t y, bool contact);
|
||||
|
||||
private:
|
||||
void InitDisplay();
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace Pinetime {
|
|||
UpdateDateTime,
|
||||
UpdateBleConnection,
|
||||
UpdateBatteryLevel,
|
||||
TouchEvent,
|
||||
ButtonPushed,
|
||||
NewNotification,
|
||||
TimerDone,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -83,12 +83,9 @@ Metronome::Metronome(DisplayApp* app, Controllers::MotorController& motorControl
|
|||
lv_obj_set_height(playPause, 39);
|
||||
playPauseLabel = lv_label_create(playPause, nullptr);
|
||||
lv_label_set_text(playPauseLabel, 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());
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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
|
||||
|
|
|
@ -210,7 +210,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, 3);
|
||||
lv_table_set_row_cnt(infoTask, 8);
|
||||
|
@ -223,9 +223,9 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
|
|||
lv_table_set_cell_value(infoTask, 0, 2, "Free");
|
||||
lv_table_set_col_width(infoTask, 2, 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());
|
||||
lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName);
|
||||
|
|
|
@ -12,9 +12,7 @@ namespace {
|
|||
|
||||
static void event_handler(lv_obj_t* obj, lv_event_t event) {
|
||||
Tile* screen = static_cast<Tile*>(obj->user_data);
|
||||
uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data();
|
||||
uint32_t eventData = *eventDataPtr;
|
||||
screen->OnObjectEvent(obj, event, eventData);
|
||||
screen->OnObjectEvent(obj, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,9 +122,9 @@ bool Tile::Refresh() {
|
|||
return running;
|
||||
}
|
||||
|
||||
void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) {
|
||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
||||
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
|
||||
void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event) {
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
app->StartApp(apps[lv_btnmatrix_get_active_btn(obj)], DisplayApp::FullRefreshDirections::Up);
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Pinetime {
|
|||
|
||||
bool Refresh() override;
|
||||
void UpdateScreen();
|
||||
void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId);
|
||||
void OnObjectEvent(lv_obj_t* obj, lv_event_t event);
|
||||
|
||||
private:
|
||||
Pinetime::Controllers::Battery& batteryController;
|
||||
|
|
|
@ -125,12 +125,12 @@ void QuickSettings::UpdateScreen() {
|
|||
}
|
||||
|
||||
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
||||
if (object == btn2 && event == LV_EVENT_PRESSED) {
|
||||
if (object == btn2 && event == LV_EVENT_CLICKED) {
|
||||
|
||||
running = false;
|
||||
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None);
|
||||
|
||||
} else if (object == btn1 && event == LV_EVENT_PRESSED) {
|
||||
} else if (object == btn1 && event == LV_EVENT_CLICKED) {
|
||||
|
||||
brightness.Step();
|
||||
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
||||
|
@ -147,7 +147,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
|||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
||||
}
|
||||
|
||||
} else if (object == btn4 && event == LV_EVENT_PRESSED) {
|
||||
} else if (object == btn4 && event == LV_EVENT_CLICKED) {
|
||||
running = false;
|
||||
settingsController.SetSettingsMenu(0);
|
||||
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
|
||||
|
|
|
@ -85,7 +85,7 @@ bool SettingDisplay::Refresh() {
|
|||
}
|
||||
|
||||
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
for (int i = 0; i < optionsTotal; i++) {
|
||||
if (object == cbOption[i]) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
|
|
|
@ -40,6 +40,16 @@ void Cst816S::Init() {
|
|||
*/
|
||||
static constexpr uint8_t motionMask = 0b00000101;
|
||||
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
|
||||
|
||||
/*
|
||||
[7] EnTest - Interrupt pin to test, enable automatic periodic issued after a low pulse.
|
||||
[6] EnTouch - When a touch is detected, a periodic pulsed Low.
|
||||
[5] EnChange - Upon detecting a touch state changes, pulsed Low.
|
||||
[4] EnMotion - When the detected gesture is pulsed Low.
|
||||
[0] OnceWLP - Press gesture only issue a pulse signal is low.
|
||||
*/
|
||||
static constexpr uint8_t irqCtl = 0b01110000;
|
||||
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
|
||||
}
|
||||
|
||||
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -43,6 +43,7 @@
|
|||
#include "drivers/TwiMaster.h"
|
||||
#include "drivers/Cst816s.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include "touchhandler/TouchHandler.h"
|
||||
|
||||
#if NRF_LOG_ENABLED
|
||||
#include "logging/NrfLogger.h"
|
||||
|
@ -118,6 +119,7 @@ Pinetime::Drivers::WatchdogView watchdogView(watchdog);
|
|||
Pinetime::Controllers::NotificationManager notificationManager;
|
||||
Pinetime::Controllers::MotionController motionController;
|
||||
Pinetime::Controllers::TimerController timerController;
|
||||
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
||||
|
||||
Pinetime::Controllers::FS fs {spiNorFlash};
|
||||
Pinetime::Controllers::Settings settingsController {fs};
|
||||
|
@ -136,7 +138,8 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
|
|||
settingsController,
|
||||
motorController,
|
||||
motionController,
|
||||
timerController);
|
||||
timerController,
|
||||
touchHandler);
|
||||
|
||||
Pinetime::System::SystemTask systemTask(spi,
|
||||
lcd,
|
||||
|
@ -162,7 +165,7 @@ Pinetime::System::SystemTask systemTask(spi,
|
|||
|
||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
if (pin == pinTouchIrq) {
|
||||
systemTask.OnTouchEvent();
|
||||
touchHandler.WakeUp();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -309,6 +312,10 @@ int main(void) {
|
|||
lvgl.Init();
|
||||
|
||||
systemTask.Start();
|
||||
|
||||
touchHandler.Register(&systemTask);
|
||||
touchHandler.Start();
|
||||
|
||||
nimble_port_init();
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
|
|
@ -397,7 +397,6 @@ void SystemTask::OnTouchEvent() {
|
|||
return;
|
||||
if (!isSleeping) {
|
||||
PushMessage(Messages::OnTouchEvent);
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
|
||||
} else if (!isWakingUp) {
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
|
||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||
|
|
70
src/touchhandler/TouchHandler.cpp
Normal file
70
src/touchhandler/TouchHandler.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "TouchHandler.h"
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl)
|
||||
: touchPanel {touchPanel},
|
||||
lvgl {lvgl} {
|
||||
}
|
||||
|
||||
void TouchHandler::CancelTap() {
|
||||
isCancelled = true;
|
||||
lvgl.SetNewTapEvent(-1, -1, false);
|
||||
}
|
||||
|
||||
Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
|
||||
auto returnGesture = gesture;
|
||||
gesture = Drivers::Cst816S::Gestures::None;
|
||||
return returnGesture;
|
||||
}
|
||||
|
||||
void TouchHandler::Start() {
|
||||
if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 80, this, 0, &taskHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
}
|
||||
|
||||
void TouchHandler::Process(void* instance) {
|
||||
auto* app = static_cast<TouchHandler*>(instance);
|
||||
app->Work();
|
||||
}
|
||||
|
||||
void TouchHandler::Work() {
|
||||
Pinetime::Drivers::Cst816S::TouchInfos info;
|
||||
while (true) {
|
||||
vTaskSuspend(taskHandle);
|
||||
info = touchPanel.GetTouchInfo();
|
||||
if (systemTask->IsSleeping()) {
|
||||
systemTask->PushMessage(System::Messages::TouchWakeUp);
|
||||
} else {
|
||||
x = info.x;
|
||||
y = info.y;
|
||||
if (info.action == 0) {
|
||||
lvgl.SetNewTapEvent(info.x, info.y, true);
|
||||
} else if (info.action == 1) {
|
||||
lvgl.SetNewTapEvent(info.x, info.y, false);
|
||||
prevGesture = Pinetime::Drivers::Cst816S::Gestures::None;
|
||||
isCancelled = false;
|
||||
} else if (info.action == 2) {
|
||||
if (!isCancelled) {
|
||||
lvgl.SetNewTapEvent(info.x, info.y, true);
|
||||
}
|
||||
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
|
||||
if (prevGesture != info.gesture) {
|
||||
prevGesture = info.gesture;
|
||||
gesture = info.gesture;
|
||||
}
|
||||
}
|
||||
}
|
||||
systemTask->OnTouchEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
|
||||
this->systemTask = systemTask;
|
||||
}
|
||||
|
||||
void TouchHandler::WakeUp() {
|
||||
vTaskResume(taskHandle);
|
||||
}
|
45
src/touchhandler/TouchHandler.h
Normal file
45
src/touchhandler/TouchHandler.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
#include "drivers/Cst816s.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Components {
|
||||
class LittleVgl;
|
||||
}
|
||||
namespace Drivers {
|
||||
class Cst816S;
|
||||
}
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
}
|
||||
namespace Controllers {
|
||||
class TouchHandler {
|
||||
public:
|
||||
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
|
||||
void CancelTap();
|
||||
void Register(Pinetime::System::SystemTask* systemTask);
|
||||
void Start();
|
||||
void WakeUp();
|
||||
uint8_t GetX() const {
|
||||
return x;
|
||||
}
|
||||
uint8_t GetY() const {
|
||||
return y;
|
||||
}
|
||||
Drivers::Cst816S::Gestures GestureGet();
|
||||
private:
|
||||
static void Process(void* instance);
|
||||
void Work();
|
||||
Pinetime::System::SystemTask* systemTask = nullptr;
|
||||
TaskHandle_t taskHandle;
|
||||
Pinetime::Drivers::Cst816S& touchPanel;
|
||||
Pinetime::Components::LittleVgl& lvgl;
|
||||
Pinetime::Drivers::Cst816S::Gestures gesture;
|
||||
Pinetime::Drivers::Cst816S::Gestures prevGesture;
|
||||
bool isCancelled = false;
|
||||
uint8_t x, y;
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue