Skip to content

Commit

Permalink
Improve the lock and the code
Browse files Browse the repository at this point in the history
  • Loading branch information
tgc-dk committed May 31, 2023
1 parent afa3393 commit f9e9a4f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
26 changes: 16 additions & 10 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ void SystemTask::Work() {
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
(gesture == Pinetime::Applications::TouchEvents::Tap &&
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
touchHandler.SetIfButtonUnlocksIgnoreTouch(true);
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction);
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction, true);
GoToRunning();
}
}
Expand All @@ -254,6 +253,7 @@ void SystemTask::Work() {
case Messages::OnNewNotification:
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::On) {
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
} else {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
Expand All @@ -263,6 +263,7 @@ void SystemTask::Work() {
break;
case Messages::SetOffAlarm:
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
}
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
Expand All @@ -275,6 +276,7 @@ void SystemTask::Work() {
case Messages::BleFirmwareUpdateStarted:
doNotGoToSleep = true;
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
}
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
Expand All @@ -289,6 +291,7 @@ void SystemTask::Work() {
NRF_LOG_INFO("[systemtask] FS Started");
doNotGoToSleep = true;
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
}
// TODO add intent of fs access icon or something
Expand All @@ -313,8 +316,7 @@ void SystemTask::Work() {
case Messages::HandleButtonEvent: {
// if the IgnoreTouchPopup is active the first button event unlocks the device
if (!touchHandler.IsIgnoreTouchPopupHidden()) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button);
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button, false);
touchHandler.SetIgnoreTouchPopupHidden(true);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
} else {
Expand All @@ -323,8 +325,7 @@ void SystemTask::Work() {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
} else {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button);
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button, false);
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
if (IsSleeping()) {
fastWakeUpDone = true;
Expand Down Expand Up @@ -353,8 +354,8 @@ void SystemTask::Work() {
}

state = SystemTaskState::Sleeping;
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other);
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
// reset touch restrictions when going to sleep
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
break;
case Messages::OnNewDay:
// We might be sleeping (with TWI device disabled.
Expand All @@ -367,6 +368,7 @@ void SystemTask::Work() {
settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours &&
alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime);
}
Expand All @@ -378,6 +380,7 @@ void SystemTask::Work() {
settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours &&
alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime);
}
Expand All @@ -387,6 +390,7 @@ void SystemTask::Work() {
batteryController.ReadPowerState();
displayApp.PushMessage(Applications::Display::Messages::OnChargingEvent);
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
}
break;
Expand All @@ -398,6 +402,7 @@ void SystemTask::Work() {
break;
case Messages::OnPairing:
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other, false);
GoToRunning();
}
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowPairingKey);
Expand Down Expand Up @@ -460,8 +465,9 @@ void SystemTask::UpdateMotion() {
motionController.ShouldRaiseWake(state == SystemTaskState::Sleeping)) ||
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
motionController.ShouldShakeWake(settingsController.GetShakeThreshold()))) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction);
touchHandler.SetIfButtonUnlocksIgnoreTouch(true);
if (state == SystemTaskState::Sleeping) {
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction, true);
}
GoToRunning();
}
}
Expand Down
48 changes: 24 additions & 24 deletions src/touchhandler/TouchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ TouchHandler::TouchProcessReply TouchHandler::ProcessTouchInfo(Drivers::Cst816S:
return TouchHandler::TouchProcessReply::NoAction;
}

// Only a single gesture per touch
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
if (gestureReleased) {
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 ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) {
if (info.touching) {
gesture = ConvertGesture(info.gesture);
gestureReleased = false;
}
} else {
gesture = ConvertGesture(info.gesture);
}
}
}

if (!info.touching) {
gestureReleased = true;
}

currentTouchPoint = {info.x, info.y, info.touching};

// if the watch was just woken by touch and button must be used to unlock, ignore the first touch event which
// is the touch event that woke the watch. Otherwise the lock-popup will be displayed
if (buttonUnlocksOn && ignoreNextTouchEvent) {
Expand All @@ -49,30 +73,6 @@ TouchHandler::TouchProcessReply TouchHandler::ProcessTouchInfo(Drivers::Cst816S:
// if we get to here TouchEvents is allowed and the "ButtonUnlocks" requirement can be overridden
wokenBy = WokenBy::Other;

// Only a single gesture per touch
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
if (gestureReleased) {
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 ||
info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) {
if (info.touching) {
gesture = ConvertGesture(info.gesture);
gestureReleased = false;
}
} else {
gesture = ConvertGesture(info.gesture);
}
}
}

if (!info.touching) {
gestureReleased = true;
}

currentTouchPoint = {info.x, info.y, info.touching};

return TouchHandler::TouchProcessReply::TouchEvent;
} else {
return TouchHandler::TouchProcessReply::IgnoreTouchPopup;
Expand Down
7 changes: 2 additions & 5 deletions src/touchhandler/TouchHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ namespace Pinetime {
return currentTouchPoint.y;
}

void SetIfButtonUnlocksIgnoreTouch(bool ignore) {
ignoreNextTouchEvent = ignore;
}

void SetIgnoreTouchPopupHidden(bool hidden) {
ignoreTouchPopupHidden = hidden;
}
Expand All @@ -50,8 +46,9 @@ namespace Pinetime {
return ignoreTouchPopupHidden;
}

void SetWokenBy(WokenBy woken) {
void SetWokenBy(WokenBy woken, bool ifButtonUnlocksIgnoreTouch) {
wokenBy = woken;
ignoreNextTouchEvent = ifButtonUnlocksIgnoreTouch;
}

Pinetime::Applications::TouchEvents GestureGet();
Expand Down

0 comments on commit f9e9a4f

Please sign in to comment.