Browse Source

draw buffer fill level, torn on debugging

main
Hendrik Langer 7 years ago
parent
commit
6157634bf2
  1. 2
      platformio.ini
  2. 5
      src/main.cpp
  3. 9
      src/mp3.cpp
  4. 3
      src/mp3.h
  5. 4
      src/screen.cpp

2
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

5
src/main.cpp

@ -1,6 +1,3 @@
//Define DEBUG to get the Output from DEBUG_PRINTLN
#define DEBUG 1
#include <Arduino.h>
//Include Basecamp in this sketch
@ -242,8 +239,8 @@ void loop()
localtime_r(&now, &timeinfo);
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo);
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
}
if(millis() - lastTransmit >= 60000) {

9
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();

3
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 */

4
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();

Loading…
Cancel
Save