diff --git a/keywords.txt b/keywords.txt index 2cd697f..bd9d001 100644 --- a/keywords.txt +++ b/keywords.txt @@ -72,6 +72,7 @@ setTextBackground KEYWORD2 setTextSize KEYWORD2 setTextWrap KEYWORD2 systemButtons KEYWORD2 +toggle KEYWORD2 width KEYWORD2 # Sprites class diff --git a/src/Arduboy2Audio.cpp b/src/Arduboy2Audio.cpp index efefef4..901f627 100644 --- a/src/Arduboy2Audio.cpp +++ b/src/Arduboy2Audio.cpp @@ -33,6 +33,14 @@ void Arduboy2Audio::off() #endif } +void Arduboy2Audio::toggle() +{ + if (audio_enabled) + off(); + else + on(); +} + void Arduboy2Audio::saveOnOff() { EEPROM.update(EEPROM_AUDIO_ON_OFF, audio_enabled); diff --git a/src/Arduboy2Audio.h b/src/Arduboy2Audio.h index afa6e54..6a78afe 100644 --- a/src/Arduboy2Audio.h +++ b/src/Arduboy2Audio.h @@ -95,7 +95,7 @@ class Arduboy2Audio * mode only until the unit is powered off. To save the current mode use * `saveOnOff()`. * - * \see off() saveOnOff() + * \see off() toggle() saveOnOff() */ void static on(); @@ -107,10 +107,23 @@ class Arduboy2Audio * the sound mode only until the unit is powered off. To save the current * mode use `saveOnOff()`. * - * \see on() saveOnOff() + * \see on() toggle() saveOnOff() */ 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 * 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 * should not continuously change and then save the state rapidly. * - * \see on() off() + * \see on() off() toggle() */ void static saveOnOff(); @@ -137,7 +150,7 @@ class Arduboy2Audio * If `true` is returned, sound can be produced. If `false` is returned, * sound should be muted. * - * \see on() off() + * \see on() off() toggle() */ bool static enabled();