Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
settingsManager.h File Reference

Detailed Description

Design Philosophy

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.

Usage

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.

Example

Adding a setting to a menu:

// Declare the label
static const char tftSettingLabel[] = "TFT";
// Add the TFT settings item to the menu. Initialize it by getting the parameters and current value
void addSettingsItemToMenu(menu_t *menu, const char *label, const settingParam_t *bounds, int32_t val)
Add a settings entry to the menu. A settings entry is left-right scrollable where an integer setting ...
Definition menu.c:329
uint8_t getTftBrightnessSetting(void)
Get the current TFT brightness setting.
Definition settingsManager.c:262
const settingParam_t * getTftBrightnessSettingBounds(void)
Get the bounds for the TFT brightness setting. Useful for initializing settings items in menus.
Definition settingsManager.c:272

Setting a setting from a menu callback

// Make sure the label matches
if (tftSettingLabel == label)
{
// Set the setting to the reported value.
// This will call setTFTBacklightBrightness(), setting the actual brightness as well
}
bool setTftBrightnessSetting(uint8_t newVal)
Set the current TFT brightness setting. This calls setTFTBacklightBrightness() after writing to NVS.
Definition settingsManager.c:283

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_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.
 
uint16_t getBgmVolumeSetting (void)
 Get the current background music volume setting.
 
const settingParam_tgetBgmVolumeSettingBounds (void)
 Get the bounds for the background volume setting. Useful for initializing settings items in menus.
 
bool setBgmVolumeSetting (uint16_t)
 Set the current background music volume setting. This calls bzrSetBgmVolume() after writing to NVS.
 
uint16_t getSfxVolumeSetting (void)
 Get the current sound effects volume setting.
 
const settingParam_tgetSfxVolumeSettingBounds (void)
 Get the bounds for the background volume setting. Useful for initializing settings items in menus.
 
bool setSfxVolumeSetting (uint16_t)
 Set the current sound effects volume setting. This calls bzrSetSfxVolume() after writing to NVS.
 
uint8_t getTftBrightnessSetting (void)
 Get the current TFT brightness setting.
 
