Pointers for Strip

- Pointers added for WS2812FX & NeoPixelBus
- new "REST API": /pixels?ct=xxx to change length of LED strip
- new "REST API": /pixels?rgbo=xxx to change RGB order
This commit is contained in:
Debashish Sahu 2019-01-24 13:31:15 -05:00
parent 0c473afb7d
commit 9efcb4530b
5 changed files with 165 additions and 116 deletions

View file

@ -84,39 +84,39 @@ ESP8266HTTPUpdateServer httpUpdater;
// *************************************************************************** // ***************************************************************************
// https://github.com/kitesurfer1404/WS2812FX // https://github.com/kitesurfer1404/WS2812FX
#include <WS2812FX.h> #include <WS2812FX.h>
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800); // WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
WS2812FX* strip;
// Parameter 1 = number of pixels in strip #if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
// Parameter 2 = Arduino pin number (most are valid) #include <NeoPixelBus.h>
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
#ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> NeoEsp8266Dma800KbpsMethod* dma;
NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) #endif
#ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
NeoEsp8266Uart0800KbpsMethod dma;
#endif
#ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
NeoEsp8266Uart1800KbpsMethod dma;
#endif
void initDMA(uint16_t stripSize = NUMLEDS){
#ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
dma = new NeoEsp8266Dma800KbpsMethod(stripSize, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) //NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
#endif #endif
#ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> dma = new NeoEsp8266Uart0800KbpsMethod(stripSize, 3);
NeoEsp8266Uart0800KbpsMethod dma = NeoEsp8266Uart0800KbpsMethod(NUMLEDS, 3);
#endif #endif
#ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
#include <NeoPixelBus.h> dma = new NeoEsp8266Uart1800KbpsMethod(stripSize, 3);
NeoEsp8266Uart1800KbpsMethod dma = NeoEsp8266Uart1800KbpsMethod(NUMLEDS, 3);
#endif #endif
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2) dma->Initialize();
}
void DMA_Show(void) { void DMA_Show(void) {
if(dma.IsReadyToUpdate()) { if(dma->IsReadyToUpdate()) {
memcpy(dma.getPixels(), strip.getPixels(), dma.getPixelsSize()); memcpy(dma->getPixels(), strip->getPixels(), dma->getPixelsSize());
dma.Update(); dma->Update();
} }
} }
#endif #endif
@ -205,10 +205,10 @@ void configModeCallback (WiFiManager *myWiFiManager) {
ticker.attach(0.2, tick); ticker.attach(0.2, tick);
uint16_t i; uint16_t i;
for (i = 0; i < strip.numPixels(); i++) { for (i = 0; i < strip->numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 255); strip->setPixelColor(i, 0, 0, 255);
} }
strip.show(); strip->show();
} }
//callback notifying us of the need to save config //callback notifying us of the need to save config
@ -227,6 +227,34 @@ void saveConfigCallback () {
// *************************************************************************** // ***************************************************************************
#include "request_handlers.h" #include "request_handlers.h"
//
void initStrip(uint16_t stripSize = NUMLEDS, neoPixelType RGBOrder = NEO_GRB){
strip = new WS2812FX(stripSize, PIN, RGBOrder + NEO_KHZ800);
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
strip->init();
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2)
initDMA(stripSize);
strip->setCustomShow(DMA_Show);
#endif
strip->setBrightness(brightness);
strip->setSpeed(convertSpeed(ws2812fx_speed));
//strip->setMode(FX_MODE_RAINBOW_CYCLE);
strip->setColor(main_color.red, main_color.green, main_color.blue);
strip->start();
}
// *************************************************************************** // ***************************************************************************
// Include: Color modes // Include: Color modes
// *************************************************************************** // ***************************************************************************
@ -274,16 +302,7 @@ void setup() {
// *************************************************************************** // ***************************************************************************
// Setup: Neopixel // Setup: Neopixel
// *************************************************************************** // ***************************************************************************
strip.init(); initStrip();
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART)
dma.Initialize();
strip.setCustomShow(DMA_Show);
#endif
strip.setBrightness(brightness);
strip.setSpeed(convertSpeed(ws2812fx_speed));
//strip.setMode(FX_MODE_RAINBOW_CYCLE);
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.start();
// *************************************************************************** // ***************************************************************************
// Setup: WiFiManager // Setup: WiFiManager
@ -675,7 +694,7 @@ void setup() {
if (server.arg("d").toInt() >= 0) { if (server.arg("d").toInt() >= 0) {
ws2812fx_speed = server.arg("d").toInt(); ws2812fx_speed = server.arg("d").toInt();
ws2812fx_speed = constrain(ws2812fx_speed, 0, 255); ws2812fx_speed = constrain(ws2812fx_speed, 0, 255);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str()); mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str());
#endif #endif
@ -717,6 +736,34 @@ void setup() {
getStatusJSON(); getStatusJSON();
}); });
server.on("/pixels", []() {
if(server.hasArg("ct")){
uint16_t pixelCt = server.arg("ct").toInt();
if (pixelCt > 0) {
initStrip(pixelCt);
DBG_OUTPUT_PORT.printf("/pixels: Count# %d\n", pixelCt);
}
}
if(server.hasArg("rgbo")){
String RGBOrder = server.arg("rgbo");
DBG_OUTPUT_PORT.print("/pixels: RGB Order# ");
if (RGBOrder == "grb") {
initStrip(strip->getLength(), NEO_GRB);
} else if (RGBOrder == "gbr") {
initStrip(strip->getLength(), NEO_GBR);
} else if (RGBOrder == "rgb") {
initStrip(strip->getLength(), NEO_RGB);
} else if (RGBOrder == "rbg") {
initStrip(strip->getLength(), NEO_RBG);
} else if (RGBOrder == "brg") {
initStrip(strip->getLength(), NEO_BRG);
} else if (RGBOrder == "bgr") {
initStrip(strip->getLength(), NEO_BGR);
}
DBG_OUTPUT_PORT.println(RGBOrder);
}
});
server.on("/off", []() { server.on("/off", []() {
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
exit_func = true; exit_func = true;
@ -1018,63 +1065,63 @@ void loop() {
// Simple statemachine that handles the different modes // Simple statemachine that handles the different modes
if (mode == SET_MODE) { if (mode == SET_MODE) {
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode); DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
strip.setMode(ws2812fx_mode); strip->setMode(ws2812fx_mode);
strip.trigger(); strip->trigger();
prevmode = SET_MODE; prevmode = SET_MODE;
mode = SETCOLOR; mode = SETCOLOR;
} }
if (mode == OFF) { if (mode == OFF) {
if(strip.isRunning()) strip.stop(); //should clear memory if(strip->isRunning()) strip->stop(); //should clear memory
// mode = HOLD; // mode = HOLD;
} }
if (mode == SETCOLOR) { if (mode == SETCOLOR) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.trigger(); strip->trigger();
mode = (prevmode == SET_MODE) ? SETSPEED : HOLD; mode = (prevmode == SET_MODE) ? SETSPEED : HOLD;
} }
if (mode == SETSPEED) { if (mode == SETSPEED) {
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.trigger(); strip->trigger();
mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD; mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD;
} }
if (mode == BRIGHTNESS) { if (mode == BRIGHTNESS) {
strip.setBrightness(brightness); strip->setBrightness(brightness);
strip.trigger(); strip->trigger();
if (prevmode == SET_MODE) prevmode = HOLD; if (prevmode == SET_MODE) prevmode = HOLD;
mode = HOLD; mode = HOLD;
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (mode == WIPE) { if (mode == WIPE) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_COLOR_WIPE); strip->setMode(FX_MODE_COLOR_WIPE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == RAINBOW) { if (mode == RAINBOW) {
strip.setMode(FX_MODE_RAINBOW); strip->setMode(FX_MODE_RAINBOW);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == RAINBOWCYCLE) { if (mode == RAINBOWCYCLE) {
strip.setMode(FX_MODE_RAINBOW_CYCLE); strip->setMode(FX_MODE_RAINBOW_CYCLE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == THEATERCHASE) { if (mode == THEATERCHASE) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_THEATER_CHASE); strip->setMode(FX_MODE_THEATER_CHASE);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == TWINKLERANDOM) { if (mode == TWINKLERANDOM) {
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
strip.setMode(FX_MODE_TWINKLE_RANDOM); strip->setMode(FX_MODE_TWINKLE_RANDOM);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
if (mode == THEATERCHASERAINBOW) { if (mode == THEATERCHASERAINBOW) {
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW); strip->setMode(FX_MODE_THEATER_CHASE_RAINBOW);
strip.trigger(); strip->trigger();
mode = HOLD; mode = HOLD;
} }
#ifdef ENABLE_E131 #ifdef ENABLE_E131
@ -1084,7 +1131,7 @@ void loop() {
#endif #endif
#endif #endif
if (mode == HOLD || mode == CUSTOM) { if (mode == HOLD || mode == CUSTOM) {
if(!strip.isRunning()) strip.start(); if(!strip->isRunning()) strip->start();
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (exit_func) { if (exit_func) {
exit_func = false; exit_func = false;
@ -1094,7 +1141,7 @@ void loop() {
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
if (mode == TV) { if (mode == TV) {
if(!strip.isRunning()) strip.start(); if(!strip->isRunning()) strip->start();
tv(); tv();
} }
#endif #endif
@ -1105,7 +1152,7 @@ void loop() {
#else #else
if (mode != CUSTOM) { if (mode != CUSTOM) {
#endif #endif
strip.service(); strip->service();
} }
#ifdef ENABLE_STATE_SAVE_SPIFFS #ifdef ENABLE_STATE_SAVE_SPIFFS
@ -1116,7 +1163,7 @@ void loop() {
#ifdef ENABLE_STATE_SAVE_EEPROM #ifdef ENABLE_STATE_SAVE_EEPROM
// Check for state changes // Check for state changes
sprintf(current_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d", mode, strip.getMode(), ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue); sprintf(current_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d", mode, strip->getMode(), ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
if (strcmp(current_state, last_state) != 0) { if (strcmp(current_state, last_state) != 0) {
// DBG_OUTPUT_PORT.printf("STATE CHANGED: %s / %s\n", last_state, current_state); // DBG_OUTPUT_PORT.printf("STATE CHANGED: %s / %s\n", last_state, current_state);

View file

@ -25,7 +25,7 @@ void hsb2rgbAN1(uint16_t index, uint8_t sat, uint8_t bright, uint8_t myled) {
temp[1] = temp[4] = (uint8_t)((((( (index & 255) * sat) / 255) + (sat ^ 255)) * bright) / 255); temp[1] = temp[4] = (uint8_t)((((( (index & 255) * sat) / 255) + (sat ^ 255)) * bright) / 255);
temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255); temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255);
strip.setPixelColor(myled, temp[n + 2], temp[n + 1], temp[n]); strip->setPixelColor(myled, temp[n + 2], temp[n + 1], temp[n]);
} }
@ -37,7 +37,7 @@ void updateLed (int led, int brightness) {
uint16_t index = (i%3 == 0) ? 400 : random(0,767); uint16_t index = (i%3 == 0) ? 400 : random(0,767);
hsb2rgbAN1(index, 200, ledStates[i], i); hsb2rgbAN1(index, 200, ledStates[i], i);
} }
strip.show(); strip->show();
} }
@ -61,7 +61,7 @@ void tv() {
} }
if(currentMillis-previousMillis<twitch) if(currentMillis-previousMillis<twitch)
{ {
led=random(0, (strip.numPixels()-1)); led=random(0, (strip->numPixels()-1));
analogLevel=random(50,255);// set the range of the 3 pwm leds analogLevel=random(50,255);// set the range of the 3 pwm leds
ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa: ledState = ledState == LOW ? HIGH: LOW; // if the LED is off turn it on and vice-versa:
@ -76,7 +76,7 @@ void tv() {
darkTime = random(50,150); darkTime = random(50,150);
dipInterval = random(5,250);// cycles of flicker dipInterval = random(5,250);// cycles of flicker
} }
//strip.show(); //strip->show();
} }
} }
else else
@ -85,7 +85,7 @@ void tv() {
currentDipTime = millis(); currentDipTime = millis();
if (currentDipTime - dipStartTime < darkTime) if (currentDipTime - dipStartTime < darkTime)
{ {
for (int i=3; i<strip.numPixels(); i++) for (int i=3; i<strip->numPixels(); i++)
{ {
updateLed(i, 0); updateLed(i, 0);
} }
@ -94,6 +94,6 @@ void tv() {
{ {
timeToDip = false; timeToDip = false;
} }
strip.show(); strip->show();
} }
} }

View file

@ -27,9 +27,9 @@ void handleE131(){
uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170; uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170;
for (uint16_t i = 0; i < len; i++){ for (uint16_t i = 0; i < len; i++){
uint16_t j = i * 3; uint16_t j = i * 3;
strip.setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]); strip->setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]);
} }
strip.show(); strip->show();
checkForRequests(); checkForRequests();
} }
} }
@ -63,7 +63,7 @@ void getArgs() {
} }
if (server.arg("m") != "") { if (server.arg("m") != "") {
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1); ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
} }
if (server.arg("c").toInt() > 0) { if (server.arg("c").toInt() > 0) {
@ -114,7 +114,7 @@ void handleSetMainColor(uint8_t * mypayload) {
main_color.red = ((rgb >> 16) & 0xFF); main_color.red = ((rgb >> 16) & 0xFF);
main_color.green = ((rgb >> 8) & 0xFF); main_color.green = ((rgb >> 8) & 0xFF);
main_color.blue = ((rgb >> 0) & 0xFF); main_color.blue = ((rgb >> 0) & 0xFF);
// strip.setColor(main_color.red, main_color.green, main_color.blue); // strip->setColor(main_color.red, main_color.green, main_color.blue);
mode = SETCOLOR; mode = SETCOLOR;
} }
@ -140,8 +140,8 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
strncpy (templed, (const char *) &mypayload[firstChar], 2 ); strncpy (templed, (const char *) &mypayload[firstChar], 2 );
uint8_t led = atoi(templed); uint8_t led = atoi(templed);
DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip.numPixels(), mypayload ); DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip->numPixels(), mypayload );
if (led <= strip.numPixels()) { if (led <= strip->numPixels()) {
char redhex[3]; char redhex[3];
char greenhex[3]; char greenhex[3];
char bluehex[3]; char bluehex[3];
@ -156,8 +156,8 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload); DBG_OUTPUT_PORT.printf("WS: Set single led [%i] to [%i] [%i] [%i] (%s)!\n", led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, mypayload);
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); strip->setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue);
strip.show(); strip->show();
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
exit_func = true; exit_func = true;
@ -234,10 +234,10 @@ void setModeByStateString(String saved_state_string) {
DBG_OUTPUT_PORT.printf("main_color.green: %d\n", main_color.green); DBG_OUTPUT_PORT.printf("main_color.green: %d\n", main_color.green);
DBG_OUTPUT_PORT.printf("main_color.blue: %d\n", main_color.blue); DBG_OUTPUT_PORT.printf("main_color.blue: %d\n", main_color.blue);
strip.setMode(ws2812fx_mode); strip->setMode(ws2812fx_mode);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.setBrightness(brightness); strip->setBrightness(brightness);
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
} }
#ifdef ENABLE_LEGACY_ANIMATIONS #ifdef ENABLE_LEGACY_ANIMATIONS
@ -306,7 +306,7 @@ void setModeByStateString(String saved_state_string) {
void handleE131NamedMode(String str_mode) { void handleE131NamedMode(String str_mode) {
exit_func = true; exit_func = true;
if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) { if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) {
if(strip.isRunning()) strip.stop(); if(strip->isRunning()) strip->stop();
mode = E131; mode = E131;
#ifdef ENABLE_HOMEASSISTANT #ifdef ENABLE_HOMEASSISTANT
stateOn = true; stateOn = true;
@ -318,18 +318,18 @@ void setModeByStateString(String saved_state_string) {
void handleSetWS2812FXMode(uint8_t * mypayload) { void handleSetWS2812FXMode(uint8_t * mypayload) {
mode = SET_MODE; mode = SET_MODE;
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10); uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip.getModeCount() - 1); ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip->getModeCount() - 1);
} }
String listStatusJSON(void) { String listStatusJSON(void) {
uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip.getMode(); uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip->getMode();
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6) + 500; const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(6) + 500;
DynamicJsonDocument jsonBuffer(bufferSize); DynamicJsonDocument jsonBuffer(bufferSize);
JsonObject root = jsonBuffer.to<JsonObject>(); JsonObject root = jsonBuffer.to<JsonObject>();
root["mode"] = (uint8_t) mode; root["mode"] = (uint8_t) mode;
root["ws2812fx_mode"] = tmp_mode; root["ws2812fx_mode"] = tmp_mode;
root["ws2812fx_mode_name"] = strip.getModeName(tmp_mode); root["ws2812fx_mode_name"] = strip->getModeName(tmp_mode);
root["speed"] = ws2812fx_speed; root["speed"] = ws2812fx_speed;
root["brightness"] = brightness; root["brightness"] = brightness;
JsonArray color = root.createNestedArray("color"); JsonArray color = root.createNestedArray("color");
@ -349,7 +349,7 @@ void getStatusJSON() {
} }
String listModesJSON(void) { String listModesJSON(void) {
const size_t bufferSize = JSON_ARRAY_SIZE(strip.getModeCount()+1) + strip.getModeCount()*JSON_OBJECT_SIZE(2) + 1000; const size_t bufferSize = JSON_ARRAY_SIZE(strip->getModeCount()+1) + strip->getModeCount()*JSON_OBJECT_SIZE(2) + 1000;
DynamicJsonDocument jsonBuffer(bufferSize); DynamicJsonDocument jsonBuffer(bufferSize);
JsonArray json = jsonBuffer.to<JsonArray>(); JsonArray json = jsonBuffer.to<JsonArray>();
#ifdef ENABLE_E131 #ifdef ENABLE_E131
@ -357,10 +357,10 @@ String listModesJSON(void) {
objecte131["mode"] = "e131"; objecte131["mode"] = "e131";
objecte131["name"] = "E131"; objecte131["name"] = "E131";
#endif #endif
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
JsonObject object = json.createNestedObject(); JsonObject object = json.createNestedObject();
object["mode"] = i; object["mode"] = i;
object["name"] = strip.getModeName(i); object["name"] = strip->getModeName(i);
} }
JsonObject object = json.createNestedObject(); JsonObject object = json.createNestedObject();
@ -422,9 +422,9 @@ Ticker autoTicker;
int autoCount = 0; int autoCount = 0;
void autoTick() { void autoTick() {
strip.setColor(autoParams[autoCount][0]); strip->setColor(autoParams[autoCount][0]);
strip.setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1])); strip->setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1]));
strip.setMode((uint8_t)autoParams[autoCount][2]); strip->setMode((uint8_t)autoParams[autoCount][2]);
autoTicker.once((float)autoParams[autoCount][3], autoTick); autoTicker.once((float)autoParams[autoCount][3], autoTick);
DBG_OUTPUT_PORT.print("autoTick "); DBG_OUTPUT_PORT.print("autoTick ");
DBG_OUTPUT_PORT.println(autoCount); DBG_OUTPUT_PORT.println(autoCount);
@ -436,12 +436,12 @@ void autoTick() {
void handleAutoStart() { void handleAutoStart() {
autoCount = 0; autoCount = 0;
autoTick(); autoTick();
strip.start(); strip->start();
} }
void handleAutoStop() { void handleAutoStop() {
autoTicker.detach(); autoTicker.detach();
strip.stop(); strip->stop();
} }
void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
@ -839,14 +839,14 @@ void checkForRequests() {
root["speed"] = ws2812fx_speed; root["speed"] = ws2812fx_speed;
//char modeName[30]; //char modeName[30];
//strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem //strncpy_P(modeName, (PGM_P)strip->getModeName(strip->getMode()), sizeof(modeName)); // copy from progmem
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT) #if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
if (mode == E131) if (mode == E131)
root["effect"] = "E131"; root["effect"] = "E131";
else else
root["effect"] = strip.getModeName(strip.getMode()); root["effect"] = strip->getModeName(strip->getMode());
#else #else
root["effect"] = strip.getModeName(strip.getMode()); root["effect"] = strip->getModeName(strip->getMode());
#endif #endif
char buffer[measureJson(root) + 1]; char buffer[measureJson(root) + 1];
@ -925,15 +925,15 @@ void checkForRequests() {
animation_on = true; animation_on = true;
String effectString = root["effect"].as<String>(); String effectString = root["effect"].as<String>();
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT) #if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
if(effectString == "E131"){ if(effectString == "E131"){
if(strip.isRunning()) strip.stop(); if(strip->isRunning()) strip->stop();
mode = E131; mode = E131;
break; break;
} }
#endif #endif
if(String(strip.getModeName(i)) == effectString) { if(String(strip->getModeName(i)) == effectString) {
mode = SET_MODE; mode = SET_MODE;
ws2812fx_mode = i; ws2812fx_mode = i;
break; break;
@ -1007,7 +1007,7 @@ void checkForRequests() {
ha_send_data.detach(); ha_send_data.detach();
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub); mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub);
#ifdef MQTT_HOME_ASSISTANT_SUPPORT #ifdef MQTT_HOME_ASSISTANT_SUPPORT
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12) + 1500); DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip->getModeCount()) + JSON_OBJECT_SIZE(12) + 1500);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["name"] = HOSTNAME; json["name"] = HOSTNAME;
#ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT
@ -1024,8 +1024,8 @@ void checkForRequests() {
json["color_temp"] = "true"; json["color_temp"] = "true";
json["effect"] = "true"; json["effect"] = "true";
JsonArray effect_list = json.createNestedArray("effect_list"); JsonArray effect_list = json.createNestedArray("effect_list");
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
effect_list.add(strip.getModeName(i)); effect_list.add(strip->getModeName(i));
} }
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
effect_list.add("E131"); effect_list.add("E131");
@ -1094,7 +1094,7 @@ void checkForRequests() {
uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in.c_str(), qossub); uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in.c_str(), qossub);
DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2); DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2);
#ifdef MQTT_HOME_ASSISTANT_SUPPORT #ifdef MQTT_HOME_ASSISTANT_SUPPORT
DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip.getModeCount()) + JSON_OBJECT_SIZE(12) + 1500); DynamicJsonDocument jsonBuffer(JSON_ARRAY_SIZE(strip->getModeCount()) + JSON_OBJECT_SIZE(12) + 1500);
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["name"] = HOSTNAME; json["name"] = HOSTNAME;
#ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT
@ -1111,8 +1111,8 @@ void checkForRequests() {
json["color_temp"] = "true"; json["color_temp"] = "true";
json["effect"] = "true"; json["effect"] = "true";
JsonArray effect_list = json.createNestedArray("effect_list"); JsonArray effect_list = json.createNestedArray("effect_list");
for (uint8_t i = 0; i < strip.getModeCount(); i++) { for (uint8_t i = 0; i < strip->getModeCount(); i++) {
effect_list.add(strip.getModeName(i)); effect_list.add(strip->getModeName(i));
} }
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
effect_list.add("E131"); effect_list.add("E131");
@ -1343,7 +1343,7 @@ bool writeStateFS(){
DynamicJsonDocument jsonBuffer; DynamicJsonDocument jsonBuffer;
JsonObject json = jsonBuffer.to<JsonObject>(); JsonObject json = jsonBuffer.to<JsonObject>();
json["mode"] = static_cast<int>(mode); json["mode"] = static_cast<int>(mode);
json["strip_mode"] = (int) strip.getMode(); json["strip_mode"] = (int) strip->getMode();
json["brightness"] = brightness; json["brightness"] = brightness;
json["speed"] = ws2812fx_speed; json["speed"] = ws2812fx_speed;
json["red"] = main_color.red; json["red"] = main_color.red;
@ -1395,14 +1395,14 @@ bool readStateFS() {
main_color.green = json["green"]; main_color.green = json["green"];
main_color.blue = json["blue"]; main_color.blue = json["blue"];
strip.setMode(ws2812fx_mode); strip->setMode(ws2812fx_mode);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip->setSpeed(convertSpeed(ws2812fx_speed));
strip.setBrightness(brightness); strip->setBrightness(brightness);
strip.setColor(main_color.red, main_color.green, main_color.blue); strip->setColor(main_color.red, main_color.green, main_color.blue);
#ifdef ENABLE_E131 #ifdef ENABLE_E131
if (mode == E131) { if (mode == E131) {
strip.stop(); strip->stop();
} }
#endif #endif

View file

@ -65,5 +65,7 @@
* - Minor fixes related to NeoPixelBus UART methods * - Minor fixes related to NeoPixelBus UART methods
* - Modify platformio.ini for future bump to esp8266-arduino v2.5.0 (shamelessly stolen settings from espurna project) * - Modify platformio.ini for future bump to esp8266-arduino v2.5.0 (shamelessly stolen settings from espurna project)
* - Gzipped index2.htm & edit.htm.gz(untouched), convereted to hex format using xxd -i abcd.gz > html_gz.h * - Gzipped index2.htm & edit.htm.gz(untouched), convereted to hex format using xxd -i abcd.gz > html_gz.h
* - Think about using pointers for WS2812FX (no code regarding this in initial push) * - Pointers added for WS2812FX & NeoPixelBus
* - new "REST API": /pixels?ct=xxx to change length of LED strip
* - new "REST API": /pixels?rgbo=xxx to change RGB order
*/ */

View file

@ -1,6 +1,6 @@
# McLighting v2 - The ESP8266 based multi-client lighting gadget # McLighting v2 - The ESP8266 based multi-client lighting gadget
[![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v2.2.0-blue.svg)](https://github.com/toblum/McLighting/blob/master/Arduino/McLighting/version.h) [![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v2.2.1-blue.svg)](https://github.com/toblum/McLighting/blob/master/Arduino/McLighting/version.h)
McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector. McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector.