Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Settings are integers that control hardware peripherals and are persistent across reboots. Each setting has a bounded range and a default value.
The range and default value is stored in a settingParam_t, which does not change and should be declared const
to compile into ROM. The setting is read from NVS and stored a setting_t in RAM so that modes and peripherals can quickly access it without disk operations. The DECL_SETTING() macro exists to easily and consistently declare the required variables for a setting.
Settings should immediately modify the hardware peripheral they control when changed.
An example of a setting is TFT brightness. The brightness is an integer (0-MAX_TFT_BRIGHTNESS), which controls a hardware peripheral (the TFT), and is persistent across reboots (once the brightness is set by the user, it should stay that way).
Settings rely heavily on, and can be thought of a wrapper around, hdw-nvs.h.
Settings can be easily added to menus with the function addSettingsItemToMenu(). Be sure to set the setting in the menuCb callback according to the new value
.
Setting variables should be declared using DECL_SETTING() and giving the macro the minimum, maximum, and default values.
Settings should be modified using the static
functions readSetting(), incSetting(), decSetting(), and setSetting().
Each setting should have it's own set of functions to be called from other files. For instance, getTftBrightnessSetting() is used to get the current TFT brightness level, getTftBrightnessSettingBounds() is used to get the setting bounds for menu construction, and setTftBrightnessSetting() is used to set a new TFT brightness value, which is used immediately.
readAllSettings() is called during system initialization to read all settings into RAM and set hardware peripherals accordingly.
Adding a setting to a menu:
Setting a setting from a menu callback
Go to the source code of this file.
Data Structures | |
struct | settingParam_t |
Immutable data for a setting, including minimum, maximum, and default values, and the NVS key. More... | |
Enumerations | |
enum | gamepadTouch_t { GAMEPAD_TOUCH_MORE_BUTTONS_SETTING , GAMEPAD_TOUCH_L_STICK_SETTING , GAMEPAD_TOUCH_R_STICK_SETTING } |
enum | showSecrets_t { SHOW_SECRETS , HIDE_SECRETS } |
Functions | |
void | readAllSettings (void) |
Read all settings from NVM and set the appropriate hardware peripherals, like TFT and LED brightness. | |
uint8_t | getTftBrightnessSetting (void) |
Get the current TFT brightness setting. | |
const settingParam_t * | getTftBrightnessSettingBounds (void) |
Get the bounds for the TFT brightness setting. Useful for initializing settings items in menus. | |
bool | setTftBrightnessSetting (uint8_t newVal) |
Set the current TFT brightness setting. This calls setTFTBacklightBrightness() after writing to NVS. | |
uint8_t | getLedBrightnessSetting (void) |
Get the current LED brightness. | |
const settingParam_t * | getLedBrightnessSettingBounds (void) |
Get the bounds for the LED brightness setting. Useful for initializing settings items in menus. | |
bool | setLedBrightnessSetting (uint8_t brightness) |
Set the current LED brightness setting. This calls setLedBrightness() after writing to NVS. | |
bool | incLedBrightnessSetting (void) |
Increment the LED brightness setting by one. This calls setLedBrightness() after writing to NVS. | |
bool | decLedBrightnessSetting (void) |
Decrement the LED brightness setting by one. This calls setLedBrightness() after writing to NVS. | |
uint8_t | getMicGainSetting (void) |
Get the current microphone gain setting. | |
const settingParam_t * | getMicGainSettingBounds (void) |
Get the bounds for the microphone gain setting. Useful for initializing settings items in menus. | |
bool | setMicGainSetting (uint8_t newGain) |
Set the current microphone gain setting. The new value is immediately used when sampling the microphone. | |
bool | decMicGainSetting (void) |
Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone. | |
bool | incMicGainSetting (void) |
Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone. | |
uint16_t | getScreensaverTimeSetting (void) |
Get the current screensaver timeout setting. | |
const settingParam_t * | getScreensaverTimeSettingBounds (void) |
Get the bounds for the screensaver timeout setting. Useful for initializing settings items in menus. | |
bool | setScreensaverTimeSetting (uint16_t val) |
Set the current screensaver timeout setting. The new value is immediately used for the screensaver timeout. | |
colorchordMode_t | getColorchordModeSetting (void) |
Get the current Colorchord LED output setting. | |
bool | setColorchordModeSetting (colorchordMode_t) |
Set the current Colorchord LED output setting. The new value is immediately used when sampling the microphone. | |
bool | getTestModePassedSetting (void) |
Get the current test mode passed setting. | |
bool | setTestModePassedSetting (bool status) |
Set the current test mode passed setting. | |
bool | getTutorialCompletedSetting (void) |
Get the current tutorial completed setting. | |
bool | setTutorialCompletedSetting (bool status) |
Set the current tutorial completed setting. | |
bool | getGamepadAccelSetting (void) |
Get the current Gamepad accel setting. | |
const settingParam_t * | getGamepadAccelSettingBounds (void) |
Get the bounds for the Gamepad accel setting. Useful for initializing settings items in menus. | |
bool | setGamepadAccelSetting (bool status) |
Set the current Gamepad accel setting. | |
gamepadTouch_t | getGamepadTouchSetting (void) |
Get the current Gamepad touch setting. | |
const settingParam_t * | getGamepadTouchSettingBounds (void) |
Get the bounds for the Gamepad touch setting. Useful for initializing settings items in menus. | |
bool | setGamepadTouchSetting (gamepadTouch_t status) |
Set the current Gamepad touch setting. | |
showSecrets_t | getShowSecretsMenuSetting (void) |
Get the current setting to show Secrets menu on the main menu. | |
const settingParam_t * | getShowSecretsMenuSettingBounds (void) |
Get the bounds for the setting to show Secrets menu on the main menu. Useful for initializing settings items in menus. | |
bool | setShowSecretsMenuSetting (showSecrets_t status) |
Set the current setting to show Secrets menu on the main menu. | |
struct settingParam_t |
enum gamepadTouch_t |
enum showSecrets_t |
void readAllSettings | ( | void | ) |
Read all settings from NVM and set the appropriate hardware peripherals, like TFT and LED brightness.
uint8_t getTftBrightnessSetting | ( | void | ) |
Get the current TFT brightness setting.
const settingParam_t * getTftBrightnessSettingBounds | ( | void | ) |
Get the bounds for the TFT brightness setting. Useful for initializing settings items in menus.
bool setTftBrightnessSetting | ( | uint8_t | newVal | ) |
Set the current TFT brightness setting. This calls setTFTBacklightBrightness() after writing to NVS.
newVal | the new TFT brightness setting, 0 to MAX_TFT_BRIGHTNESS |
uint8_t getLedBrightnessSetting | ( | void | ) |
Get the current LED brightness.
const settingParam_t * getLedBrightnessSettingBounds | ( | void | ) |
Get the bounds for the LED brightness setting. Useful for initializing settings items in menus.
bool setLedBrightnessSetting | ( | uint8_t | brightness | ) |
Set the current LED brightness setting. This calls setLedBrightness() after writing to NVS.
brightness | The new LED brightness setting, 0 to MAX_LED_BRIGHTNESS |
bool incLedBrightnessSetting | ( | void | ) |
Increment the LED brightness setting by one. This calls setLedBrightness() after writing to NVS.
bool decLedBrightnessSetting | ( | void | ) |
Decrement the LED brightness setting by one. This calls setLedBrightness() after writing to NVS.
uint8_t getMicGainSetting | ( | void | ) |
Get the current microphone gain setting.
const settingParam_t * getMicGainSettingBounds | ( | void | ) |
Get the bounds for the microphone gain setting. Useful for initializing settings items in menus.
bool setMicGainSetting | ( | uint8_t | newGain | ) |
Set the current microphone gain setting. The new value is immediately used when sampling the microphone.
newGain | The new microphone gain setting, 0 to MAX_MIC_GAIN |
bool decMicGainSetting | ( | void | ) |
Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone.
bool incMicGainSetting | ( | void | ) |
Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone.
uint16_t getScreensaverTimeSetting | ( | void | ) |
Get the current screensaver timeout setting.
const settingParam_t * getScreensaverTimeSettingBounds | ( | void | ) |
Get the bounds for the screensaver timeout setting. Useful for initializing settings items in menus.
bool setScreensaverTimeSetting | ( | uint16_t | val | ) |
Set the current screensaver timeout setting. The new value is immediately used for the screensaver timeout.
val | The new screensaver timeout setting |
colorchordMode_t getColorchordModeSetting | ( | void | ) |
Get the current Colorchord LED output setting.
bool setColorchordModeSetting | ( | colorchordMode_t | newMode | ) |
Set the current Colorchord LED output setting. The new value is immediately used when sampling the microphone.
newMode | The new Colorchord LED output setting |
bool getTestModePassedSetting | ( | void | ) |
Get the current test mode passed setting.
bool setTestModePassedSetting | ( | bool | status | ) |
Set the current test mode passed setting.
status | The new test mode passed setting |
bool getTutorialCompletedSetting | ( | void | ) |
Get the current tutorial completed setting.
bool setTutorialCompletedSetting | ( | bool | status | ) |
Set the current tutorial completed setting.
status | The new tutorial completed setting |
bool getGamepadAccelSetting | ( | void | ) |
Get the current Gamepad accel setting.
const settingParam_t * getGamepadAccelSettingBounds | ( | void | ) |
Get the bounds for the Gamepad accel setting. Useful for initializing settings items in menus.
bool setGamepadAccelSetting | ( | bool | status | ) |
Set the current Gamepad accel setting.
status | The new Gamepad accel setting |
gamepadTouch_t getGamepadTouchSetting | ( | void | ) |
Get the current Gamepad touch setting.
const settingParam_t * getGamepadTouchSettingBounds | ( | void | ) |
Get the bounds for the Gamepad touch setting. Useful for initializing settings items in menus.
bool setGamepadTouchSetting | ( | gamepadTouch_t | status | ) |
Set the current Gamepad touch setting.
status | The new Gamepad touch setting |
showSecrets_t getShowSecretsMenuSetting | ( | void | ) |
Get the current setting to show Secrets menu on the main menu.
const settingParam_t * getShowSecretsMenuSettingBounds | ( | void | ) |
Get the bounds for the setting to show Secrets menu on the main menu. Useful for initializing settings items in menus.
bool setShowSecretsMenuSetting | ( | showSecrets_t | status | ) |
Set the current setting to show Secrets menu on the main menu.
status | The new setting to show Secrets menu on the main menu |