ref: e5b73212f6addcfdb5e306df63d7135e543c4f8d
src/components/settings/Settings.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
#pragma once #include <cstdint> #include <bitset> #include "components/brightness/BrightnessController.h" #include "components/fs/FS.h" #include "displayapp/Apps.h" namespace Pinetime { namespace Controllers { class Settings { public: enum class ClockType : uint8_t { H24, H12 }; 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 Colors : uint8_t { White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange, Pink }; enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric }; enum class PTSWeather : uint8_t { On, Off }; struct PineTimeStyle { Colors ColorTime = Colors::Teal; Colors ColorBar = Colors::Teal; Colors ColorBG = Colors::Black; PTSGaugeStyle gaugeStyle = PTSGaugeStyle::Full; PTSWeather weatherEnable = PTSWeather::Off; }; struct WatchFaceInfineat { bool showSideCover = true; int colorIndex = 0; }; Settings(Pinetime::Controllers::FS& fs); Settings(const Settings&) = delete; Settings& operator=(const Settings&) = delete; Settings(Settings&&) = delete; Settings& operator=(Settings&&) = delete; void Init(); void SaveSettings(); void SetWatchFace(Pinetime::Applications::WatchFace face) { if (face != settings.watchFace) { settingsChanged = true; } settings.watchFace = face; }; Pinetime::Applications::WatchFace GetWatchFace() const { return settings.watchFace; }; void SetChimeOption(ChimesOption chimeOption) { if (chimeOption != settings.chimesOption) { settingsChanged = true; } settings.chimesOption = chimeOption; }; ChimesOption GetChimeOption() const { return settings.chimesOption; }; void SetPTSColorTime(Colors colorTime) { if (colorTime != settings.PTS.ColorTime) settingsChanged = true; settings.PTS.ColorTime = colorTime; }; Colors GetPTSColorTime() const { return settings.PTS.ColorTime; }; void SetPTSColorBar(Colors colorBar) { if (colorBar != settings.PTS.ColorBar) settingsChanged = true; settings.PTS.ColorBar = colorBar; }; Colors GetPTSColorBar() const { return settings.PTS.ColorBar; }; void SetPTSColorBG(Colors colorBG) { if (colorBG != settings.PTS.ColorBG) settingsChanged = true; settings.PTS.ColorBG = colorBG; }; Colors GetPTSColorBG() const { return settings.PTS.ColorBG; }; void SetInfineatShowSideCover(bool show) { if (show != settings.watchFaceInfineat.showSideCover) { settings.watchFaceInfineat.showSideCover = show; settingsChanged = true; } }; bool GetInfineatShowSideCover() const { return settings.watchFaceInfineat.showSideCover; }; void SetInfineatColorIndex(int index) { if (index != settings.watchFaceInfineat.colorIndex) { settings.watchFaceInfineat.colorIndex = index; settingsChanged = true; } }; int GetInfineatColorIndex() const { return settings.watchFaceInfineat.colorIndex; }; void SetPTSGaugeStyle(PTSGaugeStyle gaugeStyle) { if (gaugeStyle != settings.PTS.gaugeStyle) settingsChanged = true; settings.PTS.gaugeStyle = gaugeStyle; }; PTSGaugeStyle GetPTSGaugeStyle() const { return settings.PTS.gaugeStyle; }; void SetPTSWeather(PTSWeather weatherEnable) { if (weatherEnable != settings.PTS.weatherEnable) settingsChanged = true; settings.PTS.weatherEnable = weatherEnable; }; PTSWeather GetPTSWeather() const { return settings.PTS.weatherEnable; }; void SetAppMenu(uint8_t menu) { appMenu = menu; }; uint8_t GetAppMenu() const { return appMenu; }; void SetSettingsMenu(uint8_t menu) { settingsMenu = menu; }; uint8_t GetSettingsMenu() const { return settingsMenu; }; void SetClockType(ClockType clocktype) { if (clocktype != settings.clockType) { settingsChanged = true; } settings.clockType = clocktype; }; ClockType GetClockType() const { return settings.clockType; }; void SetNotificationStatus(Notification status) { if (status != settings.notificationStatus) { settingsChanged = true; } settings.notificationStatus = status; }; Notification GetNotificationStatus() const { return settings.notificationStatus; }; void SetScreenTimeOut(uint32_t timeout) { if (timeout != settings.screenTimeOut) { settingsChanged = true; } settings.screenTimeOut = timeout; }; uint32_t GetScreenTimeOut() const { return settings.screenTimeOut; }; void SetShakeThreshold(uint16_t thresh) { if (settings.shakeWakeThreshold != thresh) { settings.shakeWakeThreshold = thresh; settingsChanged = true; } } int16_t GetShakeThreshold() const { return settings.shakeWakeThreshold; } void setWakeUpMode(WakeUpMode wakeUp, bool enabled) { if (enabled != isWakeUpModeOn(wakeUp)) { settingsChanged = true; } 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; default: break; } } }; std::bitset<5> getWakeUpModes() const { return settings.wakeUpMode; } bool isWakeUpModeOn(const WakeUpMode mode) const { return getWakeUpModes()[static_cast<size_t>(mode)]; } void SetBrightness(Controllers::BrightnessController::Levels level) { if (level != settings.brightLevel) { settingsChanged = true; } settings.brightLevel = level; }; Controllers::BrightnessController::Levels GetBrightness() const { return settings.brightLevel; }; void SetStepsGoal(uint32_t goal) { if (goal != settings.stepsGoal) { settingsChanged = true; } settings.stepsGoal = goal; }; uint32_t GetStepsGoal() const { return settings.stepsGoal; }; void SetBleRadioEnabled(bool enabled) { bleRadioEnabled = enabled; }; bool GetBleRadioEnabled() const { return bleRadioEnabled; }; private: Pinetime::Controllers::FS& fs; static constexpr uint32_t settingsVersion = 0x0006; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; uint32_t screenTimeOut = 15000; ClockType clockType = ClockType::H24; Notification notificationStatus = Notification::On; Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital; ChimesOption chimesOption = ChimesOption::None; PineTimeStyle PTS; WatchFaceInfineat watchFaceInfineat; std::bitset<5> wakeUpMode {0}; uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; }; SettingsData settings; bool settingsChanged = false; uint8_t appMenu = 0; uint8_t settingsMenu = 0; uint8_t watchFacesMenu = 0; /* ble state is intentionally not saved with the other watch settings and initialized * to off (false) on every boot because we always want ble to be enabled on startup */ bool bleRadioEnabled = true; void LoadSettingsFromFile(); void SaveSettingsToFile(); }; } } |