Skip to content

Commit

Permalink
disable sound when webserver running sharandac#104 temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sharandac committed Sep 11, 2020
1 parent f224a56 commit 1f76faa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ or simple press "build and upload" in platformIO.
# known issues

* the webserver crashes the ESP32 really often
* sound and webserver will not work at the same time ( cause cache crashes )
* the battery indicator is not accurate, rather a problem with the power management unit ( axp202 )
* from time to time the esp32 crashes accidentally
* and some other small things
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
/*
* firmeware version string
*/
#define __FIRMWARE__ "2020091003"
#define __FIRMWARE__ "2020091101"

#endif // _CONFIG_H
28 changes: 19 additions & 9 deletions src/hardware/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <TTGO.h>

#include "powermgm.h"
#include "wifictl.h"

#include "sound.h"

Expand Down Expand Up @@ -57,6 +58,13 @@ void sound_setup( void ) {
return;

sound_read_config();

// disable sound when webserver is enabled
if ( wifictl_get_webserver() ) {
log_i("disable sound while webserver is enabled, issue #104");
sound_set_enabled_config( false );
return;
}

//out->SetPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
out = new AudioOutputI2S();
Expand Down Expand Up @@ -98,15 +106,15 @@ void sound_set_enabled( bool enabled ) {
}

void sound_loop( void ) {
if ( sound_config.enable ) {
if ( sound_config.enable && sound_init ) {
// we call sound_set_enabled(false) to ensure the PMU stops all power
if ( mp3->isRunning() && !mp3->loop() ) sound_set_enabled(false);
if ( wav->isRunning() && !wav->loop() ) sound_set_enabled(false);
}
}

void sound_play_spiffs_mp3( const char *filename ) {
if ( sound_config.enable ) {
if ( sound_config.enable && sound_init ) {
log_i("playing file %s from SPIFFS", filename);
sound_set_enabled(true);
spliffs_file = new AudioFileSourceSPIFFS(filename);
Expand All @@ -118,7 +126,7 @@ void sound_play_spiffs_mp3( const char *filename ) {
}

void sound_play_progmem_wav( const void *data, uint32_t len ) {
if ( sound_config.enable ) {
if ( sound_config.enable && sound_init ) {
log_i("playing audio (size %d) from PROGMEM ", len );
sound_set_enabled(true);
progmem_file = new AudioFileSourcePROGMEM( data, len );
Expand Down Expand Up @@ -162,8 +170,8 @@ void sound_read_config( void ) {
log_e("update check deserializeJson() failed: %s", error.c_str() );
}
else {
sound_config.enable = doc["enable"].as<bool>();
sound_config.volume = doc["volume"].as<uint8_t>();;
sound_config.enable = doc["enable"];
sound_config.volume = doc["volume"];
log_i("volume: %d", sound_config.volume);
}
doc.clear();
Expand All @@ -188,8 +196,10 @@ uint8_t sound_get_volume_config( void ) {
}

void sound_set_volume_config( uint8_t volume ) {
log_i("Setting sound volume to: %d", volume);
sound_config.volume = volume;
// limiting max gain to 3.5 (max gain is 4.0)
out->SetGain(3.5f * (sound_config.volume / 100.0f));
if ( sound_config.enable && sound_init ) {
log_i("Setting sound volume to: %d", volume);
sound_config.volume = volume;
// limiting max gain to 3.5 (max gain is 4.0)
out->SetGain(3.5f * (sound_config.volume / 100.0f));
}
}
Binary file modified ttgo-t-watch2020_v1.ino.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion ttgo-t-watch2020_v1.version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"2020091003","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
{"version":"2020091101","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}

0 comments on commit 1f76faa

Please sign in to comment.