Skip to content

Commit

Permalink
power optimization: disable always on while in notification sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffeinatedKat committed Oct 4, 2023
1 parent 93994d8 commit 59c0840
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
37 changes: 33 additions & 4 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ namespace Pinetime {
if (status != settings.notificationStatus) {
settingsChanged = true;
}
// Disable always on screen while sleep mode is enabled
if (settings.alwaysOnDisplay.enabled) {
if (status == Notification::Sleep) {
settings.alwaysOnDisplay.state = false;
} else {
settings.alwaysOnDisplay.state = true;
}
}
settings.notificationStatus = status;
};

Expand All @@ -203,16 +211,30 @@ namespace Pinetime {
};

void SetAlwaysOnDisplay(bool state) {
if (state != settings.alwaysOnDisplay) {
if (state != settings.alwaysOnDisplay.state) {
settingsChanged = true;
}
settings.alwaysOnDisplay = state;
settings.alwaysOnDisplay.state = state;
};

bool GetAlwaysOnDisplay() const {
return settings.alwaysOnDisplay;
return settings.alwaysOnDisplay.state;
};

void SetAlwaysOnDisplaySetting(bool state) {
if (state != settings.alwaysOnDisplay.enabled) {
settingsChanged = true;
}
settings.alwaysOnDisplay.enabled = state;
// the always on state and enabled flags should always match
// if the setting is being modified by the user
SetAlwaysOnDisplay(state);
}

bool GetAlwaysOnDisplaySetting() const {
return settings.alwaysOnDisplay.enabled;
}

void SetShakeThreshold(uint16_t thresh) {
if (settings.shakeWakeThreshold != thresh) {
settings.shakeWakeThreshold = thresh;
Expand Down Expand Up @@ -287,12 +309,19 @@ namespace Pinetime {

static constexpr uint32_t settingsVersion = 0x0006;

// To enable disabling it durring notificationsleep, differenciate between
// the setting being on, and the setting being set by the user
struct alwaysOnDisplayData {
bool enabled = false;
bool state = false;
};

struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
uint32_t screenTimeOut = 15000;

bool alwaysOnDisplay = false;
alwaysOnDisplayData alwaysOnDisplay;

ClockType clockType = ClockType::H24;
Notification notificationStatus = Notification::On;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/settings/SettingDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ SettingDisplay::~SettingDisplay() {
}

void SettingDisplay::ToggleAlwaysOn() {
settingsController.SetAlwaysOnDisplay(!settingsController.GetAlwaysOnDisplay());
settingsController.SetAlwaysOnDisplaySetting(!settingsController.GetAlwaysOnDisplaySetting());
lv_checkbox_set_checked(alwaysOn_checkbox, settingsController.GetAlwaysOnDisplay());
}

Expand Down

0 comments on commit 59c0840

Please sign in to comment.