From 6157634bf2aa48b50163d6c61ba085fb0a2ef25a Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 6 Feb 2018 02:03:47 +0100 Subject: [PATCH] draw buffer fill level, torn on debugging --- platformio.ini | 2 +- src/main.cpp | 7 ++----- src/mp3.cpp | 9 ++++++++- src/mp3.h | 3 +++ src/screen.cpp | 4 ++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7a0ed3a..cd09d66 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,7 +15,7 @@ board = heltec_wifi_lora_32 board_f_cpu = 240000000L board_f_flash = 80000000L framework = arduino -;build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_INFO -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y +build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DDEBUG_INT_ALLOC_DECISIONS=1 -DCONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y lib_deps = ; Basecamp diff --git a/src/main.cpp b/src/main.cpp index 39fbb97..d0654d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,3 @@ -//Define DEBUG to get the Output from DEBUG_PRINTLN -#define DEBUG 1 - #include //Include Basecamp in this sketch @@ -241,9 +238,9 @@ void loop() tzset(); localtime_r(&now, &timeinfo); -strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); + strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); + sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); - sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); } if(millis() - lastTransmit >= 60000) { diff --git a/src/mp3.cpp b/src/mp3.cpp index 7254799..4665229 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -79,6 +79,11 @@ void MP3::setVolume(int volume) { } } +uint32_t MP3::getBuffFill() { + if (audiobuffer) return ((100U*audiobuffer->getFillLevel())/(8*1024)); + else return 0; +} + void MP3::mp3_decoder_task(void *pvParameters) { AudioGenerator *decoder = nullptr; AudioFileSourceICYStream *file = nullptr; @@ -90,9 +95,10 @@ void MP3::mp3_decoder_task(void *pvParameters) { file = new AudioFileSourceICYStream(URL); file->RegisterMetadataCB(MDCallback, (void*)"ICY"); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); + audiobuffer = buff; buff->RegisterStatusCB(StatusCallback, (void*)"buffer"); if (out == NULL) { - out = new AudioOutputI2S(I2S_NUM_0, false, 0); + out = new AudioOutputI2S(I2S_NUM_0, false); out->SetPinout(12, 13, 25); } decoder = new AudioGeneratorMP3(preallocateCodec, preallocateCodecSize); @@ -130,6 +136,7 @@ void MP3::mp3_decoder_task(void *pvParameters) { buff->close(); delete buff; buff = nullptr; + audiobuffer = nullptr; } if (file) { file->close(); diff --git a/src/mp3.h b/src/mp3.h index 7ca3afe..547a33e 100644 --- a/src/mp3.h +++ b/src/mp3.h @@ -24,6 +24,7 @@ class MP3 { bool playing = false; int volume = 20; bool volumeChanged = true; + uint32_t getBuffFill(void); private: TaskHandle_t audioTaskHandle; void mp3_decoder_task(void*); @@ -33,6 +34,8 @@ class MP3 { static constexpr int preallocateCodecSize = 29192; // MP3 codec max mem needed void *preallocateBuffer = NULL; void *preallocateCodec = NULL; + + AudioFileSourceBuffer *audiobuffer = nullptr; }; #endif /* _MP3_H */ diff --git a/src/screen.cpp b/src/screen.cpp index 15d4a6e..2dcabdf 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -233,6 +233,10 @@ void MainScreen::draw() { } else { u8g2.drawUTF8((u8g2.getDisplayWidth()-width)/2, 54, titleStr); } + uint32_t buffFill = mp3.getBuffFill(); + if (buffFill > 0 && buffFill <= 100) { + u8g2.drawLine(10,60,10+buffFill,60); + } } u8g2.sendBuffer(); // bme280.printValues();