2021-02-24 20:40:24 +01:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
2021-07-14 20:51:51 +02:00
|
|
|
#include <bitset>
|
2021-04-04 04:08:51 +02:00
|
|
|
#include "components/brightness/BrightnessController.h"
|
2021-07-11 15:06:06 +02:00
|
|
|
#include "components/fs/FS.h"
|
2021-02-24 20:40:24 +01:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class Settings {
|
2021-04-24 11:00:45 +02:00
|
|
|
public:
|
2021-07-11 15:06:06 +02:00
|
|
|
enum class ClockType : uint8_t { H24, H12 };
|
2021-09-12 10:08:25 +02:00
|
|
|
enum class Notification : uint8_t { ON, OFF };
|
2022-01-04 20:32:29 +01:00
|
|
|
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
|
2021-07-14 20:51:51 +02:00
|
|
|
enum class WakeUpMode : uint8_t {
|
|
|
|
SingleTap = 0,
|
|
|
|
DoubleTap = 1,
|
|
|
|
RaiseWrist = 2,
|
2021-09-27 03:20:44 +02:00
|
|
|
Shake = 3,
|
2021-07-14 20:51:51 +02:00
|
|
|
};
|
2021-08-28 21:02:11 +02:00
|
|
|
enum class Colors : uint8_t {
|
2021-12-24 03:30:14 +01:00
|
|
|
White,
|
|
|
|
Silver,
|
|
|
|
Gray,
|
|
|
|
Black,
|
|
|
|
Red,
|
|
|
|
Maroon,
|
|
|
|
Yellow,
|
|
|
|
Olive,
|
|
|
|
Lime,
|
|
|
|
Green,
|
|
|
|
Cyan,
|
|
|
|
Teal,
|
|
|
|
Blue,
|
|
|
|
Navy,
|
|
|
|
Magenta,
|
|
|
|
Purple,
|
|
|
|
Orange
|
2021-08-28 21:02:11 +02:00
|
|
|
};
|
|
|
|
struct PineTimeStyle {
|
|
|
|
Colors ColorTime = Colors::Teal;
|
|
|
|
Colors ColorBar = Colors::Teal;
|
|
|
|
Colors ColorBG = Colors::Black;
|
|
|
|
};
|
2021-04-18 19:28:14 +02:00
|
|
|
|
2021-07-11 15:06:06 +02:00
|
|
|
Settings(Pinetime::Controllers::FS& fs);
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void SaveSettings();
|
|
|
|
|
|
|
|
void SetClockFace(uint8_t face) {
|
2021-07-11 15:06:06 +02:00
|
|
|
if (face != settings.clockFace) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
settings.clockFace = face;
|
|
|
|
};
|
|
|
|
uint8_t GetClockFace() const {
|
|
|
|
return settings.clockFace;
|
|
|
|
};
|
|
|
|
|
2022-01-04 20:32:29 +01:00
|
|
|
void SetChimeOption(ChimesOption chimeOption) {
|
|
|
|
if (chimeOption != settings.chimesOption) {
|
2021-11-07 11:50:33 +01:00
|
|
|
settingsChanged = true;
|
|
|
|
}
|
2022-01-04 20:32:29 +01:00
|
|
|
settings.chimesOption = chimeOption;
|
2021-11-07 11:50:33 +01:00
|
|
|
};
|
2022-01-04 20:32:29 +01:00
|
|
|
ChimesOption GetChimeOption() const {
|
|
|
|
return settings.chimesOption;
|
2021-11-07 11:50:33 +01:00
|
|
|
};
|
|
|
|
|
2021-08-28 21:02:11 +02:00
|
|
|
void SetPTSColorTime(Colors colorTime) {
|
|
|
|
if (colorTime != settings.PTS.ColorTime)
|
2021-06-24 21:49:04 +02:00
|
|
|
settingsChanged = true;
|
2021-08-28 21:02:11 +02:00
|
|
|
settings.PTS.ColorTime = colorTime;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
2021-08-28 21:02:11 +02:00
|
|
|
Colors GetPTSColorTime() const {
|
|
|
|
return settings.PTS.ColorTime;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
|
|
|
|
2021-08-28 21:02:11 +02:00
|
|
|
void SetPTSColorBar(Colors colorBar) {
|
|
|
|
if (colorBar != settings.PTS.ColorBar)
|
2021-06-24 21:49:04 +02:00
|
|
|
settingsChanged = true;
|
2021-08-28 21:02:11 +02:00
|
|
|
settings.PTS.ColorBar = colorBar;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
2021-08-28 21:02:11 +02:00
|
|
|
Colors GetPTSColorBar() const {
|
|
|
|
return settings.PTS.ColorBar;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
|
|
|
|
2021-08-28 21:02:11 +02:00
|
|
|
void SetPTSColorBG(Colors colorBG) {
|
|
|
|
if (colorBG != settings.PTS.ColorBG)
|
2021-06-24 21:49:04 +02:00
|
|
|
settingsChanged = true;
|
2021-08-28 21:02:11 +02:00
|
|
|
settings.PTS.ColorBG = colorBG;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
2021-08-28 21:02:11 +02:00
|
|
|
Colors GetPTSColorBG() const {
|
|
|
|
return settings.PTS.ColorBG;
|
2021-06-24 21:49:04 +02:00
|
|
|
};
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
void SetAppMenu(uint8_t menu) {
|
|
|
|
appMenu = menu;
|
|
|
|
};
|
2021-08-28 21:02:11 +02:00
|
|
|
|
|
|
|
uint8_t GetAppMenu() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return appMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetSettingsMenu(uint8_t menu) {
|
|
|
|
settingsMenu = menu;
|
|
|
|
};
|
|
|
|
uint8_t GetSettingsMenu() const {
|
|
|
|
return settingsMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetClockType(ClockType clocktype) {
|
2021-07-11 15:06:06 +02:00
|
|
|
if (clocktype != settings.clockType) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
settings.clockType = clocktype;
|
|
|
|
};
|
|
|
|
ClockType GetClockType() const {
|
|
|
|
return settings.clockType;
|
|
|
|
};
|
|
|
|
|
2021-09-12 10:08:25 +02:00
|
|
|
void SetNotificationStatus(Notification status) {
|
|
|
|
if (status != settings.notificationStatus) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-09-12 10:08:25 +02:00
|
|
|
settings.notificationStatus = status;
|
2021-04-18 19:28:14 +02:00
|
|
|
};
|
2021-09-12 10:08:25 +02:00
|
|
|
Notification GetNotificationStatus() const {
|
|
|
|
return settings.notificationStatus;
|
2021-04-18 19:28:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void SetScreenTimeOut(uint32_t timeout) {
|
2021-07-11 15:06:06 +02:00
|
|
|
if (timeout != settings.screenTimeOut) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
settings.screenTimeOut = timeout;
|
|
|
|
};
|
2021-09-27 04:52:02 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
uint32_t GetScreenTimeOut() const {
|
|
|
|
return settings.screenTimeOut;
|
|
|
|
};
|
|
|
|
|
2022-05-09 17:16:08 +02:00
|
|
|
void SetShakeThreshold(uint16_t thresh) {
|
|
|
|
if (settings.shakeWakeThreshold != thresh) {
|
|
|
|
settings.shakeWakeThreshold = thresh;
|
|
|
|
settingsChanged = true;
|
2021-09-28 06:21:47 +02:00
|
|
|
}
|
2021-09-27 04:52:02 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 17:16:08 +02:00
|
|
|
int16_t GetShakeThreshold() const {
|
2021-09-27 04:52:02 +02:00
|
|
|
return settings.shakeWakeThreshold;
|
|
|
|
}
|
|
|
|
|
2021-07-14 20:51:51 +02:00
|
|
|
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
|
2021-08-26 20:42:02 +02:00
|
|
|
if (enabled != isWakeUpModeOn(wakeUp)) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-07-14 20:51:51 +02:00
|
|
|
settings.wakeUpMode.set(static_cast<size_t>(wakeUp), enabled);
|
|
|
|
// Handle special behavior
|
|
|
|
if (enabled) {
|
|
|
|
switch (wakeUp) {
|
|
|
|
case WakeUpMode::SingleTap:
|
|
|
|
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::DoubleTap), false);
|
|
|
|
break;
|
|
|
|
case WakeUpMode::DoubleTap:
|
|
|
|
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
|
|
|
|
break;
|
2021-09-28 05:50:08 +02:00
|
|
|
default:
|
2021-07-14 20:51:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
};
|
2021-07-14 20:51:51 +02:00
|
|
|
|
2021-09-27 03:20:44 +02:00
|
|
|
std::bitset<4> getWakeUpModes() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return settings.wakeUpMode;
|
2021-07-14 20:51:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWakeUpModeOn(const WakeUpMode mode) const {
|
|
|
|
return getWakeUpModes()[static_cast<size_t>(mode)];
|
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
void SetBrightness(Controllers::BrightnessController::Levels level) {
|
2021-07-11 15:06:06 +02:00
|
|
|
if (level != settings.brightLevel) {
|
2021-04-18 19:28:14 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2021-04-18 19:28:14 +02:00
|
|
|
settings.brightLevel = level;
|
|
|
|
};
|
2021-12-24 03:30:14 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
Controllers::BrightnessController::Levels GetBrightness() const {
|
|
|
|
return settings.brightLevel;
|
|
|
|
};
|
|
|
|
|
2021-12-24 03:30:14 +01:00
|
|
|
void SetStepsGoal(uint32_t goal) {
|
|
|
|
if (goal != settings.stepsGoal) {
|
2021-05-18 17:45:16 +02:00
|
|
|
settingsChanged = true;
|
2021-07-11 15:06:06 +02:00
|
|
|
}
|
2022-05-09 17:16:08 +02:00
|
|
|
settings.stepsGoal = goal;
|
2021-05-18 17:45:16 +02:00
|
|
|
};
|
2022-05-09 17:16:08 +02:00
|
|
|
|
2021-12-24 03:30:14 +01:00
|
|
|
uint32_t GetStepsGoal() const {
|
|
|
|
return settings.stepsGoal;
|
|
|
|
};
|
|
|
|
|
2022-05-09 17:16:08 +02:00
|
|
|
void SetBleRadioEnabled(bool enabled) {
|
|
|
|
bleRadioEnabled = enabled;
|
|
|
|
};
|
2021-12-24 03:30:14 +01:00
|
|
|
|
2022-05-09 17:16:08 +02:00
|
|
|
bool GetBleRadioEnabled() const {
|
|
|
|
return bleRadioEnabled;
|
|
|
|
};
|
2021-05-18 17:45:16 +02:00
|
|
|
|
2021-04-24 11:00:45 +02:00
|
|
|
private:
|
2021-07-11 15:06:06 +02:00
|
|
|
Pinetime::Controllers::FS& fs;
|
|
|
|
|
2021-11-07 15:15:39 +01:00
|
|
|
static constexpr uint32_t settingsVersion = 0x0003;
|
2021-04-18 19:28:14 +02:00
|
|
|
struct SettingsData {
|
2021-07-11 15:06:06 +02:00
|
|
|
uint32_t version = settingsVersion;
|
|
|
|
uint32_t stepsGoal = 10000;
|
|
|
|
uint32_t screenTimeOut = 15000;
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
ClockType clockType = ClockType::H24;
|
2021-09-12 10:08:25 +02:00
|
|
|
Notification notificationStatus = Notification::ON;
|
2021-04-18 19:28:14 +02:00
|
|
|
|
|
|
|
uint8_t clockFace = 0;
|
2022-01-04 20:32:29 +01:00
|
|
|
ChimesOption chimesOption = ChimesOption::None;
|
2021-04-18 19:28:14 +02:00
|
|
|
|
2021-08-28 21:02:11 +02:00
|
|
|
PineTimeStyle PTS;
|
2021-06-24 21:49:04 +02:00
|
|
|
|
2021-09-27 03:20:44 +02:00
|
|
|
std::bitset<4> wakeUpMode {0};
|
2021-09-27 05:30:49 +02:00
|
|
|
uint16_t shakeWakeThreshold = 150;
|
2021-04-18 19:28:14 +02:00
|
|
|
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
|
|
|
|
};
|
|
|
|
|
|
|
|
SettingsData settings;
|
|
|
|
bool settingsChanged = false;
|
|
|
|
|
|
|
|
uint8_t appMenu = 0;
|
|
|
|
uint8_t settingsMenu = 0;
|
2022-04-02 15:03:20 +02:00
|
|
|
/* ble state is intentionally not saved with the other watch settings and initialized
|
2021-12-24 03:30:14 +01:00
|
|
|
* to off (false) on every boot because we always want ble to be enabled on startup
|
|
|
|
*/
|
2022-02-20 15:40:49 +01:00
|
|
|
bool bleRadioEnabled = true;
|
2021-04-18 19:28:14 +02:00
|
|
|
|
2021-07-11 15:06:06 +02:00
|
|
|
void LoadSettingsFromFile();
|
|
|
|
void SaveSettingsToFile();
|
2021-02-24 20:40:24 +01:00
|
|
|
};
|
|
|
|
}
|
2021-07-14 20:51:51 +02:00
|
|
|
}
|