Mulipin select compiles

Need to work on JS and set.cpp next
This commit is contained in:
cschwinne 2021-01-21 01:21:16 +01:00
parent 94471c0d1c
commit c105f3b970
13 changed files with 821 additions and 922 deletions

View File

@ -97,19 +97,14 @@ class UsermodTemperature : public Usermod {
} }
void loop() { void loop() {
if (disabled || strip.isUpdating()) { if (disabled || strip.isUpdating()) return;
return;
}
unsigned long now = millis(); unsigned long now = millis();
// check to see if we are due for taking a measurement // check to see if we are due for taking a measurement
// lastMeasurement will not be updated until the conversion // lastMeasurement will not be updated until the conversion
// is complete the the reading is finished // is complete the the reading is finished
if (now - lastMeasurement < USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL) if (now - lastMeasurement < USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL) return;
{
return;
}
// we are due for a measurement, if we are not already waiting // we are due for a measurement, if we are not already waiting
// for a conversion to complete, then make a new request for temps // for a conversion to complete, then make a new request for temps
@ -142,9 +137,7 @@ class UsermodTemperature : public Usermod {
void addToJsonInfo(JsonObject& root) { void addToJsonInfo(JsonObject& root) {
// dont add temperature to info if we are disabled // dont add temperature to info if we are disabled
if (disabled) { if (disabled) return;
return;
}
JsonObject user = root[F("u")]; JsonObject user = root[F("u")];
if (user.isNull()) user = root.createNestedObject(F("u")); if (user.isNull()) user = root.createNestedObject(F("u"));
@ -173,32 +166,6 @@ class UsermodTemperature : public Usermod {
#endif #endif
} }
/**
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
* Add "pin_Temperature" to json state. This can be used to check which GPIO pin usermod uses.
*/
void addToJsonState(JsonObject &root)
{
root[F("pin_Temperature")] = TEMPERATURE_PIN;
}
/**
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
* Read "pin_Temperature" from json state and and change GPIO pin used.
*/
void readFromJsonState(JsonObject &root)
{
/*
if (root[F("pin_Temperature")] != nullptr)
{
if (pinManager.allocatePin((int)root[F("pin_Temperature")],false))
temperaturePin = (int)root["PIRenabled"];
}
*/
}
uint16_t getId() uint16_t getId()
{ {
return USERMOD_ID_TEMPERATURE; return USERMOD_ID_TEMPERATURE;

View File

@ -29,12 +29,6 @@
#ifndef WS2812FX_h #ifndef WS2812FX_h
#define WS2812FX_h #define WS2812FX_h
#ifdef ESP32_MULTISTRIP
#include "../usermods/esp32_multistrip/NpbWrapper.h"
#else
#include "bus_manager.h"
#endif
#include "const.h" #include "const.h"
#define FASTLED_INTERNAL //remove annoying pragma messages #define FASTLED_INTERNAL //remove annoying pragma messages
@ -586,7 +580,6 @@ class WS2812FX {
ablMilliampsMax = 850; ablMilliampsMax = 850;
currentMilliamps = 0; currentMilliamps = 0;
timebase = 0; timebase = 0;
busses = new BusManager();
resetSegments(); resetSegments();
} }
@ -804,8 +797,6 @@ class WS2812FX {
mode_dynamic_smooth(void); mode_dynamic_smooth(void);
private: private:
BusManager *busses;
uint32_t crgb_to_col(CRGB fastled); uint32_t crgb_to_col(CRGB fastled);
CRGB col_to_crgb(uint32_t); CRGB col_to_crgb(uint32_t);
CRGBPalette16 currentPalette; CRGBPalette16 currentPalette;

View File

@ -62,11 +62,11 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
_lengthRaw += LED_SKIP_AMOUNT; _lengthRaw += LED_SKIP_AMOUNT;
} }
uint8_t pins[] = {LEDPIN}; uint8_t pins[] = {2};
while (!busses->canAllShow()) yield(); while (!busses.canAllShow()) yield();
busses->removeAll(); busses.removeAll();
busses->add(supportWhite? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, countPixels, COL_ORDER_GRB); busses.add(supportWhite? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, countPixels, COL_ORDER_GRB);
_segments[0].start = 0; _segments[0].start = 0;
_segments[0].stop = _length; _segments[0].stop = _length;
@ -74,8 +74,8 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
setBrightness(_brightness); setBrightness(_brightness);
#ifdef ESP8266 #ifdef ESP8266
for (uint8_t i = 0; i < busses->getNumBusses(); i++) { for (uint8_t i = 0; i < busses.getNumBusses(); i++) {
Bus* b = busses->getBus(i); Bus* b = busses.getBus(i);
if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue; if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue;
uint8_t pins[5]; uint8_t pins[5];
b->getPins(pins); b->getPins(pins);
@ -205,12 +205,12 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet];
#endif #endif
if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) { if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) {
busses->setPixelColor(indexSet + skip, col); busses.setPixelColor(indexSet + skip, col);
if (IS_MIRROR) { //set the corresponding mirrored pixel if (IS_MIRROR) { //set the corresponding mirrored pixel
if (reverseMode) { if (reverseMode) {
busses->setPixelColor(REV(SEGMENT.start) - indexSet + skip + REV(SEGMENT.stop) + 1, col); busses.setPixelColor(REV(SEGMENT.start) - indexSet + skip + REV(SEGMENT.stop) + 1, col);
} else { } else {
busses->setPixelColor(SEGMENT.stop - indexSet + skip + SEGMENT.start - 1, col); busses.setPixelColor(SEGMENT.stop - indexSet + skip + SEGMENT.start - 1, col);
} }
} }
} }
@ -221,11 +221,11 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
if (i < customMappingSize) i = customMappingTable[i]; if (i < customMappingSize) i = customMappingTable[i];
#endif #endif
uint32_t col = ((w << 24) | (r << 16) | (g << 8) | (b)); uint32_t col = ((w << 24) | (r << 16) | (g << 8) | (b));
busses->setPixelColor(i + skip, col); busses.setPixelColor(i + skip, col);
} }
if (skip && i == 0) { if (skip && i == 0) {
for (uint16_t j = 0; j < skip; j++) { for (uint16_t j = 0; j < skip; j++) {
busses->setPixelColor(j, BLACK); busses.setPixelColor(j, BLACK);
} }
} }
} }
@ -276,7 +276,7 @@ void WS2812FX::show(void) {
for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED
{ {
RgbwColor c = busses->getPixelColor(i); RgbwColor c = busses.getPixelColor(i);
if(useWackyWS2815PowerModel) if(useWackyWS2815PowerModel)
{ {
@ -305,24 +305,24 @@ void WS2812FX::show(void) {
uint16_t scaleI = scale * 255; uint16_t scaleI = scale * 255;
uint8_t scaleB = (scaleI > 255) ? 255 : scaleI; uint8_t scaleB = (scaleI > 255) ? 255 : scaleI;
uint8_t newBri = scale8(_brightness, scaleB); uint8_t newBri = scale8(_brightness, scaleB);
busses->setBrightness(newBri); busses.setBrightness(newBri);
currentMilliamps = (powerSum0 * newBri) / puPerMilliamp; currentMilliamps = (powerSum0 * newBri) / puPerMilliamp;
} else } else
{ {
currentMilliamps = powerSum / puPerMilliamp; currentMilliamps = powerSum / puPerMilliamp;
busses->setBrightness(_brightness); busses.setBrightness(_brightness);
} }
currentMilliamps += MA_FOR_ESP; //add power of ESP back to estimate currentMilliamps += MA_FOR_ESP; //add power of ESP back to estimate
currentMilliamps += _length; //add standby power back to estimate currentMilliamps += _length; //add standby power back to estimate
} else { } else {
currentMilliamps = 0; currentMilliamps = 0;
busses->setBrightness(_brightness); busses.setBrightness(_brightness);
} }
// some buses send asynchronously and this method will return before // some buses send asynchronously and this method will return before
// all of the data has been sent. // all of the data has been sent.
// See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods // See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods
busses->show(); busses.show();
_lastShow = millis(); _lastShow = millis();
} }
@ -331,7 +331,7 @@ void WS2812FX::show(void) {
* On some hardware (ESP32), strip updates are done asynchronously. * On some hardware (ESP32), strip updates are done asynchronously.
*/ */
bool WS2812FX::isUpdating() { bool WS2812FX::isUpdating() {
return !busses->canAllShow(); return !busses.canAllShow();
} }
/** /**
@ -492,7 +492,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
if (i >= _lengthRaw) return 0; if (i >= _lengthRaw) return 0;
return busses->getPixelColor(i); return busses.getPixelColor(i);
} }
WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) { WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) {

View File

@ -292,8 +292,11 @@ class BusManager {
return numBusses -1; return numBusses -1;
} }
//do not call this method from system context (network callback)
void removeAll() { void removeAll() {
//Serial.println("Removing all."); //Serial.println("Removing all.");
//prevents crashes due to deleting busses while in use.
while (!canAllShow()) yield();
for (uint8_t i = 0; i < numBusses; i++) delete busses[i]; for (uint8_t i = 0; i < numBusses; i++) delete busses[i];
numBusses = 0; numBusses = 0;
} }
@ -346,6 +349,12 @@ class BusManager {
return numBusses; return numBusses;
} }
static bool isRgbw(uint8_t type) {
if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true;
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true;
return false;
}
private: private:
uint8_t numBusses = 0; uint8_t numBusses = 0;
Bus* busses[WLED_MAX_BUSSES]; Bus* busses[WLED_MAX_BUSSES];

View File

@ -94,13 +94,9 @@ void handleIO()
{ {
if (!offMode) { if (!offMode) {
#ifdef ESP8266 #ifdef ESP8266
for (uint8_t s=0; s<strip.numStrips; s++) { //turn off built-in LED if strip is turned off
if (strip.getStripPin(s)==LED_BUILTIN) { pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
break;
}
}
#endif #endif
if (rlyPin>=0) { if (rlyPin>=0) {
pinMode(rlyPin, OUTPUT); pinMode(rlyPin, OUTPUT);

View File

@ -92,8 +92,9 @@ void deserializeConfig() {
// initialize LED pins and lengths prior to other HW // initialize LED pins and lengths prior to other HW
JsonObject hw_led = hw[F("led")]; JsonObject hw_led = hw[F("led")];
// CJSON(ledCount, hw_led[F("total")]); CJSON(ledCount, hw_led[F("total")]);
ledCount = 0; if (ledCount > MAX_LEDS) ledCount = MAX_LEDS;
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]); CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]); CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
CJSON(strip.reverseMode, hw_led[F("rev")]); CJSON(strip.reverseMode, hw_led[F("rev")]);
@ -104,32 +105,40 @@ void deserializeConfig() {
// some safety measures here? // some safety measures here?
} else { } else {
JsonArray elms = strVar.as<JsonArray>(); JsonArray elms = strVar.as<JsonArray>();
uint8_t s=0; uint8_t s = 0;
for ( JsonObject elm : elms ) { useRGBW = false;
if (s>=WLED_MAX_BUSSES) break; busses.removeAll();
int8_t pins[2] = {-1,-1}; for (JsonObject elm : elms) {
pins[0] = elm[F("pin")][0]; if (s >= WLED_MAX_BUSSES) break;
if (pins[0] >= 0 && pinManager.allocatePin(pins[0])) { uint8_t pins[5] = {255, 255, 255, 255, 255};
if (elm[F("pin")].size()==2) { JsonArray pinArr = elm[F("pin")];
pins[1] = elm[F("pin")][1]; if (pinArr.size() == 0) continue;
if (pins[1] >= 0) pins[0] = pinArr[0];
if (!pinManager.allocatePin(pins[1])) { uint8_t i = 0;
pinManager.deallocatePin(pins[0]); for (int p : pinArr) {
break; // pin not ok pins[i] = p;
} i++;
} if (i>4) break;
} else {
break; // pin not ok
} }
uint16_t length = elm[F("len")]);
if (length==0) break; uint16_t length = elm[F("len")];
if (length==0) continue;
uint8_t colorOrder = (int)elm[F("order")]; uint8_t colorOrder = (int)elm[F("order")];
uint8_t skipFirstLed = elm[F("skip")]; // 0 //only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
uint8_t ledType = elm[F("type")]; if (s==0) skipFirstLed = elm[F("skip")];
uint8_t useRGBW = ((ledType == TYPE_SK6812_RGBW) || ledType == TYPE_TM1814); uint16_t start = elm[F("start")] | 0;
ledCount += length; if (start >= ledCount) continue;
busses->add(ledType? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, ledCount, colorOrder); //limit length of strip if it would exceed total configured LEDs
if (start + length > ledCount) length = ledCount - start;
uint8_t ledType = elm[F("type")] | TYPE_WS2812_RGB;
bool reversed = elm[F("rev")];
//RGBW mode is enabled if at least one of the strips is RGBW
useRGBW = (useRGBW || BusManager::isRgbw(ledType));
busses.add(ledType, pins, start, ledCount, colorOrder, reversed);
} }
//if no bus inited successfully (empty cfg or invalid), init default
uint8_t defPin[] = {LEDPIN};
busses.add(TYPE_WS2812_RGB, defPin, 0, ledCount, COL_ORDER_GRB);
} }
if (ledCount > MAX_LEDS) ledCount = MAX_LEDS; if (ledCount > MAX_LEDS) ledCount = MAX_LEDS;
@ -446,21 +455,21 @@ void serializeConfig() {
JsonArray hw_led_ins = hw_led.createNestedArray("ins"); JsonArray hw_led_ins = hw_led.createNestedArray("ins");
uint16_t start = 0; uint16_t start = 0;
for (uint8_t s=0; s<busses->getNumBusses(); s++) { for (uint8_t s = 0; s < busses.getNumBusses(); s++) {
Bus *bus = busses->getBus(s); Bus *bus = busses.getBus(s);
if (!bus || bus->getLength()==0) break; if (!bus || bus->getLength()==0) break;
JsonObject hw_led_ins_0 = hw_led_ins.createNestedObject(); JsonObject ins = hw_led_ins.createNestedObject();
hw_led_ins_0[F("en")] = true; ins[F("en")] = true;
hw_led_ins_0[F("start")] = start; ins[F("start")] = bus->getStart();
start += bus->getLength(); ins[F("len")] = bus->getLength();
hw_led_ins_0[F("len")] = bus->getLength(); JsonArray ins_pin = ins.createNestedArray("pin");
JsonArray hw_led_ins_0_pin = hw_led_ins_0.createNestedArray("pin"); uint8_t pins[5];
hw_led_ins_0_pin.add(bus->getBusPins(s)[0]); uint8_t nPins = bus->getPins(pins);
if (bus->getBusPins(s)[1]>=0) hw_led_ins_0_pin.add(bus->getBusPins(s)[1]); for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
hw_led_ins_0[F("order")] = bus->getColorOrder(); ins[F("order")] = bus->getColorOrder();
hw_led_ins_0[F("rev")] = false; ins[F("rev")] = bus->reversed;
hw_led_ins_0[F("skip")] = skipFirstLed ? 1 : 0; ins[F("skip")] = (skipFirstLed && s == 0) ? 1 : 0;
hw_led_ins_0[F("type")] = bus->getType(); ins[F("type")] = bus->getType();
} }
JsonObject hw_btn = hw.createNestedObject("btn"); JsonObject hw_btn = hw.createNestedObject("btn");

View File

@ -205,4 +205,9 @@
#define JSON_BUFFER_SIZE 16384 #define JSON_BUFFER_SIZE 16384
#endif #endif
//this is merely a default now and can be changed at runtime
#ifndef LEDPIN
#define LEDPIN 2
#endif
#endif #endif

View File

@ -46,10 +46,11 @@
} }
function UI() function UI()
{ {
var isRGBW = false; //TODO check all strips for rgbw (old d.getElementById('rgbw').checked)
var myC = d.querySelectorAll('.wc'), var myC = d.querySelectorAll('.wc'),
l = myC.length; l = myC.length;
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
myC[i].style.display = (d.getElementById('rgbw').checked) ? 'inline':'none'; myC[i].style.display = (isRGBW) ? 'inline':'none';
} }
d.getElementById('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none'; d.getElementById('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none';
@ -59,8 +60,8 @@
var s = d.getElementsByTagName("select"); var s = d.getElementsByTagName("select");
for (i=0; i<s.length; i++) { for (i=0; i<s.length; i++) {
if (s[i].name.substring(0,5)=="LTsel") { if (s[i].name.substring(0,2)=="LT") {
n=s[i].name.substring(5); n=s[i].name.substring(3);
d.getElementsByName("EW"+n)[0].checked = (parseInt(s[i].value)==30||parseInt(s[i].value)==54); // TYPE_xxxx values from const.h d.getElementsByName("EW"+n)[0].checked = (parseInt(s[i].value)==30||parseInt(s[i].value)==54); // TYPE_xxxx values from const.h
var LK = d.getElementsByName("LK"+n)[0]; var LK = d.getElementsByName("LK"+n)[0];
var o = d.getElementsByName("iLK"); var o = d.getElementsByName("iLK");
@ -127,7 +128,7 @@
var o = d.getElementsByName("iST"); var o = d.getElementsByName("iST");
var i = o.length; var i = o.length;
if ((n==1 && i>=d.maxST) || (n==-1 && i<=1)) return; if ((n==1 && i>=d.maxST) || (n==-1 && i==0)) return;
var f = d.getElementById("mLC"); var f = d.getElementById("mLC");
if (n==1) { if (n==1) {
@ -137,7 +138,7 @@
t.appendChild(d.createTextNode((i+1)+": ")); t.appendChild(d.createTextNode((i+1)+": "));
s = d.createElement("select"); s = d.createElement("select");
s.setAttribute("name","LTsel"+i); s.setAttribute("name","LT"+i);
s.onchange = function(){UI()} s.onchange = function(){UI()}
o = d.createElement("option"); o.text = "WS281x"; o.value = "22"; s.add(o); o = d.createElement("option"); o.text = "WS281x"; o.value = "22"; s.add(o);
o = d.createElement("option"); o.text = "SK6812"; o.value = "30"; s.add(o); o = d.createElement("option"); o.text = "SK6812"; o.value = "30"; s.add(o);
@ -177,7 +178,7 @@
b.appendChild(d.createTextNode(" clk:")); b.appendChild(d.createTextNode(" clk:"));
e = d.createElement("input"); e = d.createElement("input");
e.type = "number"; e.value = ""; e.name = "LK"+i; e.min=0; e.max=40; e.onchange=function(){UI()}; e.type = "number"; e.value = ""; e.name = "LK"+i; e.min=0; e.max=40; e.onchange=function(){UI()};
if (d.getElementsByName("LTsel")[0].value>49) e.required = true; //if (d.getElementsByName("LT"+i)[0].value>49) e.required = true;
b.appendChild(e); b.appendChild(e);
t.appendChild(b); t.appendChild(b);
@ -214,34 +215,12 @@
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
<h2>LED &amp; HW setup</h2> <h2>LED &amp; HW setup</h2>
Total LED count: <input name="LC" type="number" min="1" max="1500" oninput="UI()" required><br>
LED strips LED strips
<button type="button" id="+" onclick="addLEDs(1)" style="display:none;">+</button><button type="button" id="-" onclick="addLEDs(-1)" style="display:none;">-</button><br> <button type="button" id="+" onclick="addLEDs(1)" style="display:none;">+</button><button type="button" id="-" onclick="addLEDs(-1)" style="display:none;"> - </button><br>
<div id="mLC"> <div id="mLC">
<div name="iST"> Loading...
1:
<select name="LTsel" onchange="UI()">
<option value="22">WS281x</option><!--TYPE_WS2812_RGB-->
<option value="30">SK6812</option><!--TYPE_WS2812_RGB-->
<option value="50">WS2801</option><!--TYPE_WS2801-->
<option value="51">APA102</option><!--TYPE_APA102-->
<option value="52">LPD8806</option><!--TYPE_LPD8806-->
<option value="53">P9813</option><!--TYPE_P9813-->
<option value="54">TM1814</option><!--TYPE_TM1814-->
</select>
CO:
<select name="CO">
<option value=0>GRB</option>
<option value=1>RGB</option>
<option value=2>BRG</option>
<option value=3>RBG</option>
<option value=4>BGR</option>
<option value=5>GBR</option>
</select>
RGBW: <input type="checkbox" name="EW" onchange=UI() id="rgbw"><br>
pin:<input name="LP" type="number" min="0" max="40" required onchange="UI()">
<div name="iLK" style="display:inline;">clk:<input name="LK" type="number" min="0" max="40" onchange="UI()"></div>
count:<input name="LC" type="number" min="1" max="1500" oninput="UI()" required>
</div>
</div><hr> </div><hr>
Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"> Active high? <input type="checkbox" name="RM"><br> Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"> Active high? <input type="checkbox" name="RM"><br>
Button pin: <input type="number" min="-1" max="40" name="BT" onchange="UI()"><br> Button pin: <input type="number" min="-1" max="40" name="BT" onchange="UI()"><br>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -75,85 +75,50 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//LED SETTINGS //LED SETTINGS
if (subPage == 2) if (subPage == 2)
{ {
String LC=F("LC"), LP=F("LP"), LK=F("LK"), CO=F("CO"), LTsel=F("LTsel"); int t = 0;
int8_t pin;
int t;
// deallocate all pins
for (uint8_t s=0; s<busses->getNumBuses(); s++) {
Bus *bus = busses->getBus(s);
pinManager.deallocatePin(bus->getPins()[0]);
pinManager.deallocatePin(bus->getPins()[1]);
}
if (rlyPin>=0 && pinManager.isPinAllocated(rlyPin)) pinManager.deallocatePin(rlyPin); if (rlyPin>=0 && pinManager.isPinAllocated(rlyPin)) pinManager.deallocatePin(rlyPin);
#ifndef WLED_DISABLE_INFRARED #ifndef WLED_DISABLE_INFRARED
if (irPin>=0 && pinManager.isPinAllocated(irPin)) pinManager.deallocatePin(irPin); if (irPin>=0 && pinManager.isPinAllocated(irPin)) pinManager.deallocatePin(irPin);
#endif #endif
if (btnPin>=0 && pinManager.isPinAllocated(btnPin)) pinManager.deallocatePin(btnPin); if (btnPin>=0 && pinManager.isPinAllocated(btnPin)) pinManager.deallocatePin(btnPin);
// remove all busses //TODO remove all busses, but not in this system call
busses->removeAll(); //busses->removeAll();
// initial bus
uint8_t colorOrder, type; uint8_t colorOrder, type;
uint8_t ledType = request->arg(LTsel).toInt();
uint16_t length; uint16_t length;
int8_t pins[2] = {-1,-1}; uint8_t pins[2] = {255, 255};
pins[0] = request->arg(LP).toInt();
if (pinManager.allocatePin(pins[0])) {
t = length = request->arg(LC).toInt();
if ( request->hasArg(LK.c_str()) ) {
pins[1] = (request->arg(LK)).length() > 0 ? request->arg(LK).toInt() : -1;
if (pinManager.allocatePin(pins[1])) {
} else {
// fallback
pins[1] = -1;
}
}
colorOrder = request->arg(CO).toInt();
type = request->arg(LTsel).toInt();
busses->add(type? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, length, colorOrder); for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
} else { char lp[4] = "LP"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9
// fallback char lk[4] = "LK"; lk[2] = 48+s; lk[3] = 0;
} char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0;
char co[4] = "CO"; co[2] = 48+s; co[3] = 0;
// secondary busses char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0;
for (uint8_t i=1; i<WLED_MAX_BUSSES; i++) { char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0;
if ( request->hasArg((LP+i).c_str()) ) { char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0;
pins[0] = request->arg((LP+i).c_str()).toInt(); if (!request->hasArg(lp)) {
if (pinManager.allocatePin(pins[0])) { DEBUG_PRINTLN("No data."); break;
if ( request->hasArg((LK+i).c_str()) ) {
pins[1] = (request->arg(LK+i)).length() > 0 ? request->arg((LK+i).c_str()).toInt() : -1;
if (pins[1]>=0) {
pinManager.allocatePin(pins[1]);
}
}
} else {
DEBUG_PRINTLN(F("Pin not ok."));
type = TYPE_NONE;
break; // pin not ok
}
type = request->arg((LTsel+i).c_str()).toInt();
} else {
DEBUG_PRINTLN("No data.");
type = TYPE_NONE;
break; // no parameter
} }
if ( request->hasArg((LC+i).c_str()) && request->arg((LC+i).c_str()).toInt() > 0 ) { pins[0] = request->arg(lp).toInt();
t += lenght = request->arg((LC+i).c_str()).toInt(); if ( request->hasArg(lk) ) {
pins[1] = (request->arg(lk).length() > 0) ? request->arg(lk).toInt() : 255;
}
type = request->arg(lt).toInt();
if (request->hasArg(lc) && request->arg(lc).toInt() > 0) {
length = request->arg(lc).toInt();
} else { } else {
type = TYPE_NONE; type = TYPE_NONE;
break; // no parameter break; // no parameter
} }
colorOrder = request->arg((CO+i).c_str()).toInt(); colorOrder = request->arg(co).toInt();
busses->add(type? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, length, colorOrder); //busses.add(type, pins, 0, length, colorOrder, request->hasArg(cv));
} }
// what to do with these? ledCount = request->arg(F("LC")).toInt();
if (t > 0 && t <= MAX_LEDS) ledCount = t; if (t > 0 && t <= MAX_LEDS) ledCount = t;
#ifdef ESP8266 //DMA method uses too much ram, TODO: limit!
if ( pinManager.isPinAllocated(3) && ledCount > MAX_LEDS_DMA) ledCount = MAX_LEDS_DMA; //DMA method uses too much ram
#endif
// upate other pins // upate other pins
#ifndef WLED_DISABLE_INFRARED #ifndef WLED_DISABLE_INFRARED

View File

@ -116,6 +116,7 @@
#include "ir_codes.h" #include "ir_codes.h"
#include "const.h" #include "const.h"
#include "pin_manager.h" #include "pin_manager.h"
#include "bus_manager.h"
#ifndef CLIENT_SSID #ifndef CLIENT_SSID
#define CLIENT_SSID DEFAULT_CLIENT_SSID #define CLIENT_SSID DEFAULT_CLIENT_SSID
@ -549,14 +550,13 @@ WLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet)));
WLED_GLOBAL bool e131NewData _INIT(false); WLED_GLOBAL bool e131NewData _INIT(false);
// led fx library object // led fx library object
WLED_GLOBAL BusManager busses _INIT(BusManager());
WLED_GLOBAL WS2812FX strip _INIT(WS2812FX()); WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
WLED_GLOBAL bool doInitStrip _INIT(false); WLED_GLOBAL bool doInitStrip _INIT(false);
// Usermod manager // Usermod manager
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager()); WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
WLED_GLOBAL PinManagerClass pinManager _INIT(PinManagerClass());
// Status LED // Status LED
#if STATUSLED #if STATUSLED
WLED_GLOBAL unsigned long ledStatusLastMillis _INIT(0); WLED_GLOBAL unsigned long ledStatusLastMillis _INIT(0);

View File

@ -256,7 +256,7 @@ void getSettingsJS(byte subPage, char* dest)
if (subPage == 2) { if (subPage == 2) {
char nS[3]; char nS[3];
// add usermod pins as d.um_p array // add usermod pins as d.um_p array (TODO: usermod config shouldn't use state. instead we should load "um" object from cfg.json)
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
JsonObject mods = doc.createNestedObject(F("mods")); JsonObject mods = doc.createNestedObject(F("mods"));
usermods.addToJsonState(mods); usermods.addToJsonState(mods);
@ -278,7 +278,6 @@ void getSettingsJS(byte subPage, char* dest)
oappend(SET_F(");")); oappend(SET_F(");"));
#endif #endif
Bus *bus = busses->getBus(0);
oappend(SET_F("d.Sf.LC.max=")); //TODO Formula for max LEDs on ESP8266 depending on types. 500 DMA or 1500 UART (about 4kB mem usage) oappend(SET_F("d.Sf.LC.max=")); //TODO Formula for max LEDs on ESP8266 depending on types. 500 DMA or 1500 UART (about 4kB mem usage)
#if defined(ESP8266) && LEDPIN == 3 #if defined(ESP8266) && LEDPIN == 3
oappendi(MAX_LEDS_DMA); oappendi(MAX_LEDS_DMA);
@ -288,34 +287,22 @@ void getSettingsJS(byte subPage, char* dest)
oappend(";"); oappend(";");
sappend('v',SET_F("LC"),ledCount); sappend('v',SET_F("LC"),ledCount);
//sappend('v',SET_F("LC"),ledCount);
sappend('v',SET_F("LP"),bus->getPins()[0]);
if (bus->getPins()[1]>=0) sappend('v',SET_F("LK"),bus->getPins()[1]);
sappend('v',SET_F("LC"),bus->getLength());
sappend('v',SET_F("LTsel"),bus->getType());
sappend('v',SET_F("CO"),bus->getColorOrder());
for (uint8_t s=1; s<busses->getNumBusses(); s++){ for (uint8_t s=0; s < busses.getNumBusses(); s++){
bus = busses->getBus(s); Bus* bus = busses.getBus(s);
String LP = F("LP"), LK = F("LK"), LC = F("LC"), CO = F("CO"), LTsel = F("LTsel"); char lp[4] = "LP"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9
LP += s; LK += s; LC += s; CO += s; LTsel += s; char lk[4] = "LK"; lk[2] = 48+s; lp[3] = 0;
char lc[4] = "LC"; lc[2] = 48+s; lp[3] = 0;
char co[4] = "CO"; co[2] = 48+s; lp[3] = 0;
char lt[4] = "LT"; lt[2] = 48+s; lp[3] = 0;
oappend(SET_F("addLEDs(1);")); oappend(SET_F("addLEDs(1);"));
sappend('v',LP.c_str(),bus->getPins()[0]); uint8_t pins[5];
if (bus->getPins()[1]>=0) sappend('v',LK.c_str(),bus->getPins()[1]); uint8_t nPins = bus->getPins(pins);
sappend('v',LC.c_str(),bus->getLength()); sappend('v', lp, pins[0]);
#ifdef ESP8266 if (pinManager.isPinOk(pins[1])) sappend('v', lk, pins[1]);
if (bus->getPins()[0]==3) { sappend('v', lc, bus->getLength());
oappend(SET_F("d.Sf.")); sappend('v',lt,bus->getType());
oappend(LC.c_str()); sappend('v',co,bus->getColorOrder());
oappend(SET_F(".max=500;"));
} else {
oappend(SET_F("d.Sf."));
oappend(LC.c_str());
oappend(SET_F(".max=1500;"));
}
#endif
sappend('v',LTsel.c_str(),bus->getType());
sappend('v',CO.c_str(),bus->getColorOrder());
} }
sappend('v',SET_F("MA"),strip.ablMilliampsMax); sappend('v',SET_F("MA"),strip.ablMilliampsMax);
sappend('v',SET_F("LA"),strip.milliampsPerLed); sappend('v',SET_F("LA"),strip.milliampsPerLed);
@ -329,7 +316,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("CA"),briS); sappend('v',SET_F("CA"),briS);
sappend('c',SET_F("EW"),useRGBW); sappend('c',SET_F("EW"),useRGBW);
sappend('i',SET_F("CO"),strip.getColorOrder()); //sappend('i',SET_F("CO"),strip.getColorOrder());
sappend('v',SET_F("AW"),strip.rgbwMode); sappend('v',SET_F("AW"),strip.rgbwMode);
sappend('c',SET_F("BO"),turnOnAtBoot); sappend('c',SET_F("BO"),turnOnAtBoot);