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

Data Structures

struct  setting_t
 A setting. The parameters are const, but the value is not. More...
 

Macros

#define DECL_SETTING(NAME, mi, ma, de)
 Helper macro to declare const parameters for settings, and the variable setting.
 

Functions

 DECL_SETTING (test, 0, 1, 0)
 
 DECL_SETTING (tutorial, 0, 1, 0)
 
 DECL_SETTING (bgm, 0, MAX_VOLUME, MAX_VOLUME)
 
 DECL_SETTING (sfx, 0, MAX_VOLUME, MAX_VOLUME)
 
 DECL_SETTING (tft_br, 0, MAX_TFT_BRIGHTNESS, MAX_TFT_BRIGHTNESS)
 
 DECL_SETTING (led_br, 0, MAX_LED_BRIGHTNESS, 5)
 
 DECL_SETTING (mic, 0, MAX_MIC_GAIN, MAX_MIC_GAIN)
 
 DECL_SETTING (cc_mode, ALL_SAME_LEDS, LINEAR_LEDS, ALL_SAME_LEDS)
 
 DECL_SETTING (scrn_sv, 0, 300, 20)
 
 DECL_SETTING (gp_accel, 0, 1, 1)
 
 DECL_SETTING (gp_touch, GAMEPAD_TOUCH_L_STICK_SETTING, GAMEPAD_TOUCH_R_STICK_SETTING, GAMEPAD_TOUCH_R_STICK_SETTING)
 
 DECL_SETTING (show_secrets, SHOW_SECRETS, HIDE_SECRETS, HIDE_SECRETS)
 
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 vol)
 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 vol)
 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 newMode)
 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

◆ setting_t

struct setting_t
Data Fields
const settingParam_t * param The setting's immutable data (bounds and NVS key)
int32_t val The setting's current value, in RAM.

Macro Definition Documentation

◆ DECL_SETTING

#define DECL_SETTING ( NAME,
mi,
ma,
de )
Value:
static const settingParam_t NAME##_param = { \
.key = #NAME, \
.min = mi, \
.max = ma, \
.def = de, \
}; \
static setting_t NAME##_setting = { \
.param = &NAME##_param, \
.val = de, \
}
const settingParam_t * param
The setting's immutable data (bounds and NVS key)
Definition settingsManager.c:22
A setting. The parameters are const, but the value is not.
Definition settingsManager.c:21
const char * key
The NVS key for this setting.
Definition settingsManager.h:103
Immutable data for a setting, including minimum, maximum, and default values, and the NVS key.
Definition settingsManager.h:99

Helper macro to declare const parameters for settings, and the variable setting.

Parameters
NAMEthe key for this setting, also used in variable names
miThe minimum value for this setting
maThe maximum value for this setting
deThe default value for this setting

Function Documentation

◆ DECL_SETTING() [1/12]

DECL_SETTING ( test ,
0 ,
1 ,
0  )

◆ DECL_SETTING() [2/12]

DECL_SETTING ( tutorial ,
0 ,
1 ,
0  )

◆ DECL_SETTING() [3/12]

DECL_SETTING ( bgm ,
0 ,
MAX_VOLUME ,
MAX_VOLUME  )

◆ DECL_SETTING() [4/12]

DECL_SETTING ( sfx ,
0 ,
MAX_VOLUME ,
MAX_VOLUME  )

◆ DECL_SETTING() [5/12]

DECL_SETTING ( tft_br ,
0 ,
MAX_TFT_BRIGHTNESS ,
MAX_TFT_BRIGHTNESS  )

◆ DECL_SETTING() [6/12]

DECL_SETTING ( led_br ,
0 ,
MAX_LED_BRIGHTNESS ,
5  )

◆ DECL_SETTING() [7/12]

DECL_SETTING ( mic ,
0 ,
MAX_MIC_GAIN ,
MAX_MIC_GAIN  )

◆ DECL_SETTING() [8/12]

DECL_SETTING ( cc_mode ,
ALL_SAME_LEDS ,
LINEAR_LEDS ,
ALL_SAME_LEDS  )

◆ DECL_SETTING() [9/12]

DECL_SETTING ( scrn_sv ,
0 ,
300 ,
20  )

◆ DECL_SETTING() [10/12]

DECL_SETTING ( gp_accel ,
0 ,
1 ,
1  )

◆ DECL_SETTING() [11/12]

◆ DECL_SETTING() [12/12]

DECL_SETTING ( show_secrets ,
SHOW_SECRETS ,
HIDE_SECRETS ,
HIDE_SECRETS  )

◆ 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