Browse Source

enable FastLED

main
Hendrik Langer 7 years ago
parent
commit
6dca832db7
  1. 1
      platformio.ini
  2. 3
      src/BME280.cpp
  3. 16
      src/led.cpp
  4. 1
      src/led.h
  5. 4
      src/main.cpp
  6. 6
      src/mp3.cpp
  7. 1
      src/mp3.h
  8. 4
      src/screen.cpp
  9. 3
      src/screen.h

1
platformio.ini

@ -29,4 +29,5 @@ lib_deps =
Adafruit Unified Sensor Adafruit Unified Sensor
Adafruit BME280 Library Adafruit BME280 Library
https://github.com/samguyer/FastLED.git https://github.com/samguyer/FastLED.git
; https://github.com/h3ndrik/FastLED.git
lib_ignore = ESPAsyncTCP lib_ignore = ESPAsyncTCP

3
src/BME280.cpp

@ -11,10 +11,13 @@ bool BME280::begin(void) {
// SPI.begin(BME_SCK, BME_MISO, BME_MOSI, BME_CS); // SPI.begin(BME_SCK, BME_MISO, BME_MOSI, BME_CS);
pinMode(18, OUTPUT); pinMode(18, OUTPUT);
digitalWrite(18, HIGH); // disable LoRa_CS digitalWrite(18, HIGH); // disable LoRa_CS
pinMode(23, OUTPUT);
digitalWrite(23, HIGH); // enable bme280 CS
delay(50); delay(50);
bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
while (!(status = bme->begin())) { while (!(status = bme->begin())) {
Serial.println("Could not find a valid BME280 sensor, check wiring!"); Serial.println("Could not find a valid BME280 sensor, check wiring!");
// bme->reset();
delay(500); delay(500);
} }
return true; return true;

16
src/led.cpp

@ -52,7 +52,6 @@ void Led::loop_steady(void) {
} }
void Led::changeAnimation(uint8_t num, uint16_t duration) { void Led::changeAnimation(uint8_t num, uint16_t duration) {
change = true;
if (duration == 0) this->duration = UINT16_MAX; if (duration == 0) this->duration = UINT16_MAX;
else this->duration = duration; else this->duration = duration;
if (num == 0) refresh = &Led::loop_steady; 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) { void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) {
color = CRGB(r, g, b); color = CRGB(r, g, b);
change = true;
} }
void Led::changeBrightness(uint8_t brightness) { void Led::changeBrightness(uint8_t brightness) {
if (brightness > 254) { // don't set first byte to 255 on tm1829 if (brightness > 254) { // don't set first byte to 255 on tm1829
@ -72,7 +70,6 @@ void Led::changeBrightness(uint8_t brightness) {
} else { } else {
FastLED.setBrightness(brightness); FastLED.setBrightness(brightness);
} }
change = true;
} }
void Led::setup(void) { void Led::setup(void) {
@ -82,9 +79,8 @@ void Led::setup(void) {
FastLED.setCorrection(0xFF5050); FastLED.setCorrection(0xFF5050);
fill_solid(leds, NUM_LEDS, CRGB::White); fill_solid(leds, NUM_LEDS, CRGB::White);
color = CRGB::Orange; color = CRGB::Orange;
change = true;
refresh = &Led::loop_steady; refresh = &Led::loop_rainbow;
delay(100); delay(100);
xTaskCreate( xTaskCreate(
&cTaskWrapper, /* Task function. */ &cTaskWrapper, /* Task function. */
@ -99,21 +95,19 @@ void Led::animationTask(void* parameters) {
while(true) { while(true) {
if (refresh != nullptr) { if (refresh != nullptr) {
(*this.*refresh)(); (*this.*refresh)();
if (refresh != (&Led::loop_steady) || change == true) FastLED.show(); FastLED.show();
change = false;
// EVERY_N_MILLISECONDS ( 20) { index++; } // EVERY_N_MILLISECONDS ( 20) { index++; }
index++; index++;
if (duration == 0) { if (duration == 0) {
refresh = &Led::loop_steady; refresh = &Led::loop_rainbow;
change = true;
} else if (duration == UINT16_MAX) { } else if (duration == UINT16_MAX) {
} else { } else {
duration--; duration--;
} }
EVERY_N_SECONDS(300) { EVERY_N_SECONDS(30) {
// FastLED.clear(); // FastLED.clear();
// delay(200); // delay(200);
changeAnimation(3, 400); changeAnimation(2, 2000);
} }
} }
vTaskDelay(50 / portTICK_PERIOD_MS); vTaskDelay(50 / portTICK_PERIOD_MS);

1
src/led.h

@ -28,7 +28,6 @@ class Led {
void loop_denied(void); void loop_denied(void);
uint16_t duration; uint16_t duration;
uint8_t index; uint8_t index;
bool change;
CRGB color; CRGB color;
}; };

4
src/main.cpp

@ -46,7 +46,7 @@ BME280 bme280;
MP3 mp3; MP3 mp3;
Rotary rotary; Rotary rotary;
Screen* screen; Screen* screen;
//Led led; Led led;
menuType menuChange = eNone; menuType menuChange = eNone;
uint32_t lastButtonPress = 0; uint32_t lastButtonPress = 0;
@ -146,7 +146,7 @@ Serial.println(strftime_buf);
} }
mp3.begin(); mp3.begin();
// led.setup(); led.setup();
rotary.registerCallback(rotation); rotary.registerCallback(rotation);
rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton);

6
src/mp3.cpp

@ -79,6 +79,10 @@ void MP3::setVolume(int volume) {
} }
} }
int MP3::getVolume() {
return volume;
}
uint32_t MP3::getBuffFill() { uint32_t MP3::getBuffFill() {
if (audiobuffer) return ((100U*audiobuffer->getFillLevel())/preallocateBufferSize); if (audiobuffer) return ((100U*audiobuffer->getFillLevel())/preallocateBufferSize);
else return 0; else return 0;
@ -128,7 +132,7 @@ void MP3::mp3_decoder_task(void *pvParameters) {
playing = false; playing = false;
if (decoder) { if (decoder) {
decoder->stop(); // ToDo: takes long decoder->stop();
delete decoder; delete decoder;
decoder = nullptr; decoder = nullptr;
} }

1
src/mp3.h

@ -21,6 +21,7 @@ class MP3 {
void start(void); void start(void);
void start(const char*); void start(const char*);
void setVolume(int); void setVolume(int);
int getVolume();
bool playing = false; bool playing = false;
int volume = 20; int volume = 20;
bool volumeChanged = true; bool volumeChanged = true;

4
src/screen.cpp

@ -242,6 +242,10 @@ void MainScreen::draw() {
// bme280.printValues(); // bme280.printValues();
} }
MainScreen::MainScreen() {
volume = mp3.getVolume();
}
uint8_t MainScreen::select() { uint8_t MainScreen::select() {
menuChange = eMainMenu; menuChange = eMainMenu;
} }

3
src/screen.h

@ -19,6 +19,7 @@
#include "mp3.h" #include "mp3.h"
#include "BME280.h" #include "BME280.h"
#include "image.h" #include "image.h"
#include "led.h"
enum menuType { eNone=0, eWelcomeScreen, eMainScreen, eMainMenu, eStationMenu }; enum menuType { eNone=0, eWelcomeScreen, eMainScreen, eMainMenu, eStationMenu };
@ -29,6 +30,7 @@ extern BME280 bme280;
extern MP3 mp3; extern MP3 mp3;
extern menuType menuChange; extern menuType menuChange;
extern Basecamp iot; extern Basecamp iot;
extern Led led;
class Screen { class Screen {
@ -70,6 +72,7 @@ class SelectionList : public Screen {
class MainScreen : public Screen { class MainScreen : public Screen {
public: public:
MainScreen();
void draw(void) override; void draw(void) override;
void next(void) override; void next(void) override;
void previous(void) override; void previous(void) override;

Loading…
Cancel
Save