Skip to content

Commit 309dd05

Browse files
committed
Implement a restricted clock-only-mode when not woken with the button. Trying new branch...
1 parent e823c8e commit 309dd05

File tree

8 files changed

+71
-11
lines changed

8 files changed

+71
-11
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ list(APPEND SOURCE_FILES
408408
displayapp/widgets/Counter.cpp
409409
displayapp/widgets/PageIndicator.cpp
410410
displayapp/widgets/StatusIcons.cpp
411+
displayapp/widgets/PopupMessage.cpp
411412

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

src/components/settings/Settings.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Pinetime {
1616
DoubleTap = 1,
1717
RaiseWrist = 2,
1818
Shake = 3,
19+
ButtonUnlocks = 4,
1920
};
2021
enum class Colors : uint8_t {
2122
White,
@@ -213,7 +214,7 @@ namespace Pinetime {
213214
}
214215
};
215216

216-
std::bitset<4> getWakeUpModes() const {
217+
std::bitset<5> getWakeUpModes() const {
217218
return settings.wakeUpMode;
218219
}
219220

@@ -254,7 +255,7 @@ namespace Pinetime {
254255
private:
255256
Pinetime::Controllers::FS& fs;
256257

257-
static constexpr uint32_t settingsVersion = 0x0004;
258+
static constexpr uint32_t settingsVersion = 0x0005;
258259
struct SettingsData {
259260
uint32_t version = settingsVersion;
260261
uint32_t stepsGoal = 10000;
@@ -270,7 +271,7 @@ namespace Pinetime {
270271

271272
WatchFaceInfineat watchFaceInfineat;
272273

273-
std::bitset<4> wakeUpMode {0};
274+
std::bitset<5> wakeUpMode {0};
274275
uint16_t shakeWakeThreshold = 150;
275276
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
276277
};

src/displayapp/DisplayApp.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
9393
alarmController {alarmController},
9494
brightnessController {brightnessController},
9595
touchHandler {touchHandler},
96-
filesystem {filesystem} {
96+
filesystem {filesystem},
97+
popupMessage {"Touch input\nis ignored,\npush button\nto unlock."} {
9798
}
9899

99100
void DisplayApp::Start(System::BootErrors error) {
@@ -277,6 +278,12 @@ void DisplayApp::Refresh() {
277278
case Messages::Clock:
278279
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
279280
break;
281+
case Messages::ShowIgnoreTouchPopup:
282+
popupMessage.SetHidden(false);
283+
break;
284+
case Messages::HideIgnoreTouchPopup:
285+
popupMessage.SetHidden(true);
286+
break;
280287
}
281288
}
282289

src/displayapp/DisplayApp.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "components/timer/TimerController.h"
1717
#include "components/alarm/AlarmController.h"
1818
#include "touchhandler/TouchHandler.h"
19+
#include "displayapp/widgets/PopupMessage.h"
1920

2021
#include "displayapp/Messages.h"
2122
#include "BootErrors.h"
@@ -95,6 +96,8 @@ namespace Pinetime {
9596

9697
Pinetime::Controllers::FirmwareValidator validator;
9798

99+
Pinetime::Applications::Widgets::PopupMessage popupMessage;
100+
98101
TaskHandle_t taskHandle;
99102

100103
States state = States::Running;

src/displayapp/Messages.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace Pinetime {
2222
ShowPairingKey,
2323
AlarmTriggered,
2424
Clock,
25-
BleRadioEnableToggle
25+
BleRadioEnableToggle,
26+
ShowIgnoreTouchPopup,
27+
HideIgnoreTouchPopup
2628
};
2729
}
2830
}

src/displayapp/screens/settings/SettingWakeUp.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
2424
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
2525
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
2626

27-
lv_obj_set_pos(container1, 10, 60);
27+
lv_obj_set_pos(container1, 10, 30);
2828
lv_obj_set_width(container1, LV_HOR_RES - 20);
29-
lv_obj_set_height(container1, LV_VER_RES - 50);
29+
lv_obj_set_height(container1, LV_VER_RES - 40);
3030
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
3131

3232
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
@@ -73,6 +73,15 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
7373
lv_checkbox_set_checked(cbOption[optionsTotal], true);
7474
}
7575
optionsTotal++;
76+
77+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
78+
lv_checkbox_set_text_static(cbOption[optionsTotal], "Button Unlock");
79+
cbOption[optionsTotal]->user_data = this;
80+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
81+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks)) {
82+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
83+
}
84+
optionsTotal++;
7685
}
7786

