diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 488a083..585a820 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -84,39 +84,39 @@ ESP8266HTTPUpdateServer httpUpdater; // *************************************************************************** // https://github.com/kitesurfer1404/WS2812FX #include -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 -// 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. +#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2) +#include #ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods - #include - NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) + NeoEsp8266Dma800KbpsMethod* dma; +#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) #endif #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods - #include - NeoEsp8266Uart0800KbpsMethod dma = NeoEsp8266Uart0800KbpsMethod(NUMLEDS, 3); + dma = new NeoEsp8266Uart0800KbpsMethod(stripSize, 3); #endif #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods - #include - NeoEsp8266Uart1800KbpsMethod dma = NeoEsp8266Uart1800KbpsMethod(NUMLEDS, 3); + dma = new NeoEsp8266Uart1800KbpsMethod(stripSize, 3); #endif -#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART1) or defined(USE_WS2812FX_UART2) + dma->Initialize(); +} void DMA_Show(void) { - if(dma.IsReadyToUpdate()) { - memcpy(dma.getPixels(), strip.getPixels(), dma.getPixelsSize()); - dma.Update(); + if(dma->IsReadyToUpdate()) { + memcpy(dma->getPixels(), strip->getPixels(), dma->getPixelsSize()); + dma->Update(); } } #endif @@ -205,10 +205,10 @@ void configModeCallback (WiFiManager *myWiFiManager) { ticker.attach(0.2, tick); uint16_t i; - for (i = 0; i < strip.numPixels(); i++) { - strip.setPixelColor(i, 0, 0, 255); + for (i = 0; i < strip->numPixels(); i++) { + strip->setPixelColor(i, 0, 0, 255); } - strip.show(); + strip->show(); } //callback notifying us of the need to save config @@ -227,6 +227,34 @@ void saveConfigCallback () { // *************************************************************************** #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 // *************************************************************************** @@ -274,16 +302,7 @@ void setup() { // *************************************************************************** // Setup: Neopixel // *************************************************************************** - strip.init(); - #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(); + initStrip(); // *************************************************************************** // Setup: WiFiManager @@ -675,7 +694,7 @@ void setup() { if (server.arg("d").toInt() >= 0) { ws2812fx_speed = server.arg("d").toInt(); ws2812fx_speed = constrain(ws2812fx_speed, 0, 255); - strip.setSpeed(convertSpeed(ws2812fx_speed)); + strip->setSpeed(convertSpeed(ws2812fx_speed)); #ifdef ENABLE_MQTT mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str()); #endif @@ -717,6 +736,34 @@ void setup() { 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", []() { #ifdef ENABLE_LEGACY_ANIMATIONS exit_func = true; @@ -1018,63 +1065,63 @@ void loop() { // Simple statemachine that handles the different modes if (mode == SET_MODE) { DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode); - strip.setMode(ws2812fx_mode); - strip.trigger(); + strip->setMode(ws2812fx_mode); + strip->trigger(); prevmode = SET_MODE; mode = SETCOLOR; } if (mode == OFF) { - if(strip.isRunning()) strip.stop(); //should clear memory + if(strip->isRunning()) strip->stop(); //should clear memory // mode = HOLD; } if (mode == SETCOLOR) { - strip.setColor(main_color.red, main_color.green, main_color.blue); - strip.trigger(); + strip->setColor(main_color.red, main_color.green, main_color.blue); + strip->trigger(); mode = (prevmode == SET_MODE) ? SETSPEED : HOLD; } if (mode == SETSPEED) { - strip.setSpeed(convertSpeed(ws2812fx_speed)); - strip.trigger(); + strip->setSpeed(convertSpeed(ws2812fx_speed)); + strip->trigger(); mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD; } if (mode == BRIGHTNESS) { - strip.setBrightness(brightness); - strip.trigger(); + strip->setBrightness(brightness); + strip->trigger(); if (prevmode == SET_MODE) prevmode = HOLD; mode = HOLD; } #ifdef ENABLE_LEGACY_ANIMATIONS if (mode == WIPE) { - strip.setColor(main_color.red, main_color.green, main_color.blue); - strip.setMode(FX_MODE_COLOR_WIPE); - strip.trigger(); + strip->setColor(main_color.red, main_color.green, main_color.blue); + strip->setMode(FX_MODE_COLOR_WIPE); + strip->trigger(); mode = HOLD; } if (mode == RAINBOW) { - strip.setMode(FX_MODE_RAINBOW); - strip.trigger(); + strip->setMode(FX_MODE_RAINBOW); + strip->trigger(); mode = HOLD; } if (mode == RAINBOWCYCLE) { - strip.setMode(FX_MODE_RAINBOW_CYCLE); - strip.trigger(); + strip->setMode(FX_MODE_RAINBOW_CYCLE); + strip->trigger(); mode = HOLD; } if (mode == THEATERCHASE) { - strip.setColor(main_color.red, main_color.green, main_color.blue); - strip.setMode(FX_MODE_THEATER_CHASE); - strip.trigger(); + strip->setColor(main_color.red, main_color.green, main_color.blue); + strip->setMode(FX_MODE_THEATER_CHASE); + strip->trigger(); mode = HOLD; } if (mode == TWINKLERANDOM) { - strip.setColor(main_color.red, main_color.green, main_color.blue); - strip.setMode(FX_MODE_TWINKLE_RANDOM); - strip.trigger(); + strip->setColor(main_color.red, main_color.green, main_color.blue); + strip->setMode(FX_MODE_TWINKLE_RANDOM); + strip->trigger(); mode = HOLD; } if (mode == THEATERCHASERAINBOW) { - strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW); - strip.trigger(); + strip->setMode(FX_MODE_THEATER_CHASE_RAINBOW); + strip->trigger(); mode = HOLD; } #ifdef ENABLE_E131 @@ -1084,7 +1131,7 @@ void loop() { #endif #endif if (mode == HOLD || mode == CUSTOM) { - if(!strip.isRunning()) strip.start(); + if(!strip->isRunning()) strip->start(); #ifdef ENABLE_LEGACY_ANIMATIONS if (exit_func) { exit_func = false; @@ -1094,7 +1141,7 @@ void loop() { } #ifdef ENABLE_LEGACY_ANIMATIONS if (mode == TV) { - if(!strip.isRunning()) strip.start(); + if(!strip->isRunning()) strip->start(); tv(); } #endif @@ -1105,7 +1152,7 @@ void loop() { #else if (mode != CUSTOM) { #endif - strip.service(); + strip->service(); } #ifdef ENABLE_STATE_SAVE_SPIFFS @@ -1116,7 +1163,7 @@ void loop() { #ifdef ENABLE_STATE_SAVE_EEPROM // 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) { // DBG_OUTPUT_PORT.printf("STATE CHANGED: %s / %s\n", last_state, current_state); diff --git a/Arduino/McLighting/colormodes.h b/Arduino/McLighting/colormodes.h index 2d73c5e..9d79086 100644 --- a/Arduino/McLighting/colormodes.h +++ b/Arduino/McLighting/colormodes.h @@ -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[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); hsb2rgbAN1(index, 200, ledStates[i], i); } - strip.show(); + strip->show(); } @@ -61,7 +61,7 @@ void tv() { } if(currentMillis-previousMillisnumPixels()-1)); 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: @@ -76,7 +76,7 @@ void tv() { darkTime = random(50,150); dipInterval = random(5,250);// cycles of flicker } - //strip.show(); + //strip->show(); } } else @@ -85,7 +85,7 @@ void tv() { currentDipTime = millis(); if (currentDipTime - dipStartTime < darkTime) { - for (int i=3; inumPixels(); i++) { updateLed(i, 0); } @@ -94,6 +94,6 @@ void tv() { { timeToDip = false; } - strip.show(); + strip->show(); } -} +} diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index d02e605..479ccbc 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -27,9 +27,9 @@ void handleE131(){ uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170; for (uint16_t i = 0; i < len; i++){ 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(); } } @@ -63,7 +63,7 @@ void getArgs() { } 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) { @@ -114,7 +114,7 @@ void handleSetMainColor(uint8_t * mypayload) { main_color.red = ((rgb >> 16) & 0xFF); main_color.green = ((rgb >> 8) & 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; } @@ -140,8 +140,8 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) { strncpy (templed, (const char *) &mypayload[firstChar], 2 ); uint8_t led = atoi(templed); - DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip.numPixels(), mypayload ); - if (led <= strip.numPixels()) { + DBG_OUTPUT_PORT.printf("led value: [%i]. Entry threshold: <= [%i] (=> %s)\n", led, strip->numPixels(), mypayload ); + if (led <= strip->numPixels()) { char redhex[3]; char greenhex[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); - strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); - strip.show(); + strip->setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue); + strip->show(); } #ifdef ENABLE_LEGACY_ANIMATIONS 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.blue: %d\n", main_color.blue); - strip.setMode(ws2812fx_mode); - strip.setSpeed(convertSpeed(ws2812fx_speed)); - strip.setBrightness(brightness); - strip.setColor(main_color.red, main_color.green, main_color.blue); + strip->setMode(ws2812fx_mode); + strip->setSpeed(convertSpeed(ws2812fx_speed)); + strip->setBrightness(brightness); + strip->setColor(main_color.red, main_color.green, main_color.blue); } #ifdef ENABLE_LEGACY_ANIMATIONS @@ -306,7 +306,7 @@ void setModeByStateString(String saved_state_string) { void handleE131NamedMode(String str_mode) { exit_func = true; if (str_mode.startsWith("=e131") or str_mode.startsWith("/e131")) { - if(strip.isRunning()) strip.stop(); + if(strip->isRunning()) strip->stop(); mode = E131; #ifdef ENABLE_HOMEASSISTANT stateOn = true; @@ -318,18 +318,18 @@ void setModeByStateString(String saved_state_string) { void handleSetWS2812FXMode(uint8_t * mypayload) { mode = SET_MODE; 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) { - 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; DynamicJsonDocument jsonBuffer(bufferSize); JsonObject root = jsonBuffer.to(); root["mode"] = (uint8_t) 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["brightness"] = brightness; JsonArray color = root.createNestedArray("color"); @@ -349,7 +349,7 @@ void getStatusJSON() { } 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); JsonArray json = jsonBuffer.to(); #ifdef ENABLE_E131 @@ -357,10 +357,10 @@ String listModesJSON(void) { objecte131["mode"] = "e131"; objecte131["name"] = "E131"; #endif - for (uint8_t i = 0; i < strip.getModeCount(); i++) { + for (uint8_t i = 0; i < strip->getModeCount(); i++) { JsonObject object = json.createNestedObject(); object["mode"] = i; - object["name"] = strip.getModeName(i); + object["name"] = strip->getModeName(i); } JsonObject object = json.createNestedObject(); @@ -422,9 +422,9 @@ Ticker autoTicker; int autoCount = 0; void autoTick() { - strip.setColor(autoParams[autoCount][0]); - strip.setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1])); - strip.setMode((uint8_t)autoParams[autoCount][2]); + strip->setColor(autoParams[autoCount][0]); + strip->setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1])); + strip->setMode((uint8_t)autoParams[autoCount][2]); autoTicker.once((float)autoParams[autoCount][3], autoTick); DBG_OUTPUT_PORT.print("autoTick "); DBG_OUTPUT_PORT.println(autoCount); @@ -436,12 +436,12 @@ void autoTick() { void handleAutoStart() { autoCount = 0; autoTick(); - strip.start(); + strip->start(); } void handleAutoStop() { autoTicker.detach(); - strip.stop(); + strip->stop(); } void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) { @@ -839,14 +839,14 @@ void checkForRequests() { root["speed"] = ws2812fx_speed; //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 (mode == E131) root["effect"] = "E131"; else - root["effect"] = strip.getModeName(strip.getMode()); + root["effect"] = strip->getModeName(strip->getMode()); #else - root["effect"] = strip.getModeName(strip.getMode()); + root["effect"] = strip->getModeName(strip->getMode()); #endif char buffer[measureJson(root) + 1]; @@ -925,15 +925,15 @@ void checkForRequests() { animation_on = true; String effectString = root["effect"].as(); - 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(effectString == "E131"){ - if(strip.isRunning()) strip.stop(); + if(strip->isRunning()) strip->stop(); mode = E131; break; } #endif - if(String(strip.getModeName(i)) == effectString) { + if(String(strip->getModeName(i)) == effectString) { mode = SET_MODE; ws2812fx_mode = i; break; @@ -1007,7 +1007,7 @@ void checkForRequests() { ha_send_data.detach(); mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub); #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(); json["name"] = HOSTNAME; #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT @@ -1024,8 +1024,8 @@ void checkForRequests() { json["color_temp"] = "true"; json["effect"] = "true"; JsonArray effect_list = json.createNestedArray("effect_list"); - for (uint8_t i = 0; i < strip.getModeCount(); i++) { - effect_list.add(strip.getModeName(i)); + for (uint8_t i = 0; i < strip->getModeCount(); i++) { + effect_list.add(strip->getModeName(i)); } #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) effect_list.add("E131"); @@ -1094,7 +1094,7 @@ void checkForRequests() { 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); #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(); json["name"] = HOSTNAME; #ifdef MQTT_HOME_ASSISTANT_0_84_SUPPORT @@ -1111,8 +1111,8 @@ void checkForRequests() { json["color_temp"] = "true"; json["effect"] = "true"; JsonArray effect_list = json.createNestedArray("effect_list"); - for (uint8_t i = 0; i < strip.getModeCount(); i++) { - effect_list.add(strip.getModeName(i)); + for (uint8_t i = 0; i < strip->getModeCount(); i++) { + effect_list.add(strip->getModeName(i)); } #if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT) effect_list.add("E131"); @@ -1343,7 +1343,7 @@ bool writeStateFS(){ DynamicJsonDocument jsonBuffer; JsonObject json = jsonBuffer.to(); json["mode"] = static_cast(mode); - json["strip_mode"] = (int) strip.getMode(); + json["strip_mode"] = (int) strip->getMode(); json["brightness"] = brightness; json["speed"] = ws2812fx_speed; json["red"] = main_color.red; @@ -1395,14 +1395,14 @@ bool readStateFS() { main_color.green = json["green"]; main_color.blue = json["blue"]; - strip.setMode(ws2812fx_mode); - strip.setSpeed(convertSpeed(ws2812fx_speed)); - strip.setBrightness(brightness); - strip.setColor(main_color.red, main_color.green, main_color.blue); + strip->setMode(ws2812fx_mode); + strip->setSpeed(convertSpeed(ws2812fx_speed)); + strip->setBrightness(brightness); + strip->setColor(main_color.red, main_color.green, main_color.blue); #ifdef ENABLE_E131 if (mode == E131) { - strip.stop(); + strip->stop(); } #endif diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index fff3085..c2ec5d5 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -65,5 +65,7 @@ * - 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) * - 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 */ diff --git a/README.md b/README.md index b56180f..c25f95a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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.