Browse Source

platformio.ini: Add common variables as dynamic variables to all board configs.

main.cpp:
-Bug Fix: Handle return code of connecttofs routine. If it is not successful the track is considered as finished. This avoids freezing the tonuino.
-Feature: Voltage Measurement averages over multiple analog reads, which is smoothing the voltage value
-Feature: When pressing the previous button during audio play and the current track is already played for more than 2s, the current track is started again instead of the previous track
master
grch101 5 years ago
committed by Torsten Stauder
parent
commit
fb9d4584a3
  1. 13
      platformio.ini
  2. 29
      src/main.cpp

13
platformio.ini

@ -14,6 +14,8 @@ board = lolin32
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -23,6 +25,8 @@ board = lolin_d32
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -32,6 +36,8 @@ board = lolin_d32_pro
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -41,6 +47,8 @@ board = nodemcu-32s
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -50,6 +58,8 @@ board = az-delivery-devkit-v4
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -59,12 +69,13 @@ monitor_port = /dev/cu.SLAB_USBtoUART
;WINDOWS: COM3
;LINUX: /dev/ttyUSB0 (if it's the first USB-device attached, otherwise increase number)
[env:common]
lib_deps =
https://github.com/schreibfaul1/ESP32-audioI2S.git
https://github.com/madhephaestus/ESP32Encoder.git
https://github.com/knolleary/pubsubclient.git
https://github.com/biologist79/ESP32FTPServer.git
https://github.com/FastLED/FastLED.git#3.3.3
https://github.com/FastLED/FastLED.git
https://github.com/biologist79/rfid.git
https://github.com/tueddy/PN5180-Library.git
ESP Async WebServer

29
src/main.cpp

@ -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)
// The average of several analog reads will be taken to reduce the noise (Note: One analog read takes ~10µs)
#ifdef MEASURE_BATTERY_VOLTAGE
float measureBatteryVoltage(void) {
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) {
@ -1376,6 +1383,7 @@ void playAudio(void *parameter) {
uint8_t currentVolume;
static BaseType_t trackQStatus;
static uint8_t trackCommand = 0;
bool audioReturnCode;
for (;;) {
if (xQueueReceive(volumeQueue, &currentVolume, 0) == pdPASS ) {
@ -1518,7 +1526,10 @@ void playAudio(void *parameter) {
#endif
}
if (playProperties.currentTrackNumber > 0) {
playProperties.currentTrackNumber--;
// play previous track when current track time is small, else play current track again
if(audio.getAudioCurrentTime() < 2) {
playProperties.currentTrackNumber--;
}
if (playProperties.saveLastPlayPosition) {
nvsRfidWriteWrapper(playProperties.playRfidTag, *(playProperties.playlist + playProperties.currentTrackNumber), 0, playProperties.playMode, playProperties.currentTrackNumber, playProperties.numberOfTracks);
loggerNl((char *) FPSTR(trackStartAudiobook), LOGLEVEL_INFO);
@ -1544,7 +1555,12 @@ void playAudio(void *parameter) {
#ifdef NEOPIXEL_ENABLE
showRewind = true;
#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);
trackCommand = 0;
continue;
@ -1677,7 +1693,12 @@ void playAudio(void *parameter) {
playProperties.trackFinished = true;
continue;
} 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
showPlaylistProgress = true;
#endif

Loading…
Cancel
Save