Recently, I updated the unit I am running applications on with a new CODEC and amplifier; the older parts are EOL. There was a bug with the old setup. For some reason, even when a tone was not being generated, you could hear a noise emanating from the speaker when the LCD brightness was on a higher setting.
In order to counteract that problem the Amplifiers mute function (standby for old amp) was toggled on and off before and after a tone was produced:
const char *const amplifierGPIO = "/sys/class/gpio/gpio107/value";
void amplifierOn()
{
std::ofstream amp(amplifierGPIO);
if (amp.is_open())
{
amp << "1";
amp.close();
}
}
void amplifierOff()
{
std::ofstream amp(amplifierGPIO);
if (amp.is_open())
{
amp << "0";
amp.close();
}
}
The problem is that now in order to get the same functionality to work with the new amplifier I have to surround the ofstream in sleep statments:
const char *const amplifierGPIO = "/sys/class/gpio/gpio107/value";
void amplifierOn()
{
sleep(1);
std::ofstream amp(amplifierGPIO);
if (amp.is_open())
{
amp << "1";
amp.close();
}
sleep(1);
}
void amplifierOff()
{
sleep(1):
std::ofstream amp(amplifierGPIO);
if (amp.is_open())
{
amp << "0";
amp.close();
}
sleep(1);
}
1) Any ideas about why this might be the case? I do not believe it's the mute function on the amplifier itself because outside of the application that uses this ofstream (inside the boot loader) I can play a song and toggle it on and off with the mute function, with no delay needed.
2) Is there another way (other than ofstream) of toggling the GPIO pin 107 from within my application?