Skip to content

Commit

Permalink
Implement a restricted clock-only-mode when not woken with the button…
Browse files Browse the repository at this point in the history
…. Trying new branch...
  • Loading branch information
tgc-dk committed May 2, 2023
1 parent e823c8e commit 309dd05
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ list(APPEND SOURCE_FILES
displayapp/widgets/Counter.cpp
displayapp/widgets/PageIndicator.cpp
displayapp/widgets/StatusIcons.cpp
displayapp/widgets/PopupMessage.cpp

## Settings
displayapp/screens/settings/QuickSettings.cpp
Expand Down
7 changes: 4 additions & 3 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Pinetime {
DoubleTap = 1,
RaiseWrist = 2,
Shake = 3,
ButtonUnlocks = 4,
};
enum class Colors : uint8_t {
White,
Expand Down Expand Up @@ -213,7 +214,7 @@ namespace Pinetime {
}
};

std::bitset<4> getWakeUpModes() const {
std::bitset<5> getWakeUpModes() const {
return settings.wakeUpMode;
}

Expand Down Expand Up @@ -254,7 +255,7 @@ namespace Pinetime {
private:
Pinetime::Controllers::FS& fs;

static constexpr uint32_t settingsVersion = 0x0004;
static constexpr uint32_t settingsVersion = 0x0005;
struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
Expand All @@ -270,7 +271,7 @@ namespace Pinetime {

WatchFaceInfineat watchFaceInfineat;

std::bitset<4> wakeUpMode {0};
std::bitset<5> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
};
Expand Down
9 changes: 8 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
alarmController {alarmController},
brightnessController {brightnessController},
touchHandler {touchHandler},
filesystem {filesystem} {
filesystem {filesystem},
popupMessage {"Touch input\nis ignored,\npush button\nto unlock."} {
}

void DisplayApp::Start(System::BootErrors error) {
Expand Down Expand Up @@ -277,6 +278,12 @@ void DisplayApp::Refresh() {
case Messages::Clock:
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
break;
case Messages::ShowIgnoreTouchPopup:
popupMessage.SetHidden(false);
break;
case Messages::HideIgnoreTouchPopup:
popupMessage.SetHidden(true);
break;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "components/timer/TimerController.h"
#include "components/alarm/AlarmController.h"
#include "touchhandler/TouchHandler.h"
#include "displayapp/widgets/PopupMessage.h"

#include "displayapp/Messages.h"
#include "BootErrors.h"
Expand Down Expand Up @@ -95,6 +96,8 @@ namespace Pinetime {

Pinetime::Controllers::FirmwareValidator validator;

Pinetime::Applications::Widgets::PopupMessage popupMessage;

TaskHandle_t taskHandle;

States state = States::Running;
Expand Down
4 changes: 3 additions & 1 deletion src/displayapp/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace Pinetime {
ShowPairingKey,
AlarmTriggered,
Clock,
BleRadioEnableToggle
BleRadioEnableToggle,
ShowIgnoreTouchPopup,
HideIgnoreTouchPopup
};
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/displayapp/screens/settings/SettingWakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

lv_obj_set_pos(container1, 10, 60);
lv_obj_set_pos(container1, 10, 30);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
lv_obj_set_height(container1, LV_VER_RES - 40);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
Expand Down Expand Up @@ -73,6 +73,15 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;

cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], "Button Unlock");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks)) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
}

SettingWakeUp::~SettingWakeUp() {
Expand Down
36 changes: 32 additions & 4 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,16 @@ void SystemTask::Work() {
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
(gesture == Pinetime::Applications::TouchEvents::Tap &&
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
ignoreNextTouchEvent = true;
wokenBy = WokenBy::WakeUpAction;
GoToRunning();
}
}
break;
}
case Messages::GoToSleep:
ignoreTouchPopupHidden = true;
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
if (doNotGoToSleep) {
break;
}
Expand Down Expand Up @@ -341,18 +345,40 @@ void SystemTask::Work() {
// TODO add intent of fs access icon or something
break;
case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) {
touchHandler.UpdateLvglTouchPoint();
// 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 (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks) && ignoreNextTouchEvent) {
ignoreNextTouchEvent = false;

// Ignore touchevents if ButtonUnlocks setting is active and the watch was woken with wakeup actions (touch etc)
} else if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::ButtonUnlocks) ||
wokenBy != WokenBy::WakeUpAction) {
if (touchHandler.GetNewTouchInfo()) {
touchHandler.UpdateLvglTouchPoint();
}
ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
// if we get to here TouchEvents is allowed and the "ButtonUnlocks" requirement can be overridden
wokenBy = WokenBy::Other;
} else {
ignoreTouchPopupHidden = false;
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowIgnoreTouchPopup);
}
ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::HandleButtonEvent: {
// if the IgnoreTouchPopup is active the first button event unlocks the device
if (!ignoreTouchPopupHidden) {
wokenBy = WokenBy::Button;
ignoreTouchPopupHidden = true;
displayApp.PushMessage(Pinetime::Applications::Display::Messages::HideIgnoreTouchPopup);
break;
}
Controllers::ButtonActions action;
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
} else {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
wokenBy = WokenBy::Button;
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
if (IsSleeping()) {
fastWakeUpDone = true;
Expand Down Expand Up @@ -381,6 +407,7 @@ void SystemTask::Work() {
}

state = SystemTaskState::Sleeping;
wokenBy = WokenBy::Other;
break;
case Messages::OnNewDay:
// We might be sleeping (with TWI device disabled.
Expand Down Expand Up @@ -491,6 +518,7 @@ void SystemTask::UpdateMotion() {
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) ||
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
motionController.Should_ShakeWake(settingsController.GetShakeThreshold()))) {
wokenBy = WokenBy::WakeUpAction;
GoToRunning();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/systemtask/SystemTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ namespace Pinetime {
class SystemTask {
public:
enum class SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
// Enum describes how the watch was woken:
// * WakeUpAction: The actions selected in the wakeup settings, single/double tap, raise, shake
// * Button: The hardware button
// * Other: Other things that can wake the watch up, eg. apps and notifications.
enum class WokenBy { WakeUpAction, Button, Other };
SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
Expand Down Expand Up @@ -127,6 +132,10 @@ namespace Pinetime {
Pinetime::Controllers::ButtonHandler& buttonHandler;
Pinetime::Controllers::NimbleController nimbleController;

WokenBy wokenBy;
bool ignoreNextTouchEvent = false;
bool ignoreTouchPopupHidden = true;

static void Process(void* instance);
void Work();
void ReloadIdleTimer();
Expand Down

0 comments on commit 309dd05

Please sign in to comment.