const settingParam_tgetTftBrightnessSettingBounds (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_tgetLedBrightnessSettingBounds (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_tgetMicGainSettingBounds (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_tgetScreensaverTimeSettingBounds (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_tgetGamepadAccelSettingBounds (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_tgetGamepadTouchSettingBounds (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_tgetShowSecretsMenuSettingBounds (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.
 

Data Structure Documentation

◆ settingParam_t

struct settingParam_t
Data Fields
const int32_t min The minimum value for this setting, inclusive.
const int32_t max The maximum value for this setting, inclusive.
const int32_t def The default value for this setting, must be between min and max.
const char * key The NVS key for this setting.

Enumeration Type Documentation

◆ gamepadTouch_t

Enumerator
GAMEPAD_TOUCH_L_STICK_SETTING 
GAMEPAD_TOUCH_R_STICK_SETTING 

◆ showSecrets_t

Enumerator
SHOW_SECRETS 
HIDE_SECRETS 

Function Documentation

◆ readAllSettings()

void readAllSettings ( void )

Read all settings from NVM and set the appropriate hardware peripherals, like TFT and LED brightness.

◆ getBgmVolumeSetting()

uint16_t getBgmVolumeSetting ( void )

Get the current background music volume setting.

Returns
the current background music volume setting

◆ getBgmVolumeSettingBounds()

const settingParam_t * getBgmVolumeSettingBounds ( void )

Get the bounds for the background volume setting. Useful for initializing settings items in menus.

Returns
the bounds for the background volume setting

◆ setBgmVolumeSetting()

bool setBgmVolumeSetting ( uint16_t vol)

Set the current background music volume setting. This calls bzrSetBgmVolume() after writing to NVS.

Parameters
volThe new volume setting, 0 to MAX_VOLUME
Returns
true if the setting was written, false if it wasn't

◆ getSfxVolumeSetting()

uint16_t getSfxVolumeSetting ( void )

Get the current sound effects volume setting.

Returns
the current sound effects volume setting

◆ getSfxVolumeSettingBounds()

const settingParam_t * getSfxVolumeSettingBounds ( void )

Get the bounds for the background volume setting. Useful for initializing settings items in menus.

Returns
the bounds for the background volume setting

◆ setSfxVolumeSetting()

bool setSfxVolumeSetting ( uint16_t vol)

Set the current sound effects volume setting. This calls bzrSetSfxVolume() after writing to NVS.

Parameters
volThe new volume setting, 0 to MAX_VOLUME
Returns
true if the setting was written, false if it wasn't

◆ getTftBrightnessSetting()

uint8_t getTftBrightnessSetting ( void )

Get the current TFT brightness setting.

Returns
the current TFT brightness setting

◆ getTftBrightnessSettingBounds()

const settingParam_t * getTftBrightnessSettingBounds ( void )

Get the bounds for the TFT brightness setting. Useful for initializing settings items in menus.

Returns
the bounds for the TFT brightness setting

◆ setTftBrightnessSetting()

bool setTftBrightnessSetting ( uint8_t newVal)

Set the current TFT brightness setting. This calls setTFTBacklightBrightness() after writing to NVS.

Parameters
newValthe new TFT brightness setting, 0 to MAX_TFT_BRIGHTNESS
Returns
true if the setting was written, false if it wasn't

◆ getLedBrightnessSetting()

uint8_t getLedBrightnessSetting ( void )

Get the current LED brightness.

Returns
the current LED brightness

◆ getLedBrightnessSettingBounds()

const settingParam_t * getLedBrightnessSettingBounds ( void )

Get the bounds for the LED brightness setting. Useful for initializing settings items in menus.

Returns
the bounds for the LED brightness setting

◆ setLedBrightnessSetting()

bool setLedBrightnessSetting ( uint8_t brightness)

Set the current LED brightness setting. This calls setLedBrightness() after writing to NVS.

Parameters
brightnessThe new LED brightness setting, 0 to MAX_LED_BRIGHTNESS
Returns
true if the setting was written, false if it was not

◆ incLedBrightnessSetting()

bool incLedBrightnessSetting ( void )

Increment the LED brightness setting by one. This calls setLedBrightness() after writing to NVS.

Returns
true if the setting was written, false if it was not

◆ decLedBrightnessSetting()

bool decLedBrightnessSetting ( void )

Decrement the LED brightness setting by one. This calls setLedBrightness() after writing to NVS.

Returns
true if the setting was written, false if it was not

◆ getMicGainSetting()

uint8_t getMicGainSetting ( void )

Get the current microphone gain setting.

Returns
the current microphone gain setting

◆ getMicGainSettingBounds()

const settingParam_t * getMicGainSettingBounds ( void )

Get the bounds for the microphone gain setting. Useful for initializing settings items in menus.

Returns
the bounds for the microphone gain setting

◆ setMicGainSetting()

bool setMicGainSetting ( uint8_t newGain)

Set the current microphone gain setting. The new value is immediately used when sampling the microphone.

Parameters
newGainThe new microphone gain setting, 0 to MAX_MIC_GAIN
Returns
true if the setting was written, false if it wasn't

◆ decMicGainSetting()

bool decMicGainSetting ( void )

Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone.

Returns
true if the setting was written, false if it was not

◆ incMicGainSetting()

bool incMicGainSetting ( void )

Decrement the microphone gain setting by one. The new value is immediately used when sampling the microphone.

Returns
true if the setting was written, false if it was not

◆ getScreensaverTimeSetting()

uint16_t getScreensaverTimeSetting ( void )

Get the current screensaver timeout setting.

Returns
the current screensaver timeout setting

◆ getScreensaverTimeSettingBounds()

const settingParam_t * getScreensaverTimeSettingBounds ( void )

Get the bounds for the screensaver timeout setting. Useful for initializing settings items in menus.

Returns
the bounds for the screensaver timeout setting

◆ setScreensaverTimeSetting()

bool setScreensaverTimeSetting ( uint16_t val)

Set the current screensaver timeout setting. The new value is immediately used for the screensaver timeout.

Parameters
valThe new screensaver timeout setting
Returns
true if the setting was written, false if it wasn't

◆ getColorchordModeSetting()

colorchordMode_t getColorchordModeSetting ( void )

Get the current Colorchord LED output setting.

Returns
the current Colorchord LED output setting

◆ setColorchordModeSetting()

bool setColorchordModeSetting ( colorchordMode_t newMode)

Set the current Colorchord LED output setting. The new value is immediately used when sampling the microphone.

Parameters
newModeThe new Colorchord LED output setting
Returns
true if the setting was written, false if it wasn't

◆ getTestModePassedSetting()

bool getTestModePassedSetting ( void )

Get the current test mode passed setting.

Returns
the current test mode passed setting

◆ setTestModePassedSetting()

bool setTestModePassedSetting ( bool status)

Set the current test mode passed setting.

Parameters
statusThe new test mode passed setting
Returns
true if the setting was written, false if it wasn't

◆ getTutorialCompletedSetting()

bool getTutorialCompletedSetting ( void )

Get the current tutorial completed setting.

Returns
the current tutorial completed setting

◆ setTutorialCompletedSetting()

bool setTutorialCompletedSetting ( bool status)

Set the current tutorial completed setting.

Parameters
statusThe new tutorial completed setting
Returns
true if the setting was written, false if it wasn't

◆ getGamepadAccelSetting()

bool getGamepadAccelSetting ( void )

Get the current Gamepad accel setting.

Returns
true if Gamepad accel is enabled, false if not

◆ getGamepadAccelSettingBounds()

const settingParam_t * getGamepadAccelSettingBounds ( void )

Get the bounds for the Gamepad accel setting. Useful for initializing settings items in menus.

Returns
the bounds for the Gamepad accel setting

◆ setGamepadAccelSetting()

bool setGamepadAccelSetting ( bool status)

Set the current Gamepad accel setting.

Parameters
statusThe new Gamepad accel setting
Returns
true if the setting was written, false if it wasn't

◆ getGamepadTouchSetting()

gamepadTouch_t getGamepadTouchSetting ( void )

Get the current Gamepad touch setting.

Returns
gamepadTouch_t indicating current setting for Gamepad touch

◆ getGamepadTouchSettingBounds()

const settingParam_t * getGamepadTouchSettingBounds ( void )

Get the bounds for the Gamepad touch setting. Useful for initializing settings items in menus.

Returns
the bounds for the Gamepad touch setting

◆ setGamepadTouchSetting()

bool setGamepadTouchSetting ( gamepadTouch_t status)

Set the current Gamepad touch setting.

Parameters
statusThe new Gamepad touch setting
Returns
true if the setting was written, false if it wasn't

◆ getShowSecretsMenuSetting()

showSecrets_t getShowSecretsMenuSetting ( void )

Get the current setting to show Secrets menu on the main menu.

Returns
showSecrets_t indicating current setting for showing Secrets menu on the main menu

◆ getShowSecretsMenuSettingBounds()

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.

Returns
the bounds for the setting to show Secrets menu on the main menu

◆ setShowSecretsMenuSetting()

bool setShowSecretsMenuSetting ( showSecrets_t status)

Set the current setting to show Secrets menu on the main menu.

Parameters
statusThe new setting to show Secrets menu on the main menu
Returns
true if the setting was written, false if it wasn't