@ -590,10 +590,17 @@ void fileHandlingTask(void *arguments) {
}
}
// Measures voltage of a battery as per interval or after bootup (after allowing a few seconds to settle down)
// Measures voltage of a battery as per interval or after bootup (after allowing a few seconds to settle down)
// The average of several analog reads will be taken to reduce the noise (Note: One analog read takes ~10µs)
# ifdef MEASURE_BATTERY_VOLTAGE
# ifdef MEASURE_BATTERY_VOLTAGE
float measureBatteryVoltage ( void ) {
float measureBatteryVoltage ( void ) {
float factor = 1 / ( ( float ) rdiv2 / ( rdiv2 + rdiv1 ) ) ;
float factor = 1 / ( ( float ) rdiv2 / ( rdiv2 + rdiv1 ) ) ;
return ( ( float ) analogRead ( VOLTAGE_READ_PIN ) / maxAnalogValue ) * refVoltage * factor ;
float averagedAnalogValue = 0 ;
int i ;
for ( i = 0 ; i < = 19 ; i + + ) {
averagedAnalogValue + = ( float ) analogRead ( VOLTAGE_READ_PIN ) ;
}
averagedAnalogValue / = 20.0 ;
return ( averagedAnalogValue / maxAnalogValue ) * refVoltage * factor ;
}
}
void batteryVoltageTester ( void ) {
void batteryVoltageTester ( void ) {
@ -1376,6 +1383,7 @@ void playAudio(void *parameter) {
uint8_t currentVolume ;
uint8_t currentVolume ;
static BaseType_t trackQStatus ;
static BaseType_t trackQStatus ;
static uint8_t trackCommand = 0 ;
static uint8_t trackCommand = 0 ;
bool audioReturnCode ;
for ( ; ; ) {
for ( ; ; ) {
if ( xQueueReceive ( volumeQueue , & currentVolume , 0 ) = = pdPASS ) {
if ( xQueueReceive ( volumeQueue , & currentVolume , 0 ) = = pdPASS ) {
@ -1518,7 +1526,10 @@ void playAudio(void *parameter) {
# endif
# endif
}
}
if ( playProperties . currentTrackNumber > 0 ) {
if ( playProperties . currentTrackNumber > 0 ) {
// play previous track when current track time is small, else play current track again
if ( audio . getAudioCurrentTime ( ) < 2 ) {
playProperties . currentTrackNumber - - ;
playProperties . currentTrackNumber - - ;
}
if ( playProperties . saveLastPlayPosition ) {
if ( playProperties . saveLastPlayPosition ) {
nvsRfidWriteWrapper ( playProperties . playRfidTag , * ( playProperties . playlist + playProperties . currentTrackNumber ) , 0 , playProperties . playMode , playProperties . currentTrackNumber , playProperties . numberOfTracks ) ;
nvsRfidWriteWrapper ( playProperties . playRfidTag , * ( playProperties . playlist + playProperties . currentTrackNumber ) , 0 , playProperties . playMode , playProperties . currentTrackNumber , playProperties . numberOfTracks ) ;
loggerNl ( ( char * ) FPSTR ( trackStartAudiobook ) , LOGLEVEL_INFO ) ;
loggerNl ( ( char * ) FPSTR ( trackStartAudiobook ) , LOGLEVEL_INFO ) ;
@ -1544,7 +1555,12 @@ void playAudio(void *parameter) {
# ifdef NEOPIXEL_ENABLE
# ifdef NEOPIXEL_ENABLE
showRewind = true ;
showRewind = true ;
# endif
# endif
audio . connecttoFS ( FSystem , * ( playProperties . playlist + playProperties . currentTrackNumber ) ) ;
audioReturnCode = audio . connecttoFS ( FSystem , * ( playProperties . playlist + playProperties . currentTrackNumber ) ) ;
// consider track as finished, when audio lib call was not successful
if ( ! audioReturnCode ) {
playProperties . trackFinished = true ;
continue ;
}
loggerNl ( ( char * ) FPSTR ( trackStart ) , LOGLEVEL_INFO ) ;
loggerNl ( ( char * ) FPSTR ( trackStart ) , LOGLEVEL_INFO ) ;
trackCommand = 0 ;
trackCommand = 0 ;
continue ;
continue ;
@ -1677,7 +1693,12 @@ void playAudio(void *parameter) {
playProperties . trackFinished = true ;
playProperties . trackFinished = true ;
continue ;
continue ;
} else {
} else {
audio . connecttoFS ( FSystem , * ( playProperties . playlist + playProperties . currentTrackNumber ) ) ;
audioReturnCode = audio . connecttoFS ( FSystem , * ( playProperties . playlist + playProperties . currentTrackNumber ) ) ;
// consider track as finished, when audio lib call was not successful
if ( ! audioReturnCode ) {
playProperties . trackFinished = true ;
continue ;
}
# ifdef NEOPIXEL_ENABLE
# ifdef NEOPIXEL_ENABLE
showPlaylistProgress = true ;
showPlaylistProgress = true ;
# endif
# endif