Bugfix saving PWM & button pins.

pull/2737/head
Blaz Kristan 2021-05-22 00:13:49 +02:00
rodzic 1952505e52
commit cc0f1be5d2
5 zmienionych plików z 19 dodań i 55 usunięć

Wyświetl plik

@ -64,7 +64,7 @@
void WS2812FX::finalizeInit(void)
{
RESET_RUNTIME;
isRgbw = false;
isRgbw = isOffRefreshRequred = false;
//if busses failed to load, add default (fresh install, FS issue, ...)
if (busses.getNumBusses() == 0) {
@ -90,7 +90,10 @@ void WS2812FX::finalizeInit(void)
Bus *bus = busses.getBus(i);
if (bus == nullptr) continue;
if (_length+bus->getLength() > MAX_LEDS) break;
//RGBW mode is enabled if at least one of the strips is RGBW
isRgbw |= bus->isRgbw();
//refresh is required to remain off if at least one of the strips requires the refresh.
isOffRefreshRequred |= BusManager::isOffRefreshRequred(bus->getType());
_length += bus->getLength();
}
ledCount = _length; // or we can use busses.getTotalLength()

Wyświetl plik

@ -30,7 +30,7 @@ struct BusConfig {
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip;
uint8_t nPins = 1;
if (type > 47) nPins = 2;
else if (type > 41 && type < 46) nPins = NUM_PWM_PINS(type);
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
}
};
@ -222,14 +222,10 @@ class BusDigital : public Bus {
class BusPwm : public Bus {
public:
BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) {
_valid = false;
if (!IS_PWM(bc.type)) return;
uint8_t numPins = NUM_PWM_PINS(bc.type);
#ifdef WLED_DEBUG
Serial.print(F("Init: Number of pins="));
Serial.println(numPins);
#endif
#ifdef ESP8266
analogWriteRange(255); //same range as one RGB channel
analogWriteFreq(WLED_PWM_FREQ);
@ -243,8 +239,7 @@ class BusPwm : public Bus {
for (uint8_t i = 0; i < numPins; i++) {
_pins[i] = bc.pins[i];
if (!pinManager.allocatePin(_pins[i])) {
//deallocatePins(); return;
_pins[i] = 255; break;
_pins[i] = 255; return;
}
#ifdef ESP8266
pinMode(_pins[i], OUTPUT);
@ -280,10 +275,12 @@ class BusPwm : public Bus {
//does no index check
uint32_t getPixelColor(uint16_t pix) {
if (!_valid) return 0;
return ((_data[3] << 24) | (_data[0] << 16) | (_data[1] << 8) | (_data[2]));
}
void show() {
if (!_valid) return;
uint8_t numPins = NUM_PWM_PINS(_type);
for (uint8_t i = 0; i < numPins; i++) {
uint8_t scaled = (_data[i] * _bri) / 255;

Wyświetl plik

@ -69,8 +69,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
noWifiSleep = !noWifiSleep;
//int wifi_phy = doc[F("wifi")][F("phy")]; //force phy mode n?
DEBUG_PRINTLN(F(" Done network."));
JsonObject hw = doc[F("hw")];
// initialize LED pins and lengths prior to other HW
@ -89,7 +87,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (fromFS || !ins.isNull()) {
uint8_t s = 0; // bus iterator
strip.isRgbw = false;
busses.removeAll();
uint32_t mem = 0;
for (JsonObject elm : ins) {
@ -112,24 +109,17 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
uint8_t skipFirst = elm[F("skip")];
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
bool reversed = elm["rev"];
//RGBW mode is enabled if at least one of the strips is RGBW
// if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary)
// strip.isRgbw |= (bool)elm[F("rgbw")];
strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(ledType));
//refresh is required to remain off if at least one of the strips requires the refresh.
strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(ledType);
//if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary)
s++;
lC += length;
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
mem += BusManager::memUsage(bc);
DEBUG_PRINT(F(" Adding bus no. "));
DEBUG_PRINTLN(busses.getNumBusses());
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
}
// finalization done in beginStrip()
//strip.finalizeInit();
}
if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup)
DEBUG_PRINTLN(F(" Done LEDs."));
// read multiple button configuration
JsonArray hw_btn_ins = hw[F("btn")][F("ins")];
@ -138,13 +128,11 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
for (JsonObject btn : hw_btn_ins) {
CJSON(buttonType[s], btn["type"]);
int8_t pin = btn[F("pin")][0] | -1;
if (pin > -1) {
if (pinManager.allocatePin(pin,false)) {
btnPin[s] = pin;
pinMode(btnPin[s], INPUT_PULLUP);
} else {
btnPin[s] = -1;
}
if (pin > -1 && pinManager.allocatePin(pin,false)) {
btnPin[s] = pin;
pinMode(btnPin[s], INPUT_PULLUP);
} else {
btnPin[s] = -1;
}
JsonArray hw_btn_ins_0_macros = btn[F("macros")];
CJSON(macroButton[s], hw_btn_ins_0_macros[0]);
@ -172,26 +160,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
}
}
CJSON(touchThreshold,hw[F("btn")][F("tt")]);
DEBUG_PRINTLN(F(" Done buttons."));
/*
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
CJSON(buttonType, hw_btn_ins_0["type"]);
int hw_btn_pin = hw_btn_ins_0[F("pin")][0] | -2; //-2 = not present in doc, keep current. -1 = disable
if (hw_btn_pin > -1) {
if (pinManager.allocatePin(hw_btn_pin,false)) {
btnPin = hw_btn_pin;
pinMode(btnPin, INPUT_PULLUP);
} else {
btnPin = -1;
}
}
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0[F("macros")];
CJSON(macroButton, hw_btn_ins_0_macros[0]);
CJSON(macroLongPress,hw_btn_ins_0_macros[1]);
CJSON(macroDoublePress, hw_btn_ins_0_macros[2]);
*/
#ifndef WLED_DISABLE_INFRARED
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
if (hw_ir_pin > -2) {
@ -217,7 +186,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (relay.containsKey("rev")) {
rlyMde = !relay["rev"];
}
DEBUG_PRINTLN(F(" Done HW."));
//int hw_status_pin = hw[F("status")]["pin"]; // -1
@ -570,7 +538,6 @@ void serializeConfig() {
// additional buttons
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) {
//if (btnPin[i]<0) continue;
hw_btn_ins_0 = hw_btn_ins.createNestedObject();
hw_btn_ins_0["type"] = buttonType[i];
hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");

Wyświetl plik

@ -85,7 +85,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (btnPin[s]>=0 && pinManager.isPinAllocated(btnPin[s]))
pinManager.deallocatePin(btnPin[s]);
strip.isRgbw = false;
uint8_t colorOrder, type, skip;
uint16_t length, start;
uint8_t pins[5] = {255, 255, 255, 255, 255};
@ -98,7 +97,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
char sl[4] = "SL"; sl[2] = 48+s; sl[3] = 0; //skip 1st LED
// char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override
//char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override
if (!request->hasArg(lp)) {
DEBUG_PRINTLN(F("No data.")); break;
}
@ -108,9 +107,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
pins[i] = (request->arg(lp).length() > 0) ? request->arg(lp).toInt() : 255;
}
type = request->arg(lt).toInt();
// if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary)
// strip.isRgbw = strip.isRgbw || request->hasArg(ew);
strip.isRgbw = strip.isRgbw || Bus::isRgbw(type);
//if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary)
skip = request->hasArg(sl) ? LED_SKIP_AMOUNT : 0;
colorOrder = request->arg(co).toInt();

Wyświetl plik

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2105211
#define VERSION 2105212
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG