Skip to content

Commit 6f6d870

Browse files
committed
Refactor the original ignore-touch implementation to owrk on latest code
1 parent 020a7fd commit 6f6d870

File tree

11 files changed

+142
-42
lines changed

11 files changed

+142
-42
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ list(APPEND SOURCE_FILES
409409
displayapp/widgets/PageIndicator.cpp
410410
displayapp/widgets/DotIndicator.cpp
411411
displayapp/widgets/StatusIcons.cpp
412+
displayapp/widgets/PopupMessage.cpp
412413

413414
## Settings
414415
displayapp/screens/settings/QuickSettings.cpp

src/components/settings/Settings.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Pinetime {
1717
DoubleTap = 1,
1818
RaiseWrist = 2,
1919
Shake = 3,
20+
ButtonUnlocks = 4,
2021
};
2122
enum class Colors : uint8_t {
2223
White,
@@ -226,7 +227,7 @@ namespace Pinetime {
226227
}
227228
};
228229

229-
std::bitset<4> getWakeUpModes() const {
230+
std::bitset<5> getWakeUpModes() const {
230231
return settings.wakeUpMode;
231232
}
232233

@@ -267,7 +268,7 @@ namespace Pinetime {
267268
private:
268269
Pinetime::Controllers::FS& fs;
269270

270-
static constexpr uint32_t settingsVersion = 0x0004;
271+
static constexpr uint32_t settingsVersion = 0x0005;
271272

272273
struct SettingsData {
273274
uint32_t version = settingsVersion;
@@ -284,7 +285,7 @@ namespace Pinetime {
284285

285286
WatchFaceInfineat watchFaceInfineat;
286287

287-
std::bitset<4> wakeUpMode {0};
288+
std::bitset<5> wakeUpMode {0};
288289
uint16_t shakeWakeThreshold = 150;
289290
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
290291
};

src/displayapp/DisplayApp.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
9595
touchHandler {touchHandler},
9696
filesystem {filesystem},
9797
lvgl {lcd, filesystem},
98-
timer(this, TimerCallback) {
98+
timer(this, TimerCallback),
99+
popupMessage {"Touch input\nis ignored,\npush button\nto unlock."} {
99100
}
100101

101102
void DisplayApp::Start(System::BootErrors error) {
@@ -363,6 +364,12 @@ void DisplayApp::Refresh() {
363364
RestoreBrightness();
364365
motorController.RunForDuration(15);
365366
break;
367+
case Messages::ShowIgnoreTouchPopup:
368+
popupMessage.SetHidden(false);
369+
break;
370+
case Messages::HideIgnoreTouchPopup:
371+
popupMessage.SetHidden(true);
372+
break;
366373
}
367374
}
368375

src/displayapp/DisplayApp.h

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "components/timer/Timer.h"
1616
#include "components/alarm/AlarmController.h"
1717
#include "touchhandler/TouchHandler.h"
18+
#include "displayapp/widgets/PopupMessage.h"
1819

1920
#include "displayapp/Messages.h"
2021
#include "BootErrors.h"
@@ -96,6 +97,8 @@ namespace Pinetime {
9697
Pinetime::Components::LittleVgl lvgl;
9798
Pinetime::Controllers::Timer timer;
9899

100+
Pinetime::Applications::Widgets::PopupMessage popupMessage;
101+
99102
TaskHandle_t taskHandle;
100103

101104
States state = States::Running;

src/displayapp/Messages.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace Pinetime {
2424
Chime,
2525
BleRadioEnableToggle,
2626
OnChargingEvent,
27+
ShowIgnoreTouchPopup,
28+
HideIgnoreTouchPopup
2729
};
2830
}
2931
}

src/displayapp/screens/settings/SettingWakeUp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace Pinetime::Applications::Screens;
1010

11-
constexpr std::array<SettingWakeUp::Option, 4> SettingWakeUp::options;
11+
constexpr std::array<SettingWakeUp::Option, 5> SettingWakeUp::options;
1212

1313
namespace {
1414
void event_handler(lv_obj_t* obj, lv_event_t event) {
@@ -27,9 +27,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController
2727
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
2828
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
2929

30-
lv_obj_set_pos(container1, 10, 60);
30+
lv_obj_set_pos(container1, 10, 30);
3131
lv_obj_set_width(container1, LV_HOR_RES - 20);
32-
lv_obj_set_height(container1, LV_VER_RES - 50);
32+
lv_obj_set_height(container1, LV_VER_RES - 40);
3333
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
3434

3535
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);

src/displayapp/screens/settings/SettingWakeUp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace Pinetime {
2525
};
2626

2727
Controllers::Settings& settingsController;
28-
static constexpr std::array<Option, 4> options = {{
28+
static constexpr std::array<Option, 5> options = {{
2929
{Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"},
3030
{Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"},
3131
{Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"},
3232
{Controllers::Settings::WakeUpMode::Shake, "Shake Wake"},
33+
{Controllers::Settings::WakeUpMode::ButtonUnlocks, "Button Unlock"},
3334
}};
3435

3536
lv_obj_t* cbOption[options.size()];

src/systemtask/SystemTask.cpp

+41-13
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,26 @@ void SystemTask::Work() {
214214
state = SystemTaskState::Running;
215215
break;
216216
case Messages::TouchWakeUp: {
217-
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
217+
Pinetime::Controllers::TouchHandler::TouchProcessReply reply;
218+
reply = touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo(), settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks));
219+
if (reply == Pinetime::Controllers::TouchHandler::TouchProcessReply::TouchEvent) {
218220
auto gesture = touchHandler.GestureGet();
219221
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep &&
220222
gesture != Pinetime::Applications::TouchEvents::None &&
221223
((gesture == Pinetime::Applications::TouchEvents::DoubleTap &&
222224
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
223225
(gesture == Pinetime::Applications::TouchEvents::Tap &&
224226
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
227+
touchHandler.SetIfButtonUnlocksIgnoreTouch(true);
228+
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction);
225229
GoToRunning();
226230
}
227231
}
228232
break;
229233
}
230234
case Messages::GoToSleep:
235+
touchHandler.SetIgnoreTouchPopupHidden(true);
236+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
231237
if (doNotGoToSleep) {
232238
break;
233239
}
@@ -291,24 +297,42 @@ void SystemTask::Work() {
291297
// TODO add intent of fs access icon or something
292298
break;
293299
case Messages::OnTouchEvent:
294-
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
300+
Pinetime::Controllers::TouchHandler::TouchProcessReply reply;
301+
reply = touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo(), settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks));
302+
NRF_LOG_INFO("[systemtask] OnTouchEvent, reply %d", reply);
303+
304+
if (reply == Pinetime::Controllers::TouchHandler::TouchProcessReply::TouchEvent) {
295305
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
306+
} else if (reply == Pinetime::Controllers::TouchHandler::TouchProcessReply::IgnoreTouchPopup) {
307+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowIgnoreTouchPopup);
308+
touchHandler.SetIgnoreTouchPopupHidden(false);
296309
}
297310
break;
298311
case Messages::HandleButtonEvent: {
299-
Controllers::ButtonActions action = Controllers::ButtonActions::None;
300-
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
301-
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
302-
} else {
303-
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
304-
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
305-
if (IsSleeping()) {
306-
fastWakeUpDone = true;
307-
GoToRunning();
308-
break;
312+
// if the IgnoreTouchPopup is active the first button event unlocks the device
313+
if (!touchHandler.IsIgnoreTouchPopupHidden()) {
314+
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button);
315+
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
316+
touchHandler.SetIgnoreTouchPopupHidden(true);
317+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
318+
}
319+
else {
320+
Controllers::ButtonActions action = Controllers::ButtonActions::None;
321+
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
322+
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
323+
} else {
324+
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
325+
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Button);
326+
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
327+
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
328+
if (IsSleeping()) {
329+
fastWakeUpDone = true;
330+
GoToRunning();
331+
break;
332+
}
309333
}
334+
HandleButtonAction(action);
310335
}
311-
HandleButtonAction(action);
312336
} break;
313337
case Messages::HandleButtonTimerEvent: {
314338
auto action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Timer);
@@ -328,6 +352,8 @@ void SystemTask::Work() {
328352
}
329353

330354
state = SystemTaskState::Sleeping;
355+
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::Other);
356+
touchHandler.SetIfButtonUnlocksIgnoreTouch(false);
331357
break;
332358
case Messages::OnNewDay:
333359
// We might be sleeping (with TWI device disabled.
@@ -433,6 +459,8 @@ void SystemTask::UpdateMotion() {
433459
motionController.ShouldRaiseWake(state == SystemTaskState::Sleeping)) ||
434460
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
435461
motionController.ShouldShakeWake(settingsController.GetShakeThreshold()))) {
462+
touchHandler.SetWokenBy(Pinetime::Controllers::TouchHandler::WokenBy::WakeUpAction);
463+
touchHandler.SetIfButtonUnlocksIgnoreTouch(true);
436464
GoToRunning();
437465
}
438466
}

src/systemtask/SystemTask.h

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ namespace Pinetime {
5353
class SystemTask {
5454
public:
5555
enum class SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
56+
// Enum describes how the watch was woken:
57+
// * WakeUpAction: The actions selected in the wakeup settings, single/double tap, raise, shake
58+
// * Button: The hardware button
59+
// * Other: Other things that can wake the watch up, eg. apps and notifications.
60+
enum class WokenBy { WakeUpAction, Button, Other };
5661
SystemTask(Drivers::SpiMaster& spi,
5762
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
5863
Drivers::TwiMaster& twiMaster,

src/touchhandler/TouchHandler.cpp

+37-20
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,51 @@ Pinetime::Applications::TouchEvents TouchHandler::GestureGet() {
3333
return returnGesture;
3434
}
3535

36-
bool TouchHandler::ProcessTouchInfo(Drivers::Cst816S::TouchInfos info) {
36+
TouchHandler::TouchProcessReply TouchHandler::ProcessTouchInfo(Drivers::Cst816S::TouchInfos info, bool buttonUnlocksOn) {
3737
if (!info.isValid) {
38-
return false;
38+
return TouchHandler::TouchProcessReply::NoAction;
3939
}
4040

41-
// Only a single gesture per touch
42-
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
43-
if (gestureReleased) {
44-
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
45-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
46-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
47-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight ||
48-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) {
49-
if (info.touching) {
41+
// if the watch was just woken by touch and button must be used to unlock, ignore the first touch event which
42+
// is the touch event that woke the watch. Otherwise the lock-popup will be displayed
43+
if (buttonUnlocksOn && ignoreNextTouchEvent) {
44+
ignoreNextTouchEvent = false;
45+
return TouchHandler::TouchProcessReply::NoAction;
46+
47+
} else if (!buttonUnlocksOn || wokenBy != WokenBy::WakeUpAction)
48+
{
49+
50+
// if we get to here TouchEvents is allowed and the "ButtonUnlocks" requirement can be overridden
51+
wokenBy = WokenBy::Other;
52+
53+
// Only a single gesture per touch
54+
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
55+
if (gestureReleased) {
56+
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
57+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
58+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
59+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight ||
60+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::LongPress) {
61+
if (info.touching) {
62+
gesture = ConvertGesture(info.gesture);
63+
gestureReleased = false;
64+
}
65+
} else {
5066
gesture = ConvertGesture(info.gesture);
51-
gestureReleased = false;
5267
}
53-
} else {
54-
gesture = ConvertGesture(info.gesture);
5568
}
5669
}
57-
}
5870

59-
if (!info.touching) {
60-
gestureReleased = true;
61-
}
71+
if (!info.touching) {
72+
gestureReleased = true;
73+
}
6274

63-
currentTouchPoint = {info.x, info.y, info.touching};
75+
currentTouchPoint = {info.x, info.y, info.touching};
6476

65-
return true;
77+
return TouchHandler::TouchProcessReply::TouchEvent;
78+
}
79+
else
80+
{
81+
return TouchHandler::TouchProcessReply::IgnoreTouchPopup;
82+
}
6683
}

src/touchhandler/TouchHandler.h

+36-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ namespace Pinetime {
66
namespace Controllers {
77
class TouchHandler {
88
public:
9+
// Enum describes how the watch was woken:
10+
// * WakeUpAction: The actions selected in the wakeup settings, single/double tap, raise, shake
11+
// * Button: The hardware button
12+
// * Other: Other things that can wake the watch up, eg. apps and notifications.
13+
enum class WokenBy { WakeUpAction, Button, Other };
14+
15+
// Enum describes how the reply from ProcessTouchInfo should be interpreted:
16+
// * NoAction: Do nothing, ignore input.
17+
// * TouchEvent: The input should be treated as a normal touch event.
18+
// * IgnoreTouchPopup: Show the popup for when ignoring touvh input.
19+
enum class TouchProcessReply { NoAction, TouchEvent, IgnoreTouchPopup };
20+
921
struct TouchPoint {
1022
int x;
1123
int y;
1224
bool touching;
1325
};
1426

15-
bool ProcessTouchInfo(Drivers::Cst816S::TouchInfos info);
27+
TouchProcessReply ProcessTouchInfo(Drivers::Cst816S::TouchInfos info, bool buttonUnlocksOn);
1628

1729
bool IsTouching() const {
1830
return currentTouchPoint.touching;
@@ -26,12 +38,35 @@ namespace Pinetime {
2638
return currentTouchPoint.y;
2739
}
2840

41+
void SetIfButtonUnlocksIgnoreTouch(bool ignore)
42+
{
43+
ignoreNextTouchEvent = ignore;
44+
}
45+
46+
void SetIgnoreTouchPopupHidden(bool hidden)
47+
{
48+
ignoreTouchPopupHidden = hidden;
49+
}
50+
bool IsIgnoreTouchPopupHidden()
51+
{
52+
return ignoreTouchPopupHidden;
53+
}
54+
55+
void SetWokenBy(WokenBy woken)
56+
{
57+
wokenBy = woken;
58+
}
59+
2960
Pinetime::Applications::TouchEvents GestureGet();
3061

3162
private:
3263
Pinetime::Applications::TouchEvents gesture;
3364
TouchPoint currentTouchPoint = {};
3465
bool gestureReleased = true;
66+
67+
WokenBy wokenBy;
68+
bool ignoreNextTouchEvent = false;
69+
bool ignoreTouchPopupHidden = true;
3570
};
3671
}
3772
}

0 commit comments

Comments
 (0)