1
0
Fork 0

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,15 +176,12 @@ 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.
* This method disable and re-enable the peripheral so that it works again. * This method disable and re-enable the peripheral so that it works again.

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,38 +18,37 @@ 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)) {
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(); info = touchPanel.GetTouchInfo();
if (info.isValid) { if (!info.isValid) {
return false;
}
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) { if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
if (slideReleased) { if (slideReleased) {
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown || if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp || info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) { info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
if (info.touching) {
gesture = info.gesture;
slideReleased = false; slideReleased = false;
} }
} else {
gesture = info.gesture; gesture = info.gesture;
} }
} }
}
if (!systemTask->IsSleeping()) { if (!info.touching) {
slideReleased = true;
}
return true;
}
void TouchHandler::UpdateLvglTouchPoint() {
if (info.touching) { if (info.touching) {
if (!isCancelled) { if (!isCancelled) {
lvgl.SetNewTouchPoint(info.x, info.y, true); lvgl.SetNewTouchPoint(info.x, info.y, true);
@ -61,18 +60,5 @@ void TouchHandler::Work() {
} else { } else {
lvgl.SetNewTouchPoint(info.x, info.y, false); 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);
}

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