Rework TouchHandler into not a task

This commit is contained in:
Riku Isokoski 2021-08-10 22:03:34 +03:00
parent 7e92577c14
commit 8a694adb09
6 changed files with 50 additions and 71 deletions

View File

@ -12,7 +12,6 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
} }
void TwiMaster::Init() { void TwiMaster::Init() {
sleeping = false;
if(mutex == nullptr) if(mutex == nullptr)
mutex = xSemaphoreCreateBinary(); mutex = xSemaphoreCreateBinary();
@ -177,14 +176,11 @@ void TwiMaster::Sleep() {
nrf_gpio_cfg_default(6); nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7); nrf_gpio_cfg_default(7);
NRF_LOG_INFO("[TWIMASTER] Sleep"); NRF_LOG_INFO("[TWIMASTER] Sleep");
sleeping = true;
} }
void TwiMaster::Wakeup() { void TwiMaster::Wakeup() {
if (sleeping) { Init();
Init(); NRF_LOG_INFO("[TWIMASTER] Wakeup");
NRF_LOG_INFO("[TWIMASTER] Wakeup");
}
} }
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX. /* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.

View File

@ -39,7 +39,6 @@ namespace Pinetime {
uint8_t internalBuffer[maxDataSize + registerSize]; uint8_t internalBuffer[maxDataSize + registerSize];
uint32_t txStartedCycleCount = 0; uint32_t txStartedCycleCount = 0;
static constexpr uint32_t HwFreezedDelay {161000}; static constexpr uint32_t HwFreezedDelay {161000};
bool sleeping;
}; };
} }
} }

View File

@ -166,8 +166,7 @@ Pinetime::System::SystemTask systemTask(spi,
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) { if (pin == pinTouchIrq) {
twiMaster.Wakeup(); systemTask.OnTouchEvent();
touchHandler.WakeUp();
return; return;
} }

View File

@ -150,9 +150,6 @@ void SystemTask::Work() {
heartRateSensor.Disable(); heartRateSensor.Disable();
heartRateApp.Start(); 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_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_cfg_output(15);
nrf_gpio_pin_set(15); nrf_gpio_pin_set(15);
@ -244,6 +241,8 @@ void SystemTask::Work() {
isDimmed = false; isDimmed = false;
break; break;
case Messages::TouchWakeUp: { case Messages::TouchWakeUp: {
twiMaster.Wakeup();
touchHandler.GetNewTouchInfo();
auto gesture = touchHandler.GestureGet(); auto gesture = touchHandler.GestureGet();
if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap && if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) || settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
@ -299,6 +298,9 @@ void SystemTask::Work() {
xTimerStart(dimTimer, 0); xTimerStart(dimTimer, 0);
break; break;
case Messages::OnTouchEvent: case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) {
touchHandler.UpdateLvglTouchPoint();
}
ReloadIdleTimer(); ReloadIdleTimer();
break; break;
case Messages::OnButtonEvent: case Messages::OnButtonEvent:

View File

@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
return returnGesture; return returnGesture;
} }
void TouchHandler::Start() { bool TouchHandler::GetNewTouchInfo() {
if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) { info = touchPanel.GetTouchInfo();
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
if (!info.isValid) {
return false;
} }
}
void TouchHandler::Process(void* instance) { if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
auto* app = static_cast<TouchHandler*>(instance); if (slideReleased) {
app->Work(); if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
} info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
void TouchHandler::Work() { info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
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 (info.touching) {
if (!isCancelled) { gesture = info.gesture;
lvgl.SetNewTouchPoint(info.x, info.y, true); slideReleased = false;
}
} else {
if (isCancelled) {
lvgl.SetNewTouchPoint(-1, -1, false);
isCancelled = false;
} else {
lvgl.SetNewTouchPoint(info.x, info.y, false);
}
slideReleased = true;
} }
} else {
gesture = info.gesture;
} }
systemTask->OnTouchEvent(); }
}
if (!info.touching) {
slideReleased = true;
}
return true;
}
void TouchHandler::UpdateLvglTouchPoint() {
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);
} }
} }
} }
void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
void TouchHandler::WakeUp() {
vTaskResume(taskHandle);
}

View File

@ -19,9 +19,9 @@ namespace Pinetime {
public: public:
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&); explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
void CancelTap(); void CancelTap();
bool GetNewTouchInfo();
void UpdateLvglTouchPoint();
void Register(Pinetime::System::SystemTask* systemTask); void Register(Pinetime::System::SystemTask* systemTask);
void Start();
void WakeUp();
bool IsTouching() const { bool IsTouching() const {
return info.touching; return info.touching;
@ -34,16 +34,13 @@ namespace Pinetime {
} }
Drivers::Cst816S::Gestures GestureGet(); Drivers::Cst816S::Gestures GestureGet();
private: private:
static void Process(void* instance);
void Work();
Pinetime::Drivers::Cst816S::TouchInfos info; Pinetime::Drivers::Cst816S::TouchInfos info;
Pinetime::System::SystemTask* systemTask = nullptr;
TaskHandle_t taskHandle;
Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Components::LittleVgl& lvgl; Pinetime::Components::LittleVgl& lvgl;
Pinetime::Drivers::Cst816S::Gestures gesture; Pinetime::Drivers::Cst816S::Gestures gesture;
bool isCancelled = false; bool isCancelled = false;
bool slideReleased = true;
}; };
} }
} }