2021-02-24 19:40:24 +00:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
2021-07-14 18:51:51 +00:00
|
|
|
#include <bitset>
|
2021-04-04 02:08:51 +00:00
|
|
|
#include "components/datetime/DateTimeController.h"
|
|
|
|
#include "components/brightness/BrightnessController.h"
|
2021-07-11 13:06:06 +00:00
|
|
|
#include "components/fs/FS.h"
|
2021-04-04 02:08:51 +00:00
|
|
|
#include "drivers/Cst816s.h"
|
2021-02-24 19:40:24 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class Settings {
|
2021-04-24 09:00:45 +00:00
|
|
|
public:
|
2021-07-11 13:06:06 +00:00
|
|
|
enum class ClockType : uint8_t { H24, H12 };
|
|
|
|
enum class Vibration : uint8_t { ON, OFF };
|
2021-07-14 18:51:51 +00:00
|
|
|
enum class WakeUpMode : uint8_t {
|
|
|
|
SingleTap = 0,
|
|
|
|
DoubleTap = 1,
|
|
|
|
RaiseWrist = 2,
|
|
|
|
};
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-07-11 13:06:06 +00:00
|
|
|
Settings(Pinetime::Controllers::FS& fs);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void SaveSettings();
|
|
|
|
|
|
|
|
void SetClockFace(uint8_t face) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if (face != settings.clockFace) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
settings.clockFace = face;
|
|
|
|
};
|
|
|
|
uint8_t GetClockFace() const {
|
|
|
|
return settings.clockFace;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetAppMenu(uint8_t menu) {
|
|
|
|
appMenu = menu;
|
|
|
|
};
|
|
|
|
uint8_t GetAppMenu() {
|
|
|
|
return appMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetSettingsMenu(uint8_t menu) {
|
|
|
|
settingsMenu = menu;
|
|
|
|
};
|
|
|
|
uint8_t GetSettingsMenu() const {
|
|
|
|
return settingsMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetClockType(ClockType clocktype) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if (clocktype != settings.clockType) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
settings.clockType = clocktype;
|
|
|
|
};
|
|
|
|
ClockType GetClockType() const {
|
|
|
|
return settings.clockType;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetVibrationStatus(Vibration status) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if (status != settings.vibrationStatus) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
settings.vibrationStatus = status;
|
|
|
|
};
|
|
|
|
Vibration GetVibrationStatus() const {
|
|
|
|
return settings.vibrationStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetScreenTimeOut(uint32_t timeout) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if (timeout != settings.screenTimeOut) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
settings.screenTimeOut = timeout;
|
|
|
|
};
|
|
|
|
uint32_t GetScreenTimeOut() const {
|
|
|
|
return settings.screenTimeOut;
|
|
|
|
};
|
|
|
|
|
2021-07-14 18:51:51 +00:00
|
|
|
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
|
|
|
|
if (!isWakeUpModeOn(wakeUp)) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-07-14 18:51:51 +00: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;
|
|
|
|
case WakeUpMode::RaiseWrist:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
};
|
2021-07-14 18:51:51 +00:00
|
|
|
|
|
|
|
std::bitset<3> getWakeUpModes() const {
|
2021-04-18 17:28:14 +00:00
|
|
|
return settings.wakeUpMode;
|
2021-07-14 18:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWakeUpModeOn(const WakeUpMode mode) const {
|
|
|
|
return getWakeUpModes()[static_cast<size_t>(mode)];
|
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
void SetBrightness(Controllers::BrightnessController::Levels level) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if (level != settings.brightLevel) {
|
2021-04-18 17:28:14 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-18 17:28:14 +00:00
|
|
|
settings.brightLevel = level;
|
|
|
|
};
|
|
|
|
Controllers::BrightnessController::Levels GetBrightness() const {
|
|
|
|
return settings.brightLevel;
|
|
|
|
};
|
|
|
|
|
2021-04-26 20:29:48 +00:00
|
|
|
void SetStepsGoal( uint32_t goal ) {
|
2021-07-11 13:06:06 +00:00
|
|
|
if ( goal != settings.stepsGoal ) {
|
2021-04-26 20:29:48 +00:00
|
|
|
settingsChanged = true;
|
2021-07-11 13:06:06 +00:00
|
|
|
}
|
2021-04-26 20:29:48 +00:00
|
|
|
settings.stepsGoal = goal;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t GetStepsGoal() const { return settings.stepsGoal; };
|
|
|
|
|
2021-04-24 09:00:45 +00:00
|
|
|
private:
|
2021-07-11 13:06:06 +00:00
|
|
|
Pinetime::Controllers::FS& fs;
|
|
|
|
|
|
|
|
static constexpr uint32_t settingsVersion = 0x0001;
|
2021-04-18 17:28:14 +00:00
|
|
|
struct SettingsData {
|
|
|
|
|
2021-07-11 13:06:06 +00:00
|
|
|
uint32_t version = settingsVersion;
|
|
|
|
uint32_t stepsGoal = 10000;
|
|
|
|
uint32_t screenTimeOut = 15000;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
ClockType clockType = ClockType::H24;
|
|
|
|
Vibration vibrationStatus = Vibration::ON;
|
|
|
|
|
|
|
|
uint8_t clockFace = 0;
|
|
|
|
|
2021-07-14 18:51:51 +00:00
|
|
|
std::bitset<3> wakeUpMode {0};
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
|
|
|
|
};
|
|
|
|
|
|
|
|
SettingsData settings;
|
|
|
|
bool settingsChanged = false;
|
|
|
|
|
|
|
|
uint8_t appMenu = 0;
|
|
|
|
uint8_t settingsMenu = 0;
|
|
|
|
|
2021-07-11 13:06:06 +00:00
|
|
|
void LoadSettingsFromFile();
|
|
|
|
void SaveSettingsToFile();
|
2021-02-24 19:40:24 +00:00
|
|
|
};
|
|
|
|
}
|
2021-07-14 18:51:51 +00:00
|
|
|
}
|