Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a restricted clock-only-mode when not woken with the button #1359

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ list(APPEND SOURCE_FILES
displayapp/widgets/PageIndicator.cpp
displayapp/widgets/DotIndicator.cpp
displayapp/widgets/StatusIcons.cpp
displayapp/widgets/PopupMessage.cpp

## Settings
displayapp/screens/settings/QuickSettings.cpp
Expand Down
13 changes: 10 additions & 3 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ namespace Pinetime {
enum class WeatherFormat : uint8_t { Metric, Imperial };
enum class Notification : uint8_t { On, Off, Sleep };
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
Shake = 3,
LowerWrist = 4,
ButtonUnlocks = 5,
};
enum class Colors : uint8_t {
White,
Silver,
Expand Down Expand Up @@ -260,7 +267,7 @@ namespace Pinetime {
}
};

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

Expand Down Expand Up @@ -321,7 +328,7 @@ namespace Pinetime {

WatchFaceInfineat watchFaceInfineat;

std::bitset<5> wakeUpMode {0};
std::bitset<6> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;

Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
Expand Down
8 changes: 7 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ void DisplayApp::Refresh() {
case Messages::OnChargingEvent:
motorController.RunForDuration(15);
break;
case Messages::ShowIgnoreTouchPopup:
popupMessage.SetHidden(false);
break;
case Messages::HideIgnoreTouchPopup:
popupMessage.SetHidden(true);
break;
}
}

Expand Down Expand Up @@ -579,7 +585,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::SettingWeatherFormat>(settingsController);
break;
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
currentScreen = std::make_unique<Screens::SettingWakeUp>(this, settingsController);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(settingsController);
Expand Down
3 changes: 3 additions & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "components/timer/Timer.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 @@ -102,8 +103,10 @@ namespace Pinetime {
Pinetime::Controllers::FirmwareValidator validator;
Pinetime::Components::LittleVgl lvgl;
Pinetime::Controllers::Timer timer;
Pinetime::Applications::Widgets::PopupMessage popupMessage;

AppControllers controllers;

TaskHandle_t taskHandle;

States state = States::Running;
Expand Down
2 changes: 2 additions & 0 deletions src/displayapp/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace Pinetime {
Chime,
BleRadioEnableToggle,
OnChargingEvent,
ShowIgnoreTouchPopup,
HideIgnoreTouchPopup
};
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/displayapp/screens/Page.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <cstdint>
#include <lvgl/lvgl.h>
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/PageIndicator.h"

namespace Pinetime {

namespace Applications {
namespace Screens {

class Page : public Screen {
public:
Page(uint8_t screenID, uint8_t numScreens, lv_obj_t* contentObj) : contentObj {contentObj}, pageIndicator(screenID, numScreens) {
pageIndicator.Create();
}

~Page() override {
lv_obj_clean(lv_scr_act());
}

private:
lv_obj_t* contentObj = nullptr;
Widgets::PageIndicator pageIndicator;
};
}
}
}
46 changes: 38 additions & 8 deletions src/displayapp/screens/settings/SettingWakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@

using namespace Pinetime::Applications::Screens;

constexpr std::array<SettingWakeUp::Option, 5> SettingWakeUp::options;
constexpr std::array<SettingWakeUp::Option, SettingWakeUp::numOptions> SettingWakeUp::options;

auto SettingWakeUp::CreateScreenList() {
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
for (size_t i = 0; i < screens.size(); i++) {
screens[i] = [this, i]() -> std::unique_ptr<Screen> {
return CreateScreen(i);
};
}
return screens;
}

namespace {
void event_handler(lv_obj_t* obj, lv_event_t event) {
Expand All @@ -19,7 +29,16 @@ namespace {
}
}

SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} {
SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: settingsController {settingsController}, screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} {
}

SettingWakeUp::~SettingWakeUp() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

std::unique_ptr<Screen> SettingWakeUp::CreateScreen(size_t screenNum) {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);

lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
Expand All @@ -43,20 +62,29 @@ SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

for (unsigned int i = 0; i < options.size(); i++) {
// cleanup any old pointers
cbOption.fill(nullptr);

// only loop as far as the list size aĺlows
unsigned int loopMax = screenNum * optionsPerScreen + optionsPerScreen;
if (loopMax > options.size()) {
loopMax = options.size();
}

for (unsigned int i = screenNum * optionsPerScreen; i < loopMax; i++) {
cbOption[i] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbOption[i], options[i].name);
if (settingsController.isWakeUpModeOn(static_cast<Controllers::Settings::WakeUpMode>(i))) {
if (settingsController.isWakeUpModeOn(options[i].wakeUpMode)) {
lv_checkbox_set_checked(cbOption[i], true);
}
cbOption[i]->user_data = this;
lv_obj_set_event_cb(cbOption[i], event_handler);
}
return std::make_unique<Screens::Page>(screenNum, nScreens, container1);
}

SettingWakeUp::~SettingWakeUp() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
bool SettingWakeUp::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screens.OnTouchEvent(event);
}

