diff --git a/platformio.ini b/platformio.ini index efe2bdf..246f2b0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,4 +29,5 @@ lib_deps = Adafruit Unified Sensor Adafruit BME280 Library https://github.com/samguyer/FastLED.git +; https://github.com/h3ndrik/FastLED.git lib_ignore = ESPAsyncTCP diff --git a/src/BME280.cpp b/src/BME280.cpp index 83d6257..ce2b136 100644 --- a/src/BME280.cpp +++ b/src/BME280.cpp @@ -11,10 +11,13 @@ bool BME280::begin(void) { // SPI.begin(BME_SCK, BME_MISO, BME_MOSI, BME_CS); pinMode(18, OUTPUT); digitalWrite(18, HIGH); // disable LoRa_CS + pinMode(23, OUTPUT); + digitalWrite(23, HIGH); // enable bme280 CS delay(50); bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI while (!(status = bme->begin())) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); +// bme->reset(); delay(500); } return true; diff --git a/src/led.cpp b/src/led.cpp index 80f3d63..c12dd0d 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -52,7 +52,6 @@ void Led::loop_steady(void) { } void Led::changeAnimation(uint8_t num, uint16_t duration) { - change = true; if (duration == 0) this->duration = UINT16_MAX; else this->duration = duration; if (num == 0) refresh = &Led::loop_steady; @@ -64,7 +63,6 @@ void Led::changeAnimation(uint8_t num, uint16_t duration) { void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) { color = CRGB(r, g, b); - change = true; } void Led::changeBrightness(uint8_t brightness) { if (brightness > 254) { // don't set first byte to 255 on tm1829 @@ -72,7 +70,6 @@ void Led::changeBrightness(uint8_t brightness) { } else { FastLED.setBrightness(brightness); } - change = true; } void Led::setup(void) { @@ -82,9 +79,8 @@ void Led::setup(void) { FastLED.setCorrection(0xFF5050); fill_solid(leds, NUM_LEDS, CRGB::White); color = CRGB::Orange; - change = true; - refresh = &Led::loop_steady; + refresh = &Led::loop_rainbow; delay(100); xTaskCreate( &cTaskWrapper, /* Task function. */ @@ -99,21 +95,19 @@ void Led::animationTask(void* parameters) { while(true) { if (refresh != nullptr) { (*this.*refresh)(); - if (refresh != (&Led::loop_steady) || change == true) FastLED.show(); - change = false; + FastLED.show(); // EVERY_N_MILLISECONDS ( 20) { index++; } index++; if (duration == 0) { - refresh = &Led::loop_steady; - change = true; + refresh = &Led::loop_rainbow; } else if (duration == UINT16_MAX) { } else { duration--; } - EVERY_N_SECONDS(300) { + EVERY_N_SECONDS(30) { // FastLED.clear(); // delay(200); - changeAnimation(3, 400); + changeAnimation(2, 2000); } } vTaskDelay(50 / portTICK_PERIOD_MS); diff --git a/src/led.h b/src/led.h index b029c09..4a0b642 100644 --- a/src/led.h +++ b/src/led.h @@ -28,7 +28,6 @@ class Led { void loop_denied(void); uint16_t duration; uint8_t index; - bool change; CRGB color; }; diff --git a/src/main.cpp b/src/main.cpp index 01f4e99..2224fdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ BME280 bme280; MP3 mp3; Rotary rotary; Screen* screen; -//Led led; +Led led; menuType menuChange = eNone; uint32_t lastButtonPress = 0; @@ -146,7 +146,7 @@ Serial.println(strftime_buf); } mp3.begin(); -// led.setup(); + led.setup(); rotary.registerCallback(rotation); rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); diff --git a/src/mp3.cpp b/src/mp3.cpp index 1e773d1..3fe4582 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -79,6 +79,10 @@ void MP3::setVolume(int volume) { } } +int MP3::getVolume() { + return volume; +} + uint32_t MP3::getBuffFill() { if (audiobuffer) return ((100U*audiobuffer->getFillLevel())/preallocateBufferSize); else return 0; @@ -128,7 +132,7 @@ void MP3::mp3_decoder_task(void *pvParameters) { playing = false; if (decoder) { - decoder->stop(); // ToDo: takes long + decoder->stop(); delete decoder; decoder = nullptr; } diff --git a/src/mp3.h b/src/mp3.h index 0f967f0..b93fffa 100644 --- a/src/mp3.h +++ b/src/mp3.h @@ -21,6 +21,7 @@ class MP3 { void start(void); void start(const char*); void setVolume(int); + int getVolume(); bool playing = false; int volume = 20; bool volumeChanged = true; diff --git a/src/screen.cpp b/src/screen.cpp index 2dcabdf..71c2aea 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -242,6 +242,10 @@ void MainScreen::draw() { // bme280.printValues(); } +MainScreen::MainScreen() { + volume = mp3.getVolume(); +} + uint8_t MainScreen::select() { menuChange = eMainMenu; } diff --git a/src/screen.h b/src/screen.h index 67bb853..f765ff5 100644 --- a/src/screen.h +++ b/src/screen.h @@ -19,6 +19,7 @@ #include "mp3.h" #include "BME280.h" #include "image.h" +#include "led.h" enum menuType { eNone=0, eWelcomeScreen, eMainScreen, eMainMenu, eStationMenu }; @@ -29,6 +30,7 @@ extern BME280 bme280; extern MP3 mp3; extern menuType menuChange; extern Basecamp iot; +extern Led led; class Screen { @@ -70,6 +72,7 @@ class SelectionList : public Screen { class MainScreen : public Screen { public: + MainScreen(); void draw(void) override; void next(void) override; void previous(void) override;