2016-11-21 21:31:10 +00:00
|
|
|
/**
|
|
|
|
* @file Arduboy2Audio.cpp
|
|
|
|
* \brief
|
|
|
|
* The Arduboy2Audio class for speaker and sound control.
|
|
|
|
*/
|
|
|
|
|
2016-05-27 21:43:58 +00:00
|
|
|
#include "Arduboy2.h"
|
2016-10-27 18:59:56 +00:00
|
|
|
#include "Arduboy2Audio.h"
|
2015-05-01 05:26:58 +00:00
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
bool Arduboy2Audio::audio_enabled = false;
|
2015-05-01 05:26:58 +00:00
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
void Arduboy2Audio::on()
|
2015-05-01 05:26:58 +00:00
|
|
|
{
|
2017-03-15 18:10:19 +00:00
|
|
|
// fire up audio pins by seting them as outputs
|
2016-03-02 01:49:46 +00:00
|
|
|
#ifdef ARDUBOY_10
|
2017-03-15 18:10:19 +00:00
|
|
|
bitSet(SPEAKER_1_DDR, SPEAKER_1_BIT);
|
|
|
|
bitSet(SPEAKER_2_DDR, SPEAKER_2_BIT);
|
2016-03-02 01:49:46 +00:00
|
|
|
#else
|
2017-03-15 18:10:19 +00:00
|
|
|
bitSet(SPEAKER_1_DDR, SPEAKER_1_BIT);
|
2016-03-02 01:49:46 +00:00
|
|
|
#endif
|
2015-05-01 05:26:58 +00:00
|
|
|
audio_enabled = true;
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
void Arduboy2Audio::off()
|
2015-05-01 05:26:58 +00:00
|
|
|
{
|
|
|
|
audio_enabled = false;
|
2017-03-15 18:10:19 +00:00
|
|
|
// shut off audio pins by setting them as inputs
|
2016-06-26 21:28:41 +00:00
|
|
|
#ifdef ARDUBOY_10
|
2017-03-15 18:10:19 +00:00
|
|
|
bitClear(SPEAKER_1_DDR, SPEAKER_1_BIT);
|
|
|
|
bitClear(SPEAKER_2_DDR, SPEAKER_2_BIT);
|
2016-06-26 21:28:41 +00:00
|
|
|
#else
|
2017-03-15 18:10:19 +00:00
|
|
|
bitClear(SPEAKER_1_DDR, SPEAKER_1_BIT);
|
2016-06-26 21:28:41 +00:00
|
|
|
#endif
|
2015-05-01 05:26:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 16:49:29 +00:00
|
|
|
void Arduboy2Audio::toggle()
|
|
|
|
{
|
|
|
|
if (audio_enabled)
|
|
|
|
off();
|
|
|
|
else
|
|
|
|
on();
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
void Arduboy2Audio::saveOnOff()
|
2015-05-01 05:26:58 +00:00
|
|
|
{
|
2016-03-02 17:31:41 +00:00
|
|
|
EEPROM.update(EEPROM_AUDIO_ON_OFF, audio_enabled);
|
2015-05-01 05:26:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
void Arduboy2Audio::begin()
|
2015-05-01 05:26:58 +00:00
|
|
|
{
|
|
|
|
if (EEPROM.read(EEPROM_AUDIO_ON_OFF))
|
|
|
|
on();
|
2017-03-15 18:10:19 +00:00
|
|
|
else
|
|
|
|
off();
|
2015-05-01 05:26:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:59:56 +00:00
|
|
|
bool Arduboy2Audio::enabled()
|
2016-06-26 21:28:41 +00:00
|
|
|
{
|
|
|
|
return audio_enabled;
|
|
|
|
}
|