void SettingWakeUp::UpdateSelected(lv_obj_t* object) {
Expand All @@ -74,6 +102,8 @@ void SettingWakeUp::UpdateSelected(lv_obj_t* object) {
// for example, when setting SingleTap, DoubleTap is unset and vice versa.
auto modes = settingsController.getWakeUpModes();
for (size_t i = 0; i < options.size(); ++i) {
lv_checkbox_set_checked(cbOption[i], modes[i]);
if (cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], modes[i]);
}
}
}
22 changes: 19 additions & 3 deletions src/displayapp/screens/settings/SettingWakeUp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <cstdint>
#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Page.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/ScreenList.h"
#include "displayapp/widgets/PageIndicator.h"

namespace Pinetime {

Expand All @@ -13,27 +16,40 @@ namespace Pinetime {

class SettingWakeUp : public Screen {
public:
SettingWakeUp(Pinetime::Controllers::Settings& settingsController);
SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingWakeUp() override;

void UpdateSelected(lv_obj_t* object);

bool OnTouchEvent(TouchEvents event) override;

private:
auto CreateScreenList();
std::unique_ptr<Screen> CreateScreen(size_t screenNum);

struct Option {
Controllers::Settings::WakeUpMode wakeUpMode;
const char* name;
};

static constexpr size_t numOptions = 6;
static constexpr size_t optionsPerScreen = 4;
static constexpr size_t nScreens = 2;

Controllers::Settings& settingsController;
static constexpr std::array<Option, 5> options = {{

ScreenList<nScreens> screens;

static constexpr std::array<Option, numOptions> options = {{
{Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"},
{Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"},
{Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"},
{Controllers::Settings::WakeUpMode::Shake, "Shake Wake"},
{Controllers::Settings::WakeUpMode::LowerWrist, "Lower Wrist"},
{Controllers::Settings::WakeUpMode::ButtonUnlocks, "Button Unlock"},
}};

lv_obj_t* cbOption[options.size()];
std::array<lv_obj_t*, numOptions> cbOption;
};
}
}
Expand Down
56 changes: 56 additions & 0 deletions src/displayapp/widgets/PopupMessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "displayapp/widgets/PopupMessage.h"
#include "displayapp/InfiniTimeTheme.h"
#include <libraries/log/nrf_log.h>

using namespace Pinetime::Applications::Widgets;

PopupMessage::PopupMessage() {
}

void PopupMessage::Create() {
popup = lv_obj_create(lv_scr_act(), nullptr);
lv_obj_set_size(popup, 90, 90);
lv_obj_align(popup, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_local_bg_color(popup, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
lv_obj_set_style_local_bg_opa(popup, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_60);
lv_obj_t* lockBody = lv_obj_create(popup, nullptr);
lv_obj_set_size(lockBody, 55, 50);
lv_obj_align(lockBody, popup, LV_ALIGN_CENTER, 0, 10);

lv_obj_set_style_local_bg_color(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_bg_opa(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);
lv_obj_set_style_local_border_color(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_border_width(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 22);
lv_obj_set_style_local_border_side(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
lv_obj_set_style_local_border_opa(lockBody, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);

lv_obj_t* lockTop = lv_obj_create(popup, nullptr);
lv_obj_set_size(lockTop, 30, 35);
lv_obj_align(lockTop, popup, LV_ALIGN_CENTER, 0, -20);
lv_obj_set_style_local_bg_color(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_bg_opa(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);
lv_obj_set_style_local_border_color(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_border_width(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 6);
lv_obj_set_style_local_border_side(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
lv_obj_set_style_local_border_opa(lockTop, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);

lv_obj_set_hidden(popup, isHidden);
}

void PopupMessage::SetHidden(bool hidden) {
if (isHidden == hidden) {
return;
}
isHidden = hidden;
// create/delete on demand
if (popup == nullptr && !isHidden) {
Create();
} else if (popup != nullptr) {
lv_obj_del(popup);
popup = nullptr;
}
}

bool PopupMessage::IsHidden() {
return isHidden;
}
20 changes: 20 additions & 0 deletions src/displayapp/widgets/PopupMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <lvgl/lvgl.h>

namespace Pinetime {
namespace Applications {
namespace Widgets {
class PopupMessage {
public:
PopupMessage();
void Create();
void SetHidden(bool hidden);
bool IsHidden();

private:
lv_obj_t* popup = nullptr;
bool isHidden = true;
};
}
}
}
Loading
Loading