might work
This commit is contained in:
parent
e44173ff09
commit
9518c5f2e4
@ -584,7 +584,7 @@ class WS2812FX {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init(bool supportWhite, uint16_t countPixels, bool skipFirst),
|
finalizeInit(bool supportWhite, uint16_t countPixels, bool skipFirst),
|
||||||
service(void),
|
service(void),
|
||||||
blur(uint8_t),
|
blur(uint8_t),
|
||||||
fill(uint32_t),
|
fill(uint32_t),
|
||||||
|
@ -49,7 +49,7 @@ const uint16_t customMappingSize = sizeof(customMappingTable)/sizeof(uint16_t);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//do not call this method from system context (network callback)
|
//do not call this method from system context (network callback)
|
||||||
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
|
void WS2812FX::finalizeInit(bool supportWhite, uint16_t countPixels, bool skipFirst)
|
||||||
{
|
{
|
||||||
if (supportWhite == _useRgbw && countPixels == _length && _skipFirstMode == skipFirst) return;
|
if (supportWhite == _useRgbw && countPixels == _length && _skipFirstMode == skipFirst) return;
|
||||||
RESET_RUNTIME;
|
RESET_RUNTIME;
|
||||||
@ -62,11 +62,12 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
|
|||||||
_lengthRaw += LED_SKIP_AMOUNT;
|
_lengthRaw += LED_SKIP_AMOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t pins[] = {2};
|
//if busses failed to load (FS issue...)
|
||||||
|
if (busses.getNumBusses() == 0) {
|
||||||
while (!busses.canAllShow()) yield();
|
uint8_t defPin[] = {LEDPIN};
|
||||||
busses.removeAll();
|
BusConfig defCfg = BusConfig(TYPE_WS2812_RGB, defPin, 0, _lengthRaw, COL_ORDER_GRB);
|
||||||
busses.add(supportWhite? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, countPixels, COL_ORDER_GRB);
|
busses.add(defCfg);
|
||||||
|
}
|
||||||
|
|
||||||
_segments[0].start = 0;
|
_segments[0].start = 0;
|
||||||
_segments[0].stop = _length;
|
_segments[0].stop = _length;
|
||||||
|
@ -10,6 +10,23 @@
|
|||||||
#include "bus_wrapper.h"
|
#include "bus_wrapper.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
//temporary struct for passing bus configuration to bus
|
||||||
|
struct BusConfig {
|
||||||
|
uint8_t type = TYPE_WS2812_RGB;
|
||||||
|
uint16_t count = 1;
|
||||||
|
uint16_t start = 0;
|
||||||
|
uint8_t colorOrder = COL_ORDER_GRB;
|
||||||
|
bool reversed = false;
|
||||||
|
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
|
||||||
|
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false) {
|
||||||
|
type = busType; count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev;
|
||||||
|
uint8_t nPins = 1;
|
||||||
|
if (type > 47) nPins = 2;
|
||||||
|
else if (type > 41 && type < 46) nPins = NUM_PWM_PINS(type);
|
||||||
|
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//parent class of BusDigital and BusPwm
|
//parent class of BusDigital and BusPwm
|
||||||
class Bus {
|
class Bus {
|
||||||
public:
|
public:
|
||||||
@ -73,23 +90,23 @@ class Bus {
|
|||||||
|
|
||||||
class BusDigital : public Bus {
|
class BusDigital : public Bus {
|
||||||
public:
|
public:
|
||||||
BusDigital(uint8_t type, uint8_t* pins, uint16_t start, uint16_t len, uint8_t colorOrder, uint8_t nr, bool rev) : Bus(type, start) {
|
BusDigital(BusConfig &bc, uint8_t nr) : Bus(bc.type, bc.start) {
|
||||||
if (!IS_DIGITAL(type) || !len) return;
|
if (!IS_DIGITAL(bc.type) || !bc.count) return;
|
||||||
_pins[0] = pins[0];
|
_pins[0] = bc.pins[0];
|
||||||
if (!pinManager.allocatePin(_pins[0])) return;
|
if (!pinManager.allocatePin(_pins[0])) return;
|
||||||
if (IS_2PIN(type)) {
|
if (IS_2PIN(bc.type)) {
|
||||||
_pins[1] = pins[1];
|
_pins[1] = bc.pins[1];
|
||||||
if (!pinManager.allocatePin(_pins[1])) {
|
if (!pinManager.allocatePin(_pins[1])) {
|
||||||
cleanup(); return;
|
cleanup(); return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_len = len;
|
_len = bc.count;
|
||||||
reversed = rev;
|
reversed = bc.reversed;
|
||||||
_iType = PolyBus::getI(type, _pins, nr);
|
_iType = PolyBus::getI(bc.type, _pins, nr);
|
||||||
if (_iType == I_NONE) return;
|
if (_iType == I_NONE) return;
|
||||||
_busPtr = PolyBus::create(_iType, _pins, _len);
|
_busPtr = PolyBus::create(_iType, _pins, _len);
|
||||||
_valid = (_busPtr != nullptr);
|
_valid = (_busPtr != nullptr);
|
||||||
_colorOrder = colorOrder;
|
_colorOrder = bc.colorOrder;
|
||||||
//Serial.printf("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, len, type, pins[0],pins[1],_iType);
|
//Serial.printf("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, len, type, pins[0],pins[1],_iType);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -170,9 +187,9 @@ class BusDigital : public Bus {
|
|||||||
|
|
||||||
class BusPwm : public Bus {
|
class BusPwm : public Bus {
|
||||||
public:
|
public:
|
||||||
BusPwm(uint8_t type, uint8_t* pins, uint16_t start) : Bus(type, start) {
|
BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) {
|
||||||
if (!IS_PWM(type)) return;
|
if (!IS_PWM(bc.type)) return;
|
||||||
uint8_t numPins = NUM_PWM_PINS(type);
|
uint8_t numPins = NUM_PWM_PINS(bc.type);
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
analogWriteRange(255); //same range as one RGB channel
|
analogWriteRange(255); //same range as one RGB channel
|
||||||
@ -185,7 +202,7 @@ class BusPwm : public Bus {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (uint8_t i = 0; i < numPins; i++) {
|
for (uint8_t i = 0; i < numPins; i++) {
|
||||||
_pins[i] = pins[i];
|
_pins[i] = bc.pins[i];
|
||||||
if (!pinManager.allocatePin(_pins[i])) {
|
if (!pinManager.allocatePin(_pins[i])) {
|
||||||
deallocatePins(); return;
|
deallocatePins(); return;
|
||||||
}
|
}
|
||||||
@ -281,12 +298,12 @@ class BusManager {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int add(uint8_t busType, uint8_t* pins, uint16_t start, uint16_t len = 1, uint8_t colorOrder = COL_ORDER_GRB, bool rev = false) {
|
int add(BusConfig &bc) {
|
||||||
if (numBusses >= WLED_MAX_BUSSES) return -1;
|
if (numBusses >= WLED_MAX_BUSSES) return -1;
|
||||||
if (IS_DIGITAL(busType)) {
|
if (IS_DIGITAL(bc.type)) {
|
||||||
busses[numBusses] = new BusDigital(busType, pins, start, len, colorOrder, numBusses, rev);
|
busses[numBusses] = new BusDigital(bc, numBusses);
|
||||||
} else {
|
} else {
|
||||||
busses[numBusses] = new BusPwm(busType, pins, start);
|
busses[numBusses] = new BusPwm(bc);
|
||||||
}
|
}
|
||||||
numBusses++;
|
numBusses++;
|
||||||
return numBusses -1;
|
return numBusses -1;
|
||||||
|
@ -44,12 +44,14 @@ bool initBusInstances(JsonArray ins) {
|
|||||||
//RGBW mode is enabled if at least one of the strips is RGBW
|
//RGBW mode is enabled if at least one of the strips is RGBW
|
||||||
useRGBW = (useRGBW || BusManager::isRgbw(ledType));
|
useRGBW = (useRGBW || BusManager::isRgbw(ledType));
|
||||||
s++;
|
s++;
|
||||||
busses.add(ledType, pins, start, ledCount, colorOrder, reversed);
|
BusConfig bc = BusConfig(ledType, pins, start, ledCount, colorOrder, reversed);
|
||||||
|
busses.add(bc);
|
||||||
}
|
}
|
||||||
//if no bus inited successfully (empty cfg or invalid), init default
|
//if no bus inited successfully (empty cfg or invalid), init default
|
||||||
if (s==0) {
|
if (s==0) {
|
||||||
uint8_t defPin[] = {LEDPIN};
|
uint8_t defPin[] = {LEDPIN};
|
||||||
busses.add(TYPE_WS2812_RGB, defPin, 0, ledCount, COL_ORDER_GRB);
|
BusConfig defCfg = BusConfig(TYPE_WS2812_RGB, defPin, 0, ledCount, COL_ORDER_GRB);
|
||||||
|
busses.add(defCfg);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -72,8 +74,6 @@ void deserializeConfig() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//deserializeJson(doc, json);
|
|
||||||
|
|
||||||
//int rev_major = doc[F("rev")][0]; // 1
|
//int rev_major = doc[F("rev")][0]; // 1
|
||||||
//int rev_minor = doc[F("rev")][1]; // 0
|
//int rev_minor = doc[F("rev")][1]; // 0
|
||||||
|
|
||||||
|
@ -89,12 +89,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
uint16_t length, start;
|
uint16_t length, start;
|
||||||
uint8_t pins[2] = {255, 255};
|
uint8_t pins[2] = {255, 255};
|
||||||
|
|
||||||
if (ledDoc != nullptr) delete ledDoc;
|
|
||||||
ledDoc = new DynamicJsonDocument(1024);
|
|
||||||
|
|
||||||
if (ledDoc) {
|
|
||||||
JsonArray ledO = ledDoc->to<JsonArray>();
|
|
||||||
//[{"en":true,"start":0,"len":120,"pin":[2],"order":0,"rev":false,"skip":0,"type":22}]
|
|
||||||
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
|
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
|
||||||
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
||||||
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
|
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
|
||||||
@ -120,19 +114,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
colorOrder = request->arg(co).toInt();
|
colorOrder = request->arg(co).toInt();
|
||||||
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : 0;
|
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : 0;
|
||||||
|
|
||||||
JsonObject ins = ledO.createNestedObject();
|
if (busConfigs[s] != nullptr) delete busConfigs[s];
|
||||||
ins[F("en")] = true;
|
busConfigs[s] = new BusConfig(type, pins, start, length, colorOrder, request->hasArg(cv));
|
||||||
ins[F("start")] = start;
|
|
||||||
ins[F("len")] = length;
|
|
||||||
JsonArray ins_pin = ins.createNestedArray("pin");
|
|
||||||
uint8_t nPins = pins[1] < 100 ? 2 : 1; //TODO 3,4,5 pin types
|
|
||||||
for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
|
|
||||||
ins[F("order")] = colorOrder;
|
|
||||||
ins[F("rev")] = request->hasArg(cv);
|
|
||||||
ins[F("skip")] = (skipFirstLed && s == 0) ? 1 : 0;
|
|
||||||
ins[F("type")] = type;
|
|
||||||
//temporary: add this info to a JSON object and re-init the strips after network callback
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ledCount = request->arg(F("LC")).toInt();
|
ledCount = request->arg(F("LC")).toInt();
|
||||||
|
@ -195,9 +195,15 @@ void WLED::loop()
|
|||||||
handleHue();
|
handleHue();
|
||||||
handleBlynk();
|
handleBlynk();
|
||||||
|
|
||||||
if (ledDoc != nullptr) {
|
//LED settings have been saved, re-init busses
|
||||||
initBusInstances(ledDoc->as<JsonArray>());
|
if (busConfigs[0] != nullptr) {
|
||||||
delete ledDoc; ledDoc = nullptr;
|
busses.removeAll();
|
||||||
|
for (uint8_t i = 0; i < WLED_MAX_BUSSES; i++) {
|
||||||
|
if (busConfigs[i] == nullptr) break;
|
||||||
|
busses.add(*busConfigs[i]);
|
||||||
|
delete busConfigs[i]; busConfigs[i] = nullptr;
|
||||||
|
}
|
||||||
|
strip.finalizeInit(useRGBW, ledCount, skipFirstLed);
|
||||||
}
|
}
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
@ -356,7 +362,7 @@ void WLED::beginStrip()
|
|||||||
if (ledCount > MAX_LEDS || ledCount == 0)
|
if (ledCount > MAX_LEDS || ledCount == 0)
|
||||||
ledCount = 30;
|
ledCount = 30;
|
||||||
|
|
||||||
strip.init(useRGBW, ledCount, skipFirstLed);
|
strip.finalizeInit(useRGBW, ledCount, skipFirstLed);
|
||||||
strip.setBrightness(0);
|
strip.setBrightness(0);
|
||||||
strip.setShowCallback(handleOverlayDraw);
|
strip.setShowCallback(handleOverlayDraw);
|
||||||
|
|
||||||
|
@ -552,7 +552,7 @@ WLED_GLOBAL bool e131NewData _INIT(false);
|
|||||||
// led fx library object
|
// led fx library object
|
||||||
WLED_GLOBAL BusManager busses _INIT(BusManager());
|
WLED_GLOBAL BusManager busses _INIT(BusManager());
|
||||||
WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
|
WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
|
||||||
WLED_GLOBAL JsonDocument* ledDoc; //temporary, to remember values from network callback until after
|
WLED_GLOBAL BusConfig* busConfigs[WLED_MAX_BUSSES]; //temporary, to remember values from network callback until after
|
||||||
|
|
||||||
// Usermod manager
|
// Usermod manager
|
||||||
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
|
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
|
||||||
|
Loading…
Reference in New Issue
Block a user