Rework TouchHandler into not a task
This commit is contained in:
parent
7e92577c14
commit
8a694adb09
|
@ -12,7 +12,6 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
|
|||
}
|
||||
|
||||
void TwiMaster::Init() {
|
||||
sleeping = false;
|
||||
if(mutex == nullptr)
|
||||
mutex = xSemaphoreCreateBinary();
|
||||
|
||||
|
@ -177,14 +176,11 @@ void TwiMaster::Sleep() {
|
|||
nrf_gpio_cfg_default(6);
|
||||
nrf_gpio_cfg_default(7);
|
||||
NRF_LOG_INFO("[TWIMASTER] Sleep");
|
||||
sleeping = true;
|
||||
}
|
||||
|
||||
void TwiMaster::Wakeup() {
|
||||
if (sleeping) {
|
||||
Init();
|
||||
NRF_LOG_INFO("[TWIMASTER] Wakeup");
|
||||
}
|
||||
Init();
|
||||
NRF_LOG_INFO("[TWIMASTER] Wakeup");
|
||||
}
|
||||
|
||||
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
|
||||
|
|
|
@ -39,7 +39,6 @@ namespace Pinetime {
|
|||
uint8_t internalBuffer[maxDataSize + registerSize];
|
||||
uint32_t txStartedCycleCount = 0;
|
||||
static constexpr uint32_t HwFreezedDelay {161000};
|
||||
bool sleeping;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -166,8 +166,7 @@ Pinetime::System::SystemTask systemTask(spi,
|
|||
|
||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
if (pin == pinTouchIrq) {
|
||||
twiMaster.Wakeup();
|
||||
touchHandler.WakeUp();
|
||||
systemTask.OnTouchEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,9 +150,6 @@ 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);
|
||||
|
@ -244,6 +241,8 @@ void SystemTask::Work() {
|
|||
isDimmed = false;
|
||||
break;
|
||||
case Messages::TouchWakeUp: {
|
||||
twiMaster.Wakeup();
|
||||
touchHandler.GetNewTouchInfo();
|
||||
auto gesture = touchHandler.GestureGet();
|
||||
if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
|
||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
|
||||
|
@ -299,6 +298,9 @@ void SystemTask::Work() {
|
|||
xTimerStart(dimTimer, 0);
|
||||
break;
|
||||
case Messages::OnTouchEvent:
|
||||
if (touchHandler.GetNewTouchInfo()) {
|
||||
touchHandler.UpdateLvglTouchPoint();
|
||||
}
|
||||
ReloadIdleTimer();
|
||||
break;
|
||||
case Messages::OnButtonEvent:
|
||||
|
|
|
@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
|
|||
return returnGesture;
|
||||
}
|
||||
|
||||
void TouchHandler::Start() {
|
||||
if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
bool TouchHandler::GetNewTouchInfo() {
|
||||
info = touchPanel.GetTouchInfo();
|
||||
|
||||
if (!info.isValid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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.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) {
|
||||
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;
|
||||
gesture = info.gesture;
|
||||
slideReleased = false;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace Pinetime {
|
|||
public:
|
||||
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
|
||||
void CancelTap();
|
||||
bool GetNewTouchInfo();
|
||||
void UpdateLvglTouchPoint();
|
||||
void Register(Pinetime::System::SystemTask* systemTask);
|
||||
void Start();
|
||||
void WakeUp();
|
||||
|
||||
bool IsTouching() const {
|
||||
return info.touching;
|
||||
|
@ -34,16 +34,13 @@ namespace Pinetime {
|
|||
}
|
||||
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;
|
||||
bool slideReleased = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user