From 67833c55132a2e0fe742c38880e6d960e5a12b13 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 19 Jan 2021 16:51:03 +0100 Subject: [PATCH] getPins() and reversed --- wled00/bus_manager.h | 31 ++++++++++++++++++++++++++----- wled00/bus_wrapper.h | 2 +- wled00/const.h | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index ca32b9a3..37c12805 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -33,6 +33,8 @@ class Bus { //Serial.println("Destructor!"); } + virtual uint8_t getPins(uint8_t* pinArray) { return 0; } + uint16_t getStart() { return _start; } @@ -59,6 +61,8 @@ class Bus { return _valid; } + bool reversed = false; + protected: uint8_t _type = TYPE_NONE; uint8_t _bri = 255; @@ -69,7 +73,7 @@ class Bus { class BusDigital : public Bus { public: - BusDigital(uint8_t type, uint8_t* pins, uint16_t start, uint16_t len, uint8_t colorOrder, uint8_t nr) : Bus(type, start) { + BusDigital(uint8_t type, uint8_t* pins, uint16_t start, uint16_t len, uint8_t colorOrder, uint8_t nr, bool rev) : Bus(type, start) { if (!IS_DIGITAL(type) || !len) return; _pins[0] = pins[0]; if (!pinManager.allocatePin(_pins[0])) return; @@ -80,6 +84,7 @@ class BusDigital : public Bus { } } _len = len; + reversed = rev; _iType = PolyBus::getI(type, _pins, nr); if (_iType == I_NONE) return; _busPtr = PolyBus::create(_iType, _pins, _len); @@ -97,19 +102,23 @@ class BusDigital : public Bus { } void setBrightness(uint8_t b) { - //Fix for turning off onboard LED breaking bus + //Fix for turning off onboard LED breaking bus and quick fix for DMA not initializing correctly #ifdef LED_BUILTIN - if (_bri == 0 && b > 0 && (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN)) PolyBus::begin(_busPtr, _iType); + if (_bri == 0 && b > 0) { + if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN || (_pins[0] == 3 && _iType < 17)) PolyBus::begin(_busPtr, _iType); + } #endif _bri = b; PolyBus::setBrightness(_busPtr, _iType, b); } void setPixelColor(uint16_t pix, uint32_t c) { + if (reversed) pix = _len - pix -1; PolyBus::setPixelColor(_busPtr, _iType, pix, c, _colorOrder); } uint32_t getPixelColor(uint16_t pix) { + if (reversed) pix = _len - pix -1; return PolyBus::getPixelColor(_busPtr, _iType, pix, _colorOrder); } @@ -121,6 +130,12 @@ class BusDigital : public Bus { return _len; } + uint8_t getPins(uint8_t* pinArray) { + uint8_t numPins = IS_2PIN(_type) ? 2 : 1; + for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i]; + return numPins; + } + void setColorOrder(uint8_t colorOrder) { if (colorOrder > 5) return; _colorOrder = colorOrder; @@ -222,6 +237,12 @@ class BusPwm : public Bus { _bri = b; } + uint8_t getPins(uint8_t* pinArray) { + uint8_t numPins = NUM_PWM_PINS(_type); + for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i]; + return numPins; + } + void cleanup() { deallocatePins(); } @@ -256,10 +277,10 @@ class BusManager { }; - int add(uint8_t busType, uint8_t* pins, uint16_t start, uint16_t len = 1, uint8_t colorOrder = COL_ORDER_GRB) { + int add(uint8_t busType, uint8_t* pins, uint16_t start, uint16_t len = 1, uint8_t colorOrder = COL_ORDER_GRB, bool rev = false) { if (numBusses >= WLED_MAX_BUSSES) return -1; if (IS_DIGITAL(busType)) { - busses[numBusses] = new BusDigital(busType, pins, start, len, colorOrder, numBusses); + busses[numBusses] = new BusDigital(busType, pins, start, len, colorOrder, numBusses, rev); } else { busses[numBusses] = new BusPwm(busType, pins, start); } diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index d9f0244f..18e29e0c 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -104,7 +104,7 @@ #define B_8266_U0_NEO_3 NeoPixelBrightnessBus //3 chan, esp8266, gpio1 #define B_8266_U1_NEO_3 NeoPixelBrightnessBus //3 chan, esp8266, gpio2 #define B_8266_DM_NEO_3 NeoPixelBrightnessBus //3 chan, esp8266, gpio3 -#define B_8266_BB_NEO_3 NeoPixelBrightnessBus //3 chan, esp8266, bb (any pin) +#define B_8266_BB_NEO_3 NeoPixelBrightnessBus //3 chan, esp8266, bb (any pin but 16) //RGBW #define B_8266_U0_NEO_4 NeoPixelBrightnessBus //4 chan, esp8266, gpio1 #define B_8266_U1_NEO_4 NeoPixelBrightnessBus //4 chan, esp8266, gpio2 diff --git a/wled00/const.h b/wled00/const.h index dabd0001..326d3e85 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -14,7 +14,7 @@ #define WLED_MAX_USERMODS 4 #ifdef ESP8266 -#define WLED_MAX_BUSSES 2 +#define WLED_MAX_BUSSES 3 #else #define WLED_MAX_BUSSES 7 #endif