7887
SettingWakeUp::~SettingWakeUp() {

src/systemtask/SystemTask.cpp

+32-4
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,16 @@ void SystemTask::Work() {
257257
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
258258
(gesture == Pinetime::Applications::TouchEvents::Tap &&
259259
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
260+
ignoreNextTouchEvent = true;
261+
wokenBy = WokenBy::WakeUpAction;
260262
GoToRunning();
261263
}
262264
}
263265
break;
264266
}
265267
case Messages::GoToSleep:
268+
ignoreTouchPopupHidden = true;
269+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
266270
if (doNotGoToSleep) {
267271
break;
268272
}
@@ -341,18 +345,40 @@ void SystemTask::Work() {
341345
// TODO add intent of fs access icon or something
342346
break;
343347
case Messages::OnTouchEvent:
344-
if (touchHandler.GetNewTouchInfo()) {
345-
touchHandler.UpdateLvglTouchPoint();
348+
// if the watch was just woken by touch and button must be used to unlock, ignore the first touch event which
349+
// is the touch event that woke the watch. Otherwise the lock-popup will be displayed
350+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks) && ignoreNextTouchEvent) {
351+
ignoreNextTouchEvent = false;
352+
353+
// Ignore touchevents if ButtonUnlocks setting is active and the watch was woken with wakeup actions (touch etc)
354+
} else if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks) ||
355+
wokenBy != WokenBy::WakeUpAction) {
356+
if (touchHandler.GetNewTouchInfo()) {
357+
touchHandler.UpdateLvglTouchPoint();
358+
}
359+
ReloadIdleTimer();
360+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
361+
// if we get to here TouchEvents is allowed and the "ButtonUnlocks" requirement can be overridden
362+
wokenBy = WokenBy::Other;
363+
} else {
364+
ignoreTouchPopupHidden = false;
365+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowIgnoreTouchPopup);
346366
}
347-
ReloadIdleTimer();
348-
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
349367
break;
350368
case Messages::HandleButtonEvent: {
369+
// if the IgnoreTouchPopup is active the first button event unlocks the device
370+
if (!ignoreTouchPopupHidden) {
371+
wokenBy = WokenBy::Button;
372+
ignoreTouchPopupHidden = true;
373+
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
374+
break;
375+
}
351376
Controllers::ButtonActions action;
352377
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
353378
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
354379
} else {
355380
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
381+
wokenBy = WokenBy::Button;
356382
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
357383
if (IsSleeping()) {
358384
fastWakeUpDone = true;
@@ -381,6 +407,7 @@ void SystemTask::Work() {
381407
}
382408

383409
state = SystemTaskState::Sleeping;
410+
wokenBy = WokenBy::Other;
384411
break;
385412
case Messages::OnNewDay:
386413
// We might be sleeping (with TWI device disabled.
@@ -491,6 +518,7 @@ void SystemTask::UpdateMotion() {
491518
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) ||
492519
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
493520
motionController.Should_ShakeWake(settingsController.GetShakeThreshold()))) {
521+
wokenBy = WokenBy::WakeUpAction;
494522
GoToRunning();
495523
}
496524
}

src/systemtask/SystemTask.h

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ namespace Pinetime {
5454
class SystemTask {
5555
public:
5656
enum class SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
57+
// Enum describes how the watch was woken:
58+
// * WakeUpAction: The actions selected in the wakeup settings, single/double tap, raise, shake
59+
// * Button: The hardware button
60+
// * Other: Other things that can wake the watch up, eg. apps and notifications.
61+
enum class WokenBy { WakeUpAction, Button, Other };
5762
SystemTask(Drivers::SpiMaster& spi,
5863
Drivers::St7789& lcd,
5964
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
@@ -127,6 +132,10 @@ namespace Pinetime {
127132
Pinetime::Controllers::ButtonHandler& buttonHandler;
128133
Pinetime::Controllers::NimbleController nimbleController;
129134

135+
WokenBy wokenBy;
136+
bool ignoreNextTouchEvent = false;
137+
bool ignoreTouchPopupHidden = true;
138+
130139
static void Process(void* instance);
131140
void Work();
132141
void ReloadIdleTimer();

0 commit comments

Comments
 (0)