summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/displayapp/DisplayApp.cpp142
-rw-r--r--src/displayapp/DisplayApp.h11
-rw-r--r--src/displayapp/LittleVgl.cpp30
-rw-r--r--src/displayapp/LittleVgl.h2
-rw-r--r--src/displayapp/Messages.h1
-rw-r--r--src/displayapp/screens/FirmwareValidation.cpp4
-rw-r--r--src/displayapp/screens/InfiniPaint.cpp3
-rw-r--r--src/displayapp/screens/List.cpp2
-rw-r--r--src/displayapp/screens/Metronome.cpp5
-rw-r--r--src/displayapp/screens/Paddle.cpp4
-rw-r--r--src/displayapp/screens/Screen.h1
-rw-r--r--src/displayapp/screens/ScreenList.h2
-rw-r--r--src/displayapp/screens/StopWatch.cpp4
-rw-r--r--src/displayapp/screens/SystemInfo.cpp6
-rw-r--r--src/displayapp/screens/Tile.cpp1
-rw-r--r--src/displayapp/screens/settings/QuickSettings.cpp6
-rw-r--r--src/displayapp/screens/settings/SettingDisplay.cpp4
-rw-r--r--src/drivers/Cst816s.cpp38
-rw-r--r--src/drivers/Cst816s.h26
-rw-r--r--src/drivers/TwiMaster.cpp12
-rw-r--r--src/drivers/TwiMaster.h3
-rw-r--r--src/main.cpp12
-rw-r--r--src/systemtask/SystemTask.cpp40
-rw-r--r--src/systemtask/SystemTask.h11
-rw-r--r--src/touchhandler/TouchHandler.cpp78
-rw-r--r--src/touchhandler/TouchHandler.h49
27 files changed, 303 insertions, 198 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 40e1f2a5..cbc8cadc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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(
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index d4a73f5e..b4fc885b 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -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,
@@ -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},
@@ -104,7 +80,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
settingsController {settingsController},
motorController {motorController},
motionController {motionController},
- timerController {timerController} {
+ timerController {timerController},
+ touchHandler {touchHandler} {
}
void DisplayApp::Start() {
@@ -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);
@@ -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() {
@@ -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);
@@ -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);
@@ -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:
@@ -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);
diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h
index 574be63f..96951d1c 100644
--- a/src/displayapp/DisplayApp.h
+++ b/src/displayapp/DisplayApp.h
@@ -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 {
@@ -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,
@@ -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);
@@ -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;
@@ -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);
diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp
index c069afa2..2bd5e57b 100644
--- a/src/displayapp/LittleVgl.cpp
+++ b/src/displayapp/LittleVgl.cpp
@@ -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() {
diff --git a/src/displayapp/LittleVgl.h b/src/displayapp/LittleVgl.h
index 41f934a7..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);
+ void SetNewTouchPoint(uint16_t x, uint16_t y, bool contact);
private:
void InitDisplay();
diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h
index 322505e6..26480987 100644
--- a/src/displayapp/Messages.h
+++ b/src/displayapp/Messages.h
@@ -8,7 +8,6 @@ namespace Pinetime {
UpdateDateTime,
UpdateBleConnection,
UpdateBatteryLevel,
- TouchEvent,
ButtonPushed,
NewNotification,
TimerDone,
diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp
index 1d05be8d..5bacb4e8 100644
--- a/src/displayapp/screens/FirmwareValidation.cpp
+++ b/src/displayapp/screens/FirmwareValidation.cpp
@@ -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();
}
}
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/List.cpp b/src/displayapp/screens/List.cpp
index b4f4d2cf..1f92634a 100644
--- a/src/displayapp/screens/List.cpp
+++ b/src/displayapp/screens/List.cpp
@@ -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);
diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp
index 7bfbccb7..3e3f478e 100644
--- a/src/displayapp/screens/Metronome.cpp
+++ b/src/displayapp/screens/Metronome.cpp
@@ -83,18 +83,15 @@ 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());
}
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 6c9110c6..420f2015 100644
--- a/src/displayapp/screens/Screen.h
+++ b/src/displayapp/screens/Screen.h
@@ -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;
}
diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h
index ea66bfb2..50d66328 100644
--- a/src/displayapp/screens/ScreenList.h
+++ b/src/displayapp/screens/ScreenList.h
@@ -110,4 +110,4 @@ namespace Pinetime {
};
}
}
-} \ No newline at end of file
+}
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
index f4db5d6e..e3db6299 100644
--- a/src/displayapp/screens/StopWatch.cpp
+++ b/src/displayapp/screens/StopWatch.cpp
@@ -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
diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp
index e7c5b65a..35337511 100644
--- a/src/displayapp/screens/SystemInfo.cpp
+++ b/src/displayapp/screens/SystemInfo.cpp
@@ -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);
@@ -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};
diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp
index d5d6cb80..397545cc 100644
--- a/src/displayapp/screens/Tile.cpp
+++ b/src/displayapp/screens/Tile.cpp
@@ -95,6 +95,7 @@ Tile::Tile(uint8_t screenID,
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, lv_color_hex(0x111111));
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);
}
diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp
index 2cd24876..c689bf15 100644
--- a/src/displayapp/screens/settings/QuickSettings.cpp
+++ b/src/displayapp/screens/settings/QuickSettings.cpp
@@ -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);
diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp
index 4954185d..aaf6a9f0 100644
--- a/src/displayapp/screens/settings/SettingDisplay.cpp
+++ b/src/displayapp/screens/settings/SettingDisplay.cpp
@@ -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);
@@ -110,4 +110,4 @@ void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index fd9792b3..b8f8e45d 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -40,38 +40,40 @@ 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() {
Cst816S::TouchInfos info;
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
- if (ret != TwiMaster::ErrorCodes::NoError)
- return {};
-
- auto nbTouchPoints = touchData[2] & 0x0f;
-
- uint8_t i = 0;
-
- uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
- if (nbTouchPoints == 0 && pointId == lastTouchId)
+ if (ret != TwiMaster::ErrorCodes::NoError) {
+ info.isValid = false;
return info;
+ }
- info.isTouch = true;
+ auto nbTouchPoints = touchData[2] & 0x0f;
- 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.action = action;
+ info.touching = (nbTouchPoints > 0);
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
return info;
@@ -90,4 +92,4 @@ void Cst816S::Sleep() {
void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
-} \ No newline at end of file
+}
diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h
index 14c296ea..d4c17bb8 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 = true;
};
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/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp
index fc9edf81..456c3e64 100644
--- a/src/drivers/TwiMaster.cpp
+++ b/src/drivers/TwiMaster.cpp
@@ -12,9 +12,10 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
}
void TwiMaster::Init() {
+ sleeping = false;
if(mutex == nullptr)
mutex = xSemaphoreCreateBinary();
-
+
NRF_GPIO->PIN_CNF[params.pinScl] =
((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
@@ -176,11 +177,14 @@ void TwiMaster::Sleep() {
nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7);
NRF_LOG_INFO("[TWIMASTER] Sleep");
+ sleeping = true;
}
void TwiMaster::Wakeup() {
- Init();
- NRF_LOG_INFO("[TWIMASTER] Wakeup");
+ if (sleeping) {
+ Init();
+ NRF_LOG_INFO("[TWIMASTER] Wakeup");
+ }
}
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
@@ -206,4 +210,4 @@ void TwiMaster::FixHwFreezed() {
// Re-enable I²C
twiBaseAddress->ENABLE = twi_state;
-} \ No newline at end of file
+}
diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h
index 6175b99b..5748ec65 100644
--- a/src/drivers/TwiMaster.h
+++ b/src/drivers/TwiMaster.h
@@ -39,6 +39,7 @@ namespace Pinetime {
uint8_t internalBuffer[maxDataSize + registerSize];
uint32_t txStartedCycleCount = 0;
static constexpr uint32_t HwFreezedDelay {161000};
+ bool sleeping;
};
}
-} \ No newline at end of file
+}
diff --git a/src/main.cpp b/src/main.cpp
index d301be67..9a5b0cfe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -44,6 +44,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"
@@ -119,6 +120,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};
@@ -137,7 +139,8 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
settingsController,
motorController,
motionController,
- timerController);
+ timerController,
+ touchHandler);
Pinetime::System::SystemTask systemTask(spi,
lcd,
@@ -159,11 +162,13 @@ Pinetime::System::SystemTask systemTask(spi,
heartRateController,
displayApp,
heartRateApp,
- fs);
+ fs,
+ touchHandler);
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) {
- systemTask.OnTouchEvent();
+ twiMaster.Wakeup();
+ touchHandler.WakeUp();
return;
}
@@ -324,6 +329,7 @@ int main(void) {
lvgl.Init();
systemTask.Start();
+
nimble_port_init();
vTaskStartScheduler();
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 8915ce74..7ba7cf69 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -67,7 +67,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
- Pinetime::Controllers::FS& fs)
+ Pinetime::Controllers::FS& fs,
+ Pinetime::Controllers::TouchHandler& touchHandler)
: spi {spi},
lcd {lcd},
spiNorFlash {spiNorFlash},
@@ -79,18 +80,18 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
dateTimeController {dateTimeController},
timerController {timerController},
watchdog {watchdog},
- notificationManager{notificationManager},
+ notificationManager {notificationManager},
motorController {motorController},
heartRateSensor {heartRateSensor},
motionSensor {motionSensor},
settingsController {settingsController},
- heartRateController{heartRateController},
- motionController{motionController},
- displayApp{displayApp},
+ heartRateController {heartRateController},
+ motionController {motionController},
+ displayApp {displayApp},
heartRateApp(heartRateApp),
- fs{fs},
+ fs {fs},
+ touchHandler {touchHandler},
nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) {
-
}
void SystemTask::Start() {
@@ -116,7 +117,7 @@ void SystemTask::Work() {
spi.Init();
spiNorFlash.Init();
spiNorFlash.Wakeup();
-
+
fs.Init();
nimbleController.Init();
@@ -149,6 +150,9 @@ void SystemTask::Work() {
heartRateSensor.Disable();
heartRateApp.Start();
+ touchHandler.Register(this);
+ touchHandler.Start();
+
nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
@@ -240,14 +244,14 @@ void SystemTask::Work() {
isDimmed = false;
break;
case Messages::TouchWakeUp: {
- twiMaster.Wakeup();
- auto touchInfo = touchPanel.GetTouchInfo();
- twiMaster.Sleep();
- if (touchInfo.isTouch 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)))) {
+ auto gesture = touchHandler.GestureGet();
+ if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
+ settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
+ (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap &&
+ settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {
GoToRunning();
+ } else {
+ twiMaster.Sleep();
}
} break;
case Messages::GoToSleep:
@@ -296,7 +300,6 @@ void SystemTask::Work() {
break;
case Messages::OnTouchEvent:
ReloadIdleTimer();
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::OnButtonEvent:
ReloadIdleTimer();
@@ -327,7 +330,7 @@ void SystemTask::Work() {
break;
case Messages::OnChargingEvent:
motorController.SetDuration(15);
- // Battery level is updated on every message - there's no need to do anything
+ // Battery level is updated on every message - there's no need to do anything
break;
default:
@@ -425,14 +428,13 @@ void SystemTask::PushMessage(System::Messages msg) {
isGoingToSleep = true;
}
- if(in_isr()) {
+ if (in_isr()) {
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken) {
/* Actual macro used here is port specific. */
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
-
}
} else {
xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY);
diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h
index ba434298..0266ba8a 100644
--- a/src/systemtask/SystemTask.h
+++ b/src/systemtask/SystemTask.h
@@ -17,6 +17,7 @@
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h"
#include "components/fs/FS.h"
+#include "touchhandler/TouchHandler.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h"
@@ -24,7 +25,7 @@
#else
#include "components/settings/Settings.h"
#include "displayapp/DisplayApp.h"
- #include "displayapp/LittleVgl.h"
+ #include "displayapp/LittleVgl.h"
#endif
#include "drivers/Watchdog.h"
@@ -39,6 +40,9 @@ namespace Pinetime {
class TwiMaster;
class Hrs3300;
}
+ namespace Controllers {
+ class TouchHandler;
+ }
namespace System {
class SystemTask {
public:
@@ -62,7 +66,8 @@ namespace Pinetime {
Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
- Pinetime::Controllers::FS& fs);
+ Pinetime::Controllers::FS& fs,
+ Pinetime::Controllers::TouchHandler& touchHandler);
void Start();
void PushMessage(Messages msg);
@@ -92,7 +97,6 @@ namespace Pinetime {
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Controllers::Battery& batteryController;
-
Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController;
@@ -113,6 +117,7 @@ namespace Pinetime {
Pinetime::Applications::DisplayApp& displayApp;
Pinetime::Applications::HeartRateTask& heartRateApp;
Pinetime::Controllers::FS& fs;
+ Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::NimbleController nimbleController;
static constexpr uint8_t pinSpiSck = 2;
diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp
new file mode 100644
index 00000000..187aa696
--- /dev/null
+++ b/src/touchhandler/TouchHandler.cpp
@@ -0,0 +1,78 @@
+#include "TouchHandler.h"
+
+using namespace Pinetime::Controllers;
+
+TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} {
+}
+
+void TouchHandler::CancelTap() {
+ if (info.touching) {
+ isCancelled = true;
+ lvgl.SetNewTouchPoint(-1, -1, true);
+ }
+}
+
+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", 100, 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() {
+ bool slideReleased = true;
+ while (true) {
+ vTaskSuspend(taskHandle);
+
+ info = touchPanel.GetTouchInfo();
+
+ if (info.isValid) {
+ if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
+ if (slideReleased) {
+ if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
+ slideReleased = false;
+ }
+ gesture = info.gesture;
+ }
+ }
+
+ if (!systemTask->IsSleeping()) {
+ 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);
+ }
+ slideReleased = true;
+ }
+ }
+ systemTask->OnTouchEvent();
+ }
+ }
+}
+
+void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
+ this->systemTask = systemTask;
+}
+
+void TouchHandler::WakeUp() {
+ vTaskResume(taskHandle);
+}
diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h
new file mode 100644
index 00000000..6b8189f5
--- /dev/null
+++ b/src/touchhandler/TouchHandler.h
@@ -0,0 +1,49 @@
+#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();
+
+ bool IsTouching() const {
+ return info.touching;
+ }
+ uint8_t GetX() const {
+ return info.x;
+ }
+ uint8_t GetY() const {
+ return info.y;
+ }
+ Drivers::Cst816S::Gestures GestureGet();
+ private:
+ static void Process(void* instance);
+ void Work();
+
+ Pinetime::Drivers::Cst816S::TouchInfos info;
+ Pinetime::System::SystemTask* systemTask = nullptr;
+ TaskHandle_t taskHandle;
+ Pinetime::Drivers::Cst816S& touchPanel;
+ Pinetime::Components::LittleVgl& lvgl;
+ Pinetime::Drivers::Cst816S::Gestures gesture;
+ bool isCancelled = false;
+ };
+ }
+}