First light from busmanager! (still not usable though)

This commit is contained in:
cschwinne 2021-01-16 00:50:43 +01:00
parent ef904e01ec
commit b934634159
6 changed files with 347 additions and 35 deletions

View File

@ -6,7 +6,7 @@
*/
#include "const.h"
#include "wled.h"
#include "pin_manager.h"
#include "bus_wrapper.h"
//parent class of BusDigital and BusPwm
@ -58,7 +58,7 @@ class Bus {
protected:
uint8_t _type = TYPE_NONE;
uint8_t _bri = 255;
uint16_t _start;
uint16_t _start = 0;
bool _valid = false;
};
@ -69,11 +69,15 @@ class BusDigital : public Bus {
if (!IS_DIGITAL(type) || !len) return;
_pins[0] = pins[0];
if (IS_2PIN(type)) _pins[1] = pins[1];
//TODO allocate pins with pin manager
_len = len;
_iType = PolyBus::getI(type, _pins, nr);
if (_iType == I_NONE) return;
_valid = true;
_busPtr = PolyBus::begin(_iType, _pins, _len);
_valid = (_busPtr != nullptr);
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);
};
//TODO clean up stuff (destructor)
void show() {
PolyBus::show(_busPtr, _iType);
@ -83,8 +87,13 @@ class BusDigital : public Bus {
return PolyBus::canShow(_busPtr, _iType);
}
void setBrightness(uint8_t b) {
PolyBus::setBrightness(_busPtr, _iType, b);
}
void setPixelColor(uint16_t pix, uint32_t c) {
//TODO color order
PolyBus::setPixelColor(_busPtr, _iType, pix, c);
}
uint32_t getPixelColor(uint16_t pix) {

View File

@ -1,7 +1,6 @@
#ifndef BusWrapper_h
#define BusWrapper_h
#include "wled.h"
#include "NeoPixelBrightnessBus.h"
//Hardware SPI Pins
@ -192,9 +191,83 @@
//handles pointer type conversion for all possible bus types
class PolyBus {
public:
static void* begin(uint8_t busType, uint8_t* pins, uint16_t len) {
void* busPtr;
//delete busPtr; //TODO this needs type handling or destructor isn't called
switch (busType) {
case I_NONE: busPtr = new B_8266_U0_NEO_3(len, pins[0]); break;
#ifdef ESP8266
case I_8266_U0_NEO_3: busPtr = new B_8266_U0_NEO_3(len, pins[0]); (static_cast<B_8266_U0_NEO_3*>(busPtr))->Begin(); break;
case I_8266_U1_NEO_3: busPtr = new B_8266_U1_NEO_3(len, pins[0]); (static_cast<B_8266_U1_NEO_3*>(busPtr))->Begin(); break;
case I_8266_DM_NEO_3: busPtr = new B_8266_DM_NEO_3(len, pins[0]); (static_cast<B_8266_DM_NEO_3*>(busPtr))->Begin(); break;
case I_8266_BB_NEO_3: busPtr = new B_8266_BB_NEO_3(len, pins[0]); (static_cast<B_8266_BB_NEO_3*>(busPtr))->Begin(); break;
case I_8266_U0_NEO_4: busPtr = new B_8266_U0_NEO_4(len, pins[0]); (static_cast<B_8266_U0_NEO_4*>(busPtr))->Begin(); break;
case I_8266_U1_NEO_4: busPtr = new B_8266_U1_NEO_4(len, pins[0]); (static_cast<B_8266_U1_NEO_4*>(busPtr))->Begin(); break;
case I_8266_DM_NEO_4: busPtr = new B_8266_DM_NEO_4(len, pins[0]); (static_cast<B_8266_DM_NEO_4*>(busPtr))->Begin(); break;
case I_8266_BB_NEO_4: busPtr = new B_8266_BB_NEO_4(len, pins[0]); (static_cast<B_8266_BB_NEO_4*>(busPtr))->Begin(); break;
case I_8266_U0_400_3: busPtr = new B_8266_U0_400_3(len, pins[0]); (static_cast<B_8266_U0_400_3*>(busPtr))->Begin(); break;
case I_8266_U1_400_3: busPtr = new B_8266_U1_400_3(len, pins[0]); (static_cast<B_8266_U1_400_3*>(busPtr))->Begin(); break;
case I_8266_DM_400_3: busPtr = new B_8266_DM_400_3(len, pins[0]); (static_cast<B_8266_DM_400_3*>(busPtr))->Begin(); break;
case I_8266_BB_400_3: busPtr = new B_8266_BB_400_3(len, pins[0]); (static_cast<B_8266_BB_400_3*>(busPtr))->Begin(); break;
case I_8266_U0_TM1_4: busPtr = new B_8266_U0_TM1_4(len, pins[0]); (static_cast<B_8266_U0_TM1_4*>(busPtr))->Begin(); break;
case I_8266_U1_TM1_4: busPtr = new B_8266_U1_TM1_4(len, pins[0]); (static_cast<B_8266_U1_TM1_4*>(busPtr))->Begin(); break;
case I_8266_DM_TM1_4: busPtr = new B_8266_DM_TM1_4(len, pins[0]); (static_cast<B_8266_DM_TM1_4*>(busPtr))->Begin(); break;
case I_8266_BB_TM1_4: busPtr = new B_8266_BB_TM1_4(len, pins[0]); (static_cast<B_8266_BB_TM1_4*>(busPtr))->Begin(); break;
#endif
#ifdef ARDUINO_ARCH_ESP32
case I_32_R0_NEO_3: busPtr = new B_32_R0_NEO_3(len, pins[0]); (static_cast<B_32_R0_NEO_3*>(busPtr))->Begin(); break;
case I_32_R1_NEO_3: busPtr = new B_32_R1_NEO_3(len, pins[0]); (static_cast<B_32_R1_NEO_3*>(busPtr))->Begin(); break;
case I_32_R2_NEO_3: busPtr = new B_32_R2_NEO_3(len, pins[0]); (static_cast<B_32_R2_NEO_3*>(busPtr))->Begin(); break;
case I_32_R3_NEO_3: busPtr = new B_32_R3_NEO_3(len, pins[0]); (static_cast<B_32_R3_NEO_3*>(busPtr))->Begin(); break;
case I_32_R4_NEO_3: busPtr = new B_32_R4_NEO_3(len, pins[0]); (static_cast<B_32_R4_NEO_3*>(busPtr))->Begin(); break;
case I_32_R5_NEO_3: busPtr = new B_32_R5_NEO_3(len, pins[0]); (static_cast<B_32_R5_NEO_3*>(busPtr))->Begin(); break;
case I_32_R6_NEO_3: busPtr = new B_32_R6_NEO_3(len, pins[0]); (static_cast<B_32_R6_NEO_3*>(busPtr))->Begin(); break;
case I_32_R7_NEO_3: busPtr = new B_32_R7_NEO_3(len, pins[0]); (static_cast<B_32_R7_NEO_3*>(busPtr))->Begin(); break;
case I_32_I0_NEO_3: busPtr = new B_32_I0_NEO_3(len, pins[0]); (static_cast<B_32_I0_NEO_3*>(busPtr))->Begin(); break;
case I_32_I1_NEO_3: busPtr = new B_32_I1_NEO_3(len, pins[0]); (static_cast<B_32_I1_NEO_3*>(busPtr))->Begin(); break;
case I_32_R0_NEO_4: busPtr = new B_32_R0_NEO_4(len, pins[0]); (static_cast<B_32_R0_NEO_4*>(busPtr))->Begin(); break;
case I_32_R1_NEO_4: busPtr = new B_32_R1_NEO_4(len, pins[0]); (static_cast<B_32_R1_NEO_4*>(busPtr))->Begin(); break;
case I_32_R2_NEO_4: busPtr = new B_32_R2_NEO_4(len, pins[0]); (static_cast<B_32_R2_NEO_4*>(busPtr))->Begin(); break;
case I_32_R3_NEO_4: busPtr = new B_32_R3_NEO_4(len, pins[0]); (static_cast<B_32_R3_NEO_4*>(busPtr))->Begin(); break;
case I_32_R4_NEO_4: busPtr = new B_32_R4_NEO_4(len, pins[0]); (static_cast<B_32_R4_NEO_4*>(busPtr))->Begin(); break;
case I_32_R5_NEO_4: busPtr = new B_32_R5_NEO_4(len, pins[0]); (static_cast<B_32_R5_NEO_4*>(busPtr))->Begin(); break;
case I_32_R6_NEO_4: busPtr = new B_32_R6_NEO_4(len, pins[0]); (static_cast<B_32_R6_NEO_4*>(busPtr))->Begin(); break;
case I_32_R7_NEO_4: busPtr = new B_32_R7_NEO_4(len, pins[0]); (static_cast<B_32_R7_NEO_4*>(busPtr))->Begin(); break;
case I_32_I0_NEO_4: busPtr = new B_32_I0_NEO_4(len, pins[0]); (static_cast<B_32_I0_NEO_4*>(busPtr))->Begin(); break;
case I_32_I1_NEO_4: busPtr = new B_32_I1_NEO_4(len, pins[0]); (static_cast<B_32_I1_NEO_4*>(busPtr))->Begin(); break;
case I_32_R0_400_3: busPtr = new B_32_R0_400_3(len, pins[0]); (static_cast<B_32_R0_400_3*>(busPtr))->Begin(); break;
case I_32_R1_400_3: busPtr = new B_32_R1_400_3(len, pins[0]); (static_cast<B_32_R1_400_3*>(busPtr))->Begin(); break;
case I_32_R2_400_3: busPtr = new B_32_R2_400_3(len, pins[0]); (static_cast<B_32_R2_400_3*>(busPtr))->Begin(); break;
case I_32_R3_400_3: busPtr = new B_32_R3_400_3(len, pins[0]); (static_cast<B_32_R3_400_3*>(busPtr))->Begin(); break;
case I_32_R4_400_3: busPtr = new B_32_R4_400_3(len, pins[0]); (static_cast<B_32_R4_400_3*>(busPtr))->Begin(); break;
case I_32_R5_400_3: busPtr = new B_32_R5_400_3(len, pins[0]); (static_cast<B_32_R5_400_3*>(busPtr))->Begin(); break;
case I_32_R6_400_3: busPtr = new B_32_R6_400_3(len, pins[0]); (static_cast<B_32_R6_400_3*>(busPtr))->Begin(); break;
case I_32_R7_400_3: busPtr = new B_32_R7_400_3(len, pins[0]); (static_cast<B_32_R7_400_3*>(busPtr))->Begin(); break;
case I_32_I0_400_3: busPtr = new B_32_I0_400_3(len, pins[0]); (static_cast<B_32_I0_400_3*>(busPtr))->Begin(); break;
case I_32_I1_400_3: busPtr = new B_32_I1_400_3(len, pins[0]); (static_cast<B_32_I1_400_3*>(busPtr))->Begin(); break;
case I_32_R0_TM1_4: busPtr = new B_32_R0_TM1_4(len, pins[0]); (static_cast<B_32_R0_TM1_4*>(busPtr))->Begin(); break;
case I_32_R1_TM1_4: busPtr = new B_32_R1_TM1_4(len, pins[0]); (static_cast<B_32_R1_TM1_4*>(busPtr))->Begin(); break;
case I_32_R2_TM1_4: busPtr = new B_32_R2_TM1_4(len, pins[0]); (static_cast<B_32_R2_TM1_4*>(busPtr))->Begin(); break;
case I_32_R3_TM1_4: busPtr = new B_32_R3_TM1_4(len, pins[0]); (static_cast<B_32_R3_TM1_4*>(busPtr))->Begin(); break;
case I_32_R4_TM1_4: busPtr = new B_32_R4_TM1_4(len, pins[0]); (static_cast<B_32_R4_TM1_4*>(busPtr))->Begin(); break;
case I_32_R5_TM1_4: busPtr = new B_32_R5_TM1_4(len, pins[0]); (static_cast<B_32_R5_TM1_4*>(busPtr))->Begin(); break;
case I_32_R6_TM1_4: busPtr = new B_32_R6_TM1_4(len, pins[0]); (static_cast<B_32_R6_TM1_4*>(busPtr))->Begin(); break;
case I_32_R7_TM1_4: busPtr = new B_32_R7_TM1_4(len, pins[0]); (static_cast<B_32_R7_TM1_4*>(busPtr))->Begin(); break;
case I_32_I0_TM1_4: busPtr = new B_32_I0_TM1_4(len, pins[0]); (static_cast<B_32_I0_TM1_4*>(busPtr))->Begin(); break;
case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); (static_cast<B_32_I1_TM1_4*>(busPtr))->Begin(); break;
#endif
case I_HS_DOT_3: busPtr = new B_HS_DOT_3(len, pins[0], pins[1]); (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
case I_SS_DOT_3: busPtr = new B_SS_DOT_3(len, pins[0], pins[1]); (static_cast<B_SS_DOT_3*>(busPtr))->Begin(); break;
case I_HS_LPD_3: busPtr = new B_HS_LPD_3(len, pins[0], pins[1]); (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
case I_SS_LPD_3: busPtr = new B_SS_LPD_3(len, pins[0], pins[1]); (static_cast<B_SS_LPD_3*>(busPtr))->Begin(); break;
case I_HS_WS1_3: busPtr = new B_HS_WS1_3(len, pins[0], pins[1]); (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
case I_SS_WS1_3: busPtr = new B_SS_WS1_3(len, pins[0], pins[1]); (static_cast<B_SS_WS1_3*>(busPtr))->Begin(); break;
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[0], pins[1]); (static_cast<B_HS_P98_3*>(busPtr))->Begin(); break;
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[0], pins[1]); (static_cast<B_SS_P98_3*>(busPtr))->Begin(); break;
}
return busPtr;
};
static void show(void* busPtr, uint8_t busType) {
(static_cast<B_8266_U1_NEO_3*>(busPtr))->Show();
switch (busType) {
case I_NONE: break;
#ifdef ESP8266
@ -268,8 +341,232 @@ class PolyBus {
}
};
static bool canShow(void* busPtr, uint8_t busType) {
return (static_cast<B_8266_U1_NEO_3*>(busPtr))->CanShow();
switch (busType) {
case I_NONE: return true;
#ifdef ESP8266
case I_8266_U0_NEO_3: return (static_cast<B_8266_U0_NEO_3*>(busPtr))->CanShow(); break;
case I_8266_U1_NEO_3: return (static_cast<B_8266_U1_NEO_3*>(busPtr))->CanShow(); break;
case I_8266_DM_NEO_3: return (static_cast<B_8266_DM_NEO_3*>(busPtr))->CanShow(); break;
case I_8266_BB_NEO_3: return (static_cast<B_8266_BB_NEO_3*>(busPtr))->CanShow(); break;
case I_8266_U0_NEO_4: return (static_cast<B_8266_U0_NEO_4*>(busPtr))->CanShow(); break;
case I_8266_U1_NEO_4: return (static_cast<B_8266_U1_NEO_4*>(busPtr))->CanShow(); break;
case I_8266_DM_NEO_4: return (static_cast<B_8266_DM_NEO_4*>(busPtr))->CanShow(); break;
case I_8266_BB_NEO_4: return (static_cast<B_8266_BB_NEO_4*>(busPtr))->CanShow(); break;
case I_8266_U0_400_3: return (static_cast<B_8266_U0_400_3*>(busPtr))->CanShow(); break;
case I_8266_U1_400_3: return (static_cast<B_8266_U1_400_3*>(busPtr))->CanShow(); break;
case I_8266_DM_400_3: return (static_cast<B_8266_DM_400_3*>(busPtr))->CanShow(); break;
case I_8266_BB_400_3: return (static_cast<B_8266_BB_400_3*>(busPtr))->CanShow(); break;
case I_8266_U0_TM1_4: return (static_cast<B_8266_U0_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_U1_TM1_4: return (static_cast<B_8266_U1_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_DM_TM1_4: return (static_cast<B_8266_DM_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_BB_TM1_4: return (static_cast<B_8266_BB_TM1_4*>(busPtr))->CanShow(); break;
#endif
#ifdef ARDUINO_ARCH_ESP32
case I_32_R0_NEO_3: return (static_cast<B_32_R0_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R1_NEO_3: return (static_cast<B_32_R1_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R2_NEO_3: return (static_cast<B_32_R2_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R3_NEO_3: return (static_cast<B_32_R3_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R4_NEO_3: return (static_cast<B_32_R4_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R5_NEO_3: return (static_cast<B_32_R5_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R6_NEO_3: return (static_cast<B_32_R6_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R7_NEO_3: return (static_cast<B_32_R7_NEO_3*>(busPtr))->CanShow(); break;
case I_32_I0_NEO_3: return (static_cast<B_32_I0_NEO_3*>(busPtr))->CanShow(); break;
case I_32_I1_NEO_3: return (static_cast<B_32_I1_NEO_3*>(busPtr))->CanShow(); break;
case I_32_R0_NEO_4: return (static_cast<B_32_R0_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R1_NEO_4: return (static_cast<B_32_R1_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R2_NEO_4: return (static_cast<B_32_R2_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R3_NEO_4: return (static_cast<B_32_R3_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R4_NEO_4: return (static_cast<B_32_R4_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R5_NEO_4: return (static_cast<B_32_R5_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R6_NEO_4: return (static_cast<B_32_R6_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R7_NEO_4: return (static_cast<B_32_R7_NEO_4*>(busPtr))->CanShow(); break;
case I_32_I0_NEO_4: return (static_cast<B_32_I0_NEO_4*>(busPtr))->CanShow(); break;
case I_32_I1_NEO_4: return (static_cast<B_32_I1_NEO_4*>(busPtr))->CanShow(); break;
case I_32_R0_400_3: return (static_cast<B_32_R0_400_3*>(busPtr))->CanShow(); break;
case I_32_R1_400_3: return (static_cast<B_32_R1_400_3*>(busPtr))->CanShow(); break;
case I_32_R2_400_3: return (static_cast<B_32_R2_400_3*>(busPtr))->CanShow(); break;
case I_32_R3_400_3: return (static_cast<B_32_R3_400_3*>(busPtr))->CanShow(); break;
case I_32_R4_400_3: return (static_cast<B_32_R4_400_3*>(busPtr))->CanShow(); break;
case I_32_R5_400_3: return (static_cast<B_32_R5_400_3*>(busPtr))->CanShow(); break;
case I_32_R6_400_3: return (static_cast<B_32_R6_400_3*>(busPtr))->CanShow(); break;
case I_32_R7_400_3: return (static_cast<B_32_R7_400_3*>(busPtr))->CanShow(); break;
case I_32_I0_400_3: return (static_cast<B_32_I0_400_3*>(busPtr))->CanShow(); break;
case I_32_I1_400_3: return (static_cast<B_32_I1_400_3*>(busPtr))->CanShow(); break;
case I_32_R0_TM1_4: return (static_cast<B_32_R0_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R1_TM1_4: return (static_cast<B_32_R1_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R2_TM1_4: return (static_cast<B_32_R2_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R3_TM1_4: return (static_cast<B_32_R3_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R4_TM1_4: return (static_cast<B_32_R4_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R5_TM1_4: return (static_cast<B_32_R5_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R6_TM1_4: return (static_cast<B_32_R6_TM1_4*>(busPtr))->CanShow(); break;
case I_32_R7_TM1_4: return (static_cast<B_32_R7_TM1_4*>(busPtr))->CanShow(); break;
case I_32_I0_TM1_4: return (static_cast<B_32_I0_TM1_4*>(busPtr))->CanShow(); break;
case I_32_I1_TM1_4: return (static_cast<B_32_I1_TM1_4*>(busPtr))->CanShow(); break;
#endif
case I_HS_DOT_3: return (static_cast<B_HS_DOT_3*>(busPtr))->CanShow(); break;
case I_SS_DOT_3: return (static_cast<B_SS_DOT_3*>(busPtr))->CanShow(); break;
case I_HS_LPD_3: return (static_cast<B_HS_LPD_3*>(busPtr))->CanShow(); break;
case I_SS_LPD_3: return (static_cast<B_SS_LPD_3*>(busPtr))->CanShow(); break;
case I_HS_WS1_3: return (static_cast<B_HS_WS1_3*>(busPtr))->CanShow(); break;
case I_SS_WS1_3: return (static_cast<B_SS_WS1_3*>(busPtr))->CanShow(); break;
case I_HS_P98_3: return (static_cast<B_HS_P98_3*>(busPtr))->CanShow(); break;
case I_SS_P98_3: return (static_cast<B_SS_P98_3*>(busPtr))->CanShow(); break;
}
return true;
};
static void setPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint32_t c) {
uint8_t r = c >> 16;
uint8_t g = c >> 8;
uint8_t b = c >> 0;
uint8_t w = c >> 24;
switch (busType) {
case I_NONE: break;
#ifdef ESP8266
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
#endif
#ifdef ARDUINO_ARCH_ESP32
case I_32_R0_NEO_3: (static_cast<B_32_R0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R1_NEO_3: (static_cast<B_32_R1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R2_NEO_3: (static_cast<B_32_R2_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R3_NEO_3: (static_cast<B_32_R3_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R4_NEO_3: (static_cast<B_32_R4_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R5_NEO_3: (static_cast<B_32_R5_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R6_NEO_3: (static_cast<B_32_R6_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R7_NEO_3: (static_cast<B_32_R7_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R0_NEO_4: (static_cast<B_32_R0_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R1_NEO_4: (static_cast<B_32_R1_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R2_NEO_4: (static_cast<B_32_R2_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R3_NEO_4: (static_cast<B_32_R3_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R4_NEO_4: (static_cast<B_32_R4_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R5_NEO_4: (static_cast<B_32_R5_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R6_NEO_4: (static_cast<B_32_R6_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R7_NEO_4: (static_cast<B_32_R7_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R0_400_3: (static_cast<B_32_R0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R1_400_3: (static_cast<B_32_R1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R2_400_3: (static_cast<B_32_R2_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R3_400_3: (static_cast<B_32_R3_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R4_400_3: (static_cast<B_32_R4_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R5_400_3: (static_cast<B_32_R5_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R6_400_3: (static_cast<B_32_R6_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R7_400_3: (static_cast<B_32_R7_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_32_R0_TM1_4: (static_cast<B_32_R0_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R1_TM1_4: (static_cast<B_32_R1_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R2_TM1_4: (static_cast<B_32_R2_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R3_TM1_4: (static_cast<B_32_R3_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R4_TM1_4: (static_cast<B_32_R4_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R5_TM1_4: (static_cast<B_32_R5_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R6_TM1_4: (static_cast<B_32_R6_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_R7_TM1_4: (static_cast<B_32_R7_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetPixelColor(pix, RgbwColor(r,g,b,w)); break;
#endif
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(r,g,b)); break;
}
};
static void setBrightness(void* busPtr, uint8_t busType, uint8_t b) {
switch (busType) {
case I_NONE: break;
#ifdef ESP8266
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetBrightness(b); break;
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetBrightness(b); break;
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetBrightness(b); break;
#endif
#ifdef ARDUINO_ARCH_ESP32
case I_32_R0_NEO_3: (static_cast<B_32_R0_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R1_NEO_3: (static_cast<B_32_R1_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R2_NEO_3: (static_cast<B_32_R2_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R3_NEO_3: (static_cast<B_32_R3_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R4_NEO_3: (static_cast<B_32_R4_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R5_NEO_3: (static_cast<B_32_R5_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R6_NEO_3: (static_cast<B_32_R6_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R7_NEO_3: (static_cast<B_32_R7_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_R0_NEO_4: (static_cast<B_32_R0_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R1_NEO_4: (static_cast<B_32_R1_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R2_NEO_4: (static_cast<B_32_R2_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R3_NEO_4: (static_cast<B_32_R3_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R4_NEO_4: (static_cast<B_32_R4_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R5_NEO_4: (static_cast<B_32_R5_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R6_NEO_4: (static_cast<B_32_R6_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R7_NEO_4: (static_cast<B_32_R7_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_R0_400_3: (static_cast<B_32_R0_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R1_400_3: (static_cast<B_32_R1_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R2_400_3: (static_cast<B_32_R2_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R3_400_3: (static_cast<B_32_R3_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R4_400_3: (static_cast<B_32_R4_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R5_400_3: (static_cast<B_32_R5_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R6_400_3: (static_cast<B_32_R6_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R7_400_3: (static_cast<B_32_R7_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_R0_TM1_4: (static_cast<B_32_R0_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R1_TM1_4: (static_cast<B_32_R1_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R2_TM1_4: (static_cast<B_32_R2_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R3_TM1_4: (static_cast<B_32_R3_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R4_TM1_4: (static_cast<B_32_R4_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R5_TM1_4: (static_cast<B_32_R5_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R6_TM1_4: (static_cast<B_32_R6_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_R7_TM1_4: (static_cast<B_32_R7_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetBrightness(b); break;
#endif
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetBrightness(b); break;
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetBrightness(b); break;
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetBrightness(b); break;
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetBrightness(b); break;
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetBrightness(b); break;
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetBrightness(b); break;
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetBrightness(b); break;
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetBrightness(b); break;
}
};
static uint32_t getPixelColor() {
return 0; //TODO
}
//gives back the internal type index (I_XX_XXX_X above) for the input
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0) {
if (!IS_DIGITAL(busType)) return I_NONE;

View File

@ -149,27 +149,6 @@ void setCronixie();
void _overlayCronixie();
void _drawOverlayCronixie();
//pin_manager.cpp
class PinManagerClass {
private:
#ifdef ESP8266
uint8_t pinAlloc[3] = {0x00, 0x00, 0x00}; //24bit, 1 bit per pin, we use first 17bits
#else
uint8_t pinAlloc[5] = {0x00, 0x00, 0x00, 0x00, 0x00}; //40bit, 1 bit per pin, we use all bits
uint8_t ledcAlloc[2] = {0x00, 0x00}; //16 LEDC channels
#endif
public:
void deallocatePin(byte gpio);
bool allocatePin(byte gpio, bool output = true);
bool isPinAllocated(byte gpio);
bool isPinOk(byte gpio, bool output = true);
#ifdef ARDUINO_ARCH_ESP32
byte allocateLedc(byte channels);
void deallocateLedc(byte pos, byte channels);
#endif
};
//playlist.cpp
void loadPlaylist(JsonObject playlistObject);
void handlePlaylist();

View File

@ -1,9 +1,6 @@
#include "pin_manager.h"
#include "wled.h"
/*
* Registers pins so there is no attempt for two interfaces to use the same pin
*/
void PinManagerClass::deallocatePin(byte gpio)
{
if (!isPinOk(gpio, false)) return;
@ -89,4 +86,6 @@ void PinManagerClass::deallocateLedc(byte pos, byte channels)
bitWrite(ledcAlloc[by], bi, false);
}
}
#endif
#endif
PinManagerClass pinManager = PinManagerClass();

29
wled00/pin_manager.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef WLED_PIN_MANAGER_H
#define WLED_PIN_MANAGER_H
/*
* Registers pins so there is no attempt for two interfaces to use the same pin
*/
#include <Arduino.h>
class PinManagerClass {
private:
#ifdef ESP8266
uint8_t pinAlloc[3] = {0x00, 0x00, 0x00}; //24bit, 1 bit per pin, we use first 17bits
#else
uint8_t pinAlloc[5] = {0x00, 0x00, 0x00, 0x00, 0x00}; //40bit, 1 bit per pin, we use all bits
uint8_t ledcAlloc[2] = {0x00, 0x00}; //16 LEDC channels
#endif
public:
void deallocatePin(byte gpio);
bool allocatePin(byte gpio, bool output = true);
bool isPinAllocated(byte gpio);
bool isPinOk(byte gpio, bool output = true);
#ifdef ARDUINO_ARCH_ESP32
byte allocateLedc(byte channels);
void deallocateLedc(byte pos, byte channels);
#endif
};
extern PinManagerClass pinManager;
#endif

View File

@ -115,6 +115,7 @@
#include "FX.h"
#include "ir_codes.h"
#include "const.h"
#include "pin_manager.h"
#ifndef CLIENT_SSID
#define CLIENT_SSID DEFAULT_CLIENT_SSID
@ -531,8 +532,6 @@ WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
// Usermod manager
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
WLED_GLOBAL PinManagerClass pinManager _INIT(PinManagerClass());
// Status LED
#if STATUSLED && STATUSLED != LEDPIN
WLED_GLOBAL unsigned long ledStatusLastMillis _INIT(0);