Fix most issues

This commit is contained in:
Riku Isokoski 2021-07-16 00:07:55 +03:00
parent 0d24d2b81e
commit 2a3e126390
12 changed files with 40 additions and 63 deletions

View File

@ -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<Screens::Metronome>(this, motorController, *systemTask);
ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::Motion:
currentScreen = std::make_unique<Screens::Motion>(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);

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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());
}

View File

@ -91,7 +91,7 @@ Metronome::~Metronome() {
}
bool Metronome::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return true;
return false;
}
bool Metronome::Refresh() {

View File

@ -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());
}

View File

@ -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;
}

View File

@ -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<Gestures>(touchData[gestureIndex]);
return info;

View File

@ -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;
};
}
}
}

View File

@ -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)))) {

View File

@ -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();
}