Add sound on/off toggle function

This commit is contained in:
Scott Allen 2016-12-13 11:49:29 -05:00
parent a9271a335d
commit 7dfb4f14f7
3 changed files with 26 additions and 4 deletions

View File

@ -72,6 +72,7 @@ setTextBackground KEYWORD2
setTextSize KEYWORD2 setTextSize KEYWORD2
setTextWrap KEYWORD2 setTextWrap KEYWORD2
systemButtons KEYWORD2 systemButtons KEYWORD2
toggle KEYWORD2
width KEYWORD2 width KEYWORD2
# Sprites class # Sprites class

View File

@ -33,6 +33,14 @@ void Arduboy2Audio::off()
#endif #endif
} }
void Arduboy2Audio::toggle()
{
if (audio_enabled)
off();
else
on();
}
void Arduboy2Audio::saveOnOff() void Arduboy2Audio::saveOnOff()
{ {
EEPROM.update(EEPROM_AUDIO_ON_OFF, audio_enabled); EEPROM.update(EEPROM_AUDIO_ON_OFF, audio_enabled);

View File

@ -95,7 +95,7 @@ class Arduboy2Audio
* mode only until the unit is powered off. To save the current mode use * mode only until the unit is powered off. To save the current mode use
* `saveOnOff()`. * `saveOnOff()`.
* *
* \see off() saveOnOff() * \see off() toggle() saveOnOff()
*/ */
void static on(); void static on();
@ -107,10 +107,23 @@ class Arduboy2Audio
* the sound mode only until the unit is powered off. To save the current * the sound mode only until the unit is powered off. To save the current
* mode use `saveOnOff()`. * mode use `saveOnOff()`.
* *
* \see on() saveOnOff() * \see on() toggle() saveOnOff()
*/ */
void static off(); void static off();
/** \brief
* Toggle the sound on/off state.
*
* \details
* If the system is configured for sound on, it will be changed to sound off
* (mute). If sound is off, it will be changed to on. This function sets
* the sound mode only until the unit is powered off. To save the current
* mode use `saveOnOff()`.
*
* \see on() off() saveOnOff()
*/
void static toggle();
/** \brief /** \brief
* Save the current sound state in EEPROM. * Save the current sound state in EEPROM.
* *
@ -123,7 +136,7 @@ class Arduboy2Audio
* EEPROM is limited in the number of times it can be written to. Sketches * EEPROM is limited in the number of times it can be written to. Sketches
* should not continuously change and then save the state rapidly. * should not continuously change and then save the state rapidly.
* *
* \see on() off() * \see on() off() toggle()
*/ */
void static saveOnOff(); void static saveOnOff();
@ -137,7 +150,7 @@ class Arduboy2Audio
* If `true` is returned, sound can be produced. If `false` is returned, * If `true` is returned, sound can be produced. If `false` is returned,
* sound should be muted. * sound should be muted.
* *
* \see on() off() * \see on() off() toggle()
*/ */
bool static enabled(); bool static enabled();