Add sleep mode which disables notifications, touch- and motion wakeup (#1261)
This commit is contained in:
parent
62c4ff9c2d
commit
69563ed031
|
@ -9,7 +9,7 @@ namespace Pinetime {
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
enum class ClockType : uint8_t { H24, H12 };
|
enum class ClockType : uint8_t { H24, H12 };
|
||||||
enum class Notification : uint8_t { ON, OFF };
|
enum class Notification : uint8_t { On, Off, Sleep };
|
||||||
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
|
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
|
||||||
enum class WakeUpMode : uint8_t {
|
enum class WakeUpMode : uint8_t {
|
||||||
SingleTap = 0,
|
SingleTap = 0,
|
||||||
|
@ -219,7 +219,7 @@ namespace Pinetime {
|
||||||
uint32_t screenTimeOut = 15000;
|
uint32_t screenTimeOut = 15000;
|
||||||
|
|
||||||
ClockType clockType = ClockType::H24;
|
ClockType clockType = ClockType::H24;
|
||||||
Notification notificationStatus = Notification::ON;
|
Notification notificationStatus = Notification::On;
|
||||||
|
|
||||||
uint8_t clockFace = 0;
|
uint8_t clockFace = 0;
|
||||||
ChimesOption chimesOption = ChimesOption::None;
|
ChimesOption chimesOption = ChimesOption::None;
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
"sources": [
|
"sources": [
|
||||||
{
|
{
|
||||||
"file": "material-design-icons/MaterialIcons-Regular.ttf",
|
"file": "material-design-icons/MaterialIcons-Regular.ttf",
|
||||||
"range": "0xf00b, 0xe3aa-0xe3ac, 0xe7f6-0xe7f7, 0xe8b8"
|
"range": "0xf00b, 0xe3aa-0xe3ac, 0xe7f6-0xe7f7, 0xe8b8, 0xef44"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bpp": 1,
|
"bpp": 1,
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace Pinetime {
|
||||||
static constexpr const char* chartLine = "\xEF\x88\x81";
|
static constexpr const char* chartLine = "\xEF\x88\x81";
|
||||||
static constexpr const char* eye = "\xEF\x81\xAE";
|
static constexpr const char* eye = "\xEF\x81\xAE";
|
||||||
static constexpr const char* home = "\xEF\x80\x95";
|
static constexpr const char* home = "\xEF\x80\x95";
|
||||||
|
static constexpr const char* sleep = "\xEE\xBD\x84";
|
||||||
|
|
||||||
// lv_font_sys_48.c
|
// lv_font_sys_48.c
|
||||||
static constexpr const char* settings = "\xEE\xA2\xB8";
|
static constexpr const char* settings = "\xEE\xA2\xB8";
|
||||||
|
|
|
@ -10,13 +10,21 @@ using namespace Pinetime::Applications::Screens;
|
||||||
namespace {
|
namespace {
|
||||||
void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||||
auto* screen = static_cast<QuickSettings*>(obj->user_data);
|
auto* screen = static_cast<QuickSettings*>(obj->user_data);
|
||||||
screen->OnButtonEvent(obj, event);
|
if (event == LV_EVENT_CLICKED) {
|
||||||
|
screen->OnButtonEvent(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_update_task(struct _lv_task_t* task) {
|
void lv_update_task(struct _lv_task_t* task) {
|
||||||
auto* user_data = static_cast<QuickSettings*>(task->user_data);
|
auto* user_data = static_cast<QuickSettings*>(task->user_data);
|
||||||
user_data->UpdateScreen();
|
user_data->UpdateScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ButtonState : lv_state_t {
|
||||||
|
NotificationsOn = LV_STATE_CHECKED,
|
||||||
|
NotificationsOff = LV_STATE_DEFAULT,
|
||||||
|
Sleep = 0x40,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||||
|
@ -79,19 +87,24 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||||
btn3 = lv_btn_create(lv_scr_act(), nullptr);
|
btn3 = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
btn3->user_data = this;
|
btn3->user_data = this;
|
||||||
lv_obj_set_event_cb(btn3, ButtonEventHandler);
|
lv_obj_set_event_cb(btn3, ButtonEventHandler);
|
||||||
lv_btn_set_checkable(btn3, true);
|
|
||||||
lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style);
|
lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style);
|
||||||
|
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast<lv_state_t>(ButtonState::NotificationsOff), LV_COLOR_RED);
|
||||||
|
static constexpr lv_color_t violet = LV_COLOR_MAKE(0x60, 0x00, 0xff);
|
||||||
|
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast<lv_state_t>(ButtonState::Sleep), violet);
|
||||||
lv_obj_set_size(btn3, buttonWidth, buttonHeight);
|
lv_obj_set_size(btn3, buttonWidth, buttonHeight);
|
||||||
lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, buttonXOffset, 0);
|
lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, buttonXOffset, 0);
|
||||||
|
|
||||||
btn3_lvl = lv_label_create(btn3, nullptr);
|
btn3_lvl = lv_label_create(btn3, nullptr);
|
||||||
lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
||||||
|
|
||||||
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::ON) {
|
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) {
|
||||||
lv_obj_add_state(btn3, LV_STATE_CHECKED);
|
|
||||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
||||||
} else {
|
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOn));
|
||||||
|
} else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) {
|
||||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
||||||
|
} else {
|
||||||
|
lv_label_set_text_static(btn3_lvl, Symbols::sleep);
|
||||||
|
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::Sleep));
|
||||||
}
|
}
|
||||||
|
|
||||||
btn4 = lv_btn_create(lv_scr_act(), nullptr);
|
btn4 = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
@ -122,31 +135,33 @@ void QuickSettings::UpdateScreen() {
|
||||||
statusIcons.Update();
|
statusIcons.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
void QuickSettings::OnButtonEvent(lv_obj_t* object) {
|
||||||
if (object == btn2 && event == LV_EVENT_CLICKED) {
|
if (object == btn2) {
|
||||||
|
|
||||||
running = false;
|
|
||||||
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up);
|
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up);
|
||||||
|
} else if (object == btn1) {
|
||||||
} else if (object == btn1 && event == LV_EVENT_CLICKED) {
|
|
||||||
|
|
||||||
brightness.Step();
|
brightness.Step();
|
||||||
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
||||||
settingsController.SetBrightness(brightness.Level());
|
settingsController.SetBrightness(brightness.Level());
|
||||||
|
|
||||||
} else if (object == btn3 && event == LV_EVENT_VALUE_CHANGED) {
|
} else if (object == btn3) {
|
||||||
|
|
||||||
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
|
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) {
|
||||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::ON);
|
settingsController.SetNotificationStatus(Controllers::Settings::Notification::Off);
|
||||||
motorController.RunForDuration(35);
|
|
||||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
|
||||||
} else {
|
|
||||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::OFF);
|
|
||||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
||||||
|
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOff));
|
||||||
|
} else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) {
|
||||||
|
settingsController.SetNotificationStatus(Controllers::Settings::Notification::Sleep);
|
||||||
|
lv_label_set_text_static(btn3_lvl, Symbols::sleep);
|
||||||
|
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::Sleep));
|
||||||
|
} else {
|
||||||
|
settingsController.SetNotificationStatus(Controllers::Settings::Notification::On);
|
||||||
|
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
||||||
|
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOn));
|
||||||
|
motorController.RunForDuration(35);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (object == btn4 && event == LV_EVENT_CLICKED) {
|
} else if (object == btn4) {
|
||||||
running = false;
|
|
||||||
settingsController.SetSettingsMenu(0);
|
settingsController.SetSettingsMenu(0);
|
||||||
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
|
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Pinetime {
|
||||||
|
|
||||||
~QuickSettings() override;
|
~QuickSettings() override;
|
||||||
|
|
||||||
void OnButtonEvent(lv_obj_t* object, lv_event_t event);
|
void OnButtonEvent(lv_obj_t* object);
|
||||||
|
|
||||||
void UpdateScreen();
|
void UpdateScreen();
|
||||||
|
|
||||||
|
|
|
@ -251,7 +251,8 @@ void SystemTask::Work() {
|
||||||
case Messages::TouchWakeUp: {
|
case Messages::TouchWakeUp: {
|
||||||
if (touchHandler.GetNewTouchInfo()) {
|
if (touchHandler.GetNewTouchInfo()) {
|
||||||
auto gesture = touchHandler.GestureGet();
|
auto gesture = touchHandler.GestureGet();
|
||||||
if (gesture != Pinetime::Applications::TouchEvents::None &&
|
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep &&
|
||||||
|
gesture != Pinetime::Applications::TouchEvents::None &&
|
||||||
((gesture == Pinetime::Applications::TouchEvents::DoubleTap &&
|
((gesture == Pinetime::Applications::TouchEvents::DoubleTap &&
|
||||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
|
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
|
||||||
(gesture == Pinetime::Applications::TouchEvents::Tap &&
|
(gesture == Pinetime::Applications::TouchEvents::Tap &&
|
||||||
|
@ -280,7 +281,7 @@ void SystemTask::Work() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewNotification:
|
case Messages::OnNewNotification:
|
||||||
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) {
|
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::On) {
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
} else {
|
} else {
|
||||||
|
@ -388,7 +389,8 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewHour:
|
case Messages::OnNewHour:
|
||||||
using Pinetime::Controllers::AlarmController;
|
using Pinetime::Controllers::AlarmController;
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours &&
|
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep &&
|
||||||
|
settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours &&
|
||||||
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
|
@ -399,7 +401,8 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewHalfHour:
|
case Messages::OnNewHalfHour:
|
||||||
using Pinetime::Controllers::AlarmController;
|
using Pinetime::Controllers::AlarmController;
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours &&
|
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep &&
|
||||||
|
settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours &&
|
||||||
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
|
@ -483,13 +486,13 @@ void SystemTask::UpdateMotion() {
|
||||||
motionController.IsSensorOk(motionSensor.IsOk());
|
motionController.IsSensorOk(motionSensor.IsOk());
|
||||||
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
|
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
|
||||||
|
|
||||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
|
if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep) {
|
||||||
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) {
|
if ((settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
|
||||||
|
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) ||
|
||||||
|
(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
|
||||||
|
motionController.Should_ShakeWake(settingsController.GetShakeThreshold()))) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
|
|
||||||
motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) {
|
|
||||||
GoToRunning();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue