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 BME280 Library
https://github.com/samguyer/FastLED.git
; https://github.com/h3ndrik/FastLED.git
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);
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;

16
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);

1
src/led.h

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

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

6
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;
}

1
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;

4
src/screen.cpp

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

3
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;

Loading…
Cancel
Save