Added bus cleanup
This commit is contained in:
parent
0d63dad8c2
commit
99dbd9e649
@ -12,8 +12,9 @@
|
||||
//parent class of BusDigital and BusPwm
|
||||
class Bus {
|
||||
public:
|
||||
Bus(uint8_t type) {
|
||||
Bus(uint8_t type, uint16_t start) {
|
||||
_type = type;
|
||||
_start = start;
|
||||
};
|
||||
|
||||
virtual void show() {}
|
||||
@ -25,8 +26,10 @@ class Bus {
|
||||
|
||||
virtual uint32_t getPixelColor(uint16_t pix) { return 0; };
|
||||
|
||||
virtual ~Bus() { //throw the bus under the bus
|
||||
virtual void cleanup() {};
|
||||
|
||||
virtual ~Bus() { //throw the bus under the bus
|
||||
cleanup();
|
||||
}
|
||||
|
||||
uint16_t getStart() {
|
||||
@ -37,16 +40,16 @@ class Bus {
|
||||
_start = start;
|
||||
}
|
||||
|
||||
virtual uint8_t getColorOrder() {
|
||||
return COL_ORDER_RGB;
|
||||
}
|
||||
|
||||
virtual uint16_t getLength() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual void setColorOrder() {}
|
||||
|
||||
virtual uint8_t getColorOrder() {
|
||||
return COL_ORDER_RGB;
|
||||
}
|
||||
|
||||
uint8_t getType() {
|
||||
return _type;
|
||||
}
|
||||
@ -65,19 +68,24 @@ class Bus {
|
||||
|
||||
class BusDigital : public Bus {
|
||||
public:
|
||||
BusDigital(uint8_t type, uint8_t* pins, uint16_t len, uint8_t nr) : Bus(type) {
|
||||
BusDigital(uint8_t type, uint8_t* pins, uint16_t start, uint16_t len, uint8_t colorOrder, uint8_t nr) : Bus(type, start) {
|
||||
if (!IS_DIGITAL(type) || !len) return;
|
||||
_pins[0] = pins[0];
|
||||
if (IS_2PIN(type)) _pins[1] = pins[1];
|
||||
//TODO allocate pins with pin manager
|
||||
if (!pinManager.allocatePin(_pins[0])) return;
|
||||
if (IS_2PIN(type)) {
|
||||
_pins[1] = pins[1];
|
||||
if (!pinManager.allocatePin(_pins[1])) {
|
||||
cleanup(); return;
|
||||
}
|
||||
}
|
||||
_len = len;
|
||||
_iType = PolyBus::getI(type, _pins, nr);
|
||||
if (_iType == I_NONE) return;
|
||||
_busPtr = PolyBus::begin(_iType, _pins, _len);
|
||||
_busPtr = PolyBus::create(_iType, _pins, _len);
|
||||
_valid = (_busPtr != nullptr);
|
||||
_colorOrder = 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);
|
||||
};
|
||||
//TODO clean up stuff (destructor)
|
||||
|
||||
void show() {
|
||||
PolyBus::show(_busPtr, _iType);
|
||||
@ -112,6 +120,15 @@ class BusDigital : public Bus {
|
||||
_colorOrder = colorOrder;
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
PolyBus::cleanup(_busPtr, _iType);
|
||||
_iType = I_NONE;
|
||||
_valid = false;
|
||||
_busPtr = nullptr;
|
||||
pinManager.deallocatePin(_pins[0]);
|
||||
pinManager.deallocatePin(_pins[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t _colorOrder = COL_ORDER_GRB;
|
||||
uint8_t _pins[2] = {255, 255};
|
||||
@ -123,7 +140,7 @@ class BusDigital : public Bus {
|
||||
|
||||
class BusPwm : public Bus {
|
||||
public:
|
||||
BusPwm(uint8_t type, uint8_t* pins) : Bus(type) {
|
||||
BusPwm(uint8_t type, uint8_t* pins, uint16_t start) : Bus(type, start) {
|
||||
if (!IS_PWM(type)) return;
|
||||
uint8_t numPins = NUM_PWM_PINS(type);
|
||||
|
||||
@ -149,7 +166,6 @@ class BusPwm : public Bus {
|
||||
ledcAttachPin(_pins[i], _ledcStart + i);
|
||||
#endif
|
||||
}
|
||||
|
||||
_valid = true;
|
||||
};
|
||||
|
||||
@ -191,12 +207,12 @@ class BusPwm : public Bus {
|
||||
}
|
||||
}
|
||||
|
||||
~BusPwm() {
|
||||
void cleanup() {
|
||||
deallocatePins();
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t _pins[5];
|
||||
uint8_t _pins[5] = {255, 255, 255, 255, 255};
|
||||
uint8_t _data[5] = {255, 255, 255, 255, 255};
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
uint8_t _ledcStart = 255;
|
||||
@ -209,7 +225,7 @@ class BusPwm : public Bus {
|
||||
#ifdef ESP8266
|
||||
digitalWrite(_pins[i], LOW); //turn off PWM interrupt
|
||||
#else
|
||||
if (_ledcStart < 16) ledcDetachPin(_pins[i], _ledcStart + i);
|
||||
if (_ledcStart < 16) ledcDetachPin(_pins[i]);
|
||||
#endif
|
||||
pinManager.deallocatePin(_pins[i]);
|
||||
}
|
||||
@ -225,12 +241,12 @@ class BusManager {
|
||||
|
||||
};
|
||||
|
||||
int add(uint8_t busType, uint8_t* pins, uint16_t len = 1) {
|
||||
int add(uint8_t busType, uint8_t* pins, uint16_t start, uint16_t len = 1, uint8_t colorOrder = COL_ORDER_GRB) {
|
||||
if (numBusses >= WLED_MAX_BUSSES) return -1;
|
||||
if (IS_DIGITAL(busType)) {
|
||||
busses[numBusses] = new BusDigital(busType, pins, len, numBusses);
|
||||
busses[numBusses] = new BusDigital(busType, pins, start, len, colorOrder, numBusses);
|
||||
} else {
|
||||
busses[numBusses] = new BusPwm(busType, pins);
|
||||
busses[numBusses] = new BusPwm(busType, pins, start);
|
||||
}
|
||||
numBusses++;
|
||||
return numBusses -1;
|
||||
@ -280,6 +296,15 @@ class BusManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bus* getBus(uint8_t busNr) {
|
||||
if (busNr >= numBusses) return nullptr;
|
||||
return busses[busNr];
|
||||
}
|
||||
|
||||
uint8_t getNumBusses() {
|
||||
return numBusses;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t numBusses = 0;
|
||||
Bus* busses[WLED_MAX_BUSSES];
|
||||
|
@ -191,80 +191,154 @@
|
||||
//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
|
||||
static void begin(void* busPtr, uint8_t busType) {
|
||||
switch (busType) {
|
||||
case I_NONE: busPtr = new B_8266_U0_NEO_3(len, pins[0]); break;
|
||||
case I_NONE: 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;
|
||||
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->Begin(); break;
|
||||
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_8266_BB_TM1_4: (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;
|
||||
case I_32_R0_NEO_3: (static_cast<B_32_R0_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R1_NEO_3: (static_cast<B_32_R1_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R2_NEO_3: (static_cast<B_32_R2_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R3_NEO_3: (static_cast<B_32_R3_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R4_NEO_3: (static_cast<B_32_R4_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R5_NEO_3: (static_cast<B_32_R5_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R6_NEO_3: (static_cast<B_32_R6_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R7_NEO_3: (static_cast<B_32_R7_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R0_NEO_4: (static_cast<B_32_R0_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R1_NEO_4: (static_cast<B_32_R1_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R2_NEO_4: (static_cast<B_32_R2_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R3_NEO_4: (static_cast<B_32_R3_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R4_NEO_4: (static_cast<B_32_R4_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R5_NEO_4: (static_cast<B_32_R5_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R6_NEO_4: (static_cast<B_32_R6_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R7_NEO_4: (static_cast<B_32_R7_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R0_400_3: (static_cast<B_32_R0_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R1_400_3: (static_cast<B_32_R1_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R2_400_3: (static_cast<B_32_R2_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R3_400_3: (static_cast<B_32_R3_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R4_400_3: (static_cast<B_32_R4_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R5_400_3: (static_cast<B_32_R5_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R6_400_3: (static_cast<B_32_R6_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R7_400_3: (static_cast<B_32_R7_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Begin(); break;
|
||||
case I_32_R0_TM1_4: (static_cast<B_32_R0_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R1_TM1_4: (static_cast<B_32_R1_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R2_TM1_4: (static_cast<B_32_R2_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R3_TM1_4: (static_cast<B_32_R3_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R4_TM1_4: (static_cast<B_32_R4_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R5_TM1_4: (static_cast<B_32_R5_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R6_TM1_4: (static_cast<B_32_R6_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_R7_TM1_4: (static_cast<B_32_R7_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Begin(); break;
|
||||
case I_32_I1_TM1_4: (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;
|
||||
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
|
||||
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Begin(); break;
|
||||
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
|
||||
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Begin(); break;
|
||||
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
|
||||
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Begin(); break;
|
||||
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(); break;
|
||||
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Begin(); break;
|
||||
}
|
||||
};
|
||||
static void* create(uint8_t busType, uint8_t* pins, uint16_t len) {
|
||||
void* busPtr = nullptr;
|
||||
//delete busPtr; //TODO this needs type handling or destructor isn't called
|
||||
switch (busType) {
|
||||
case I_NONE: break;
|
||||
#ifdef ESP8266
|
||||
case I_8266_U0_NEO_3: busPtr = new B_8266_U0_NEO_3(len, pins[0]); break;
|
||||
case I_8266_U1_NEO_3: busPtr = new B_8266_U1_NEO_3(len, pins[0]); break;
|
||||
case I_8266_DM_NEO_3: busPtr = new B_8266_DM_NEO_3(len, pins[0]); break;
|
||||
case I_8266_BB_NEO_3: busPtr = new B_8266_BB_NEO_3(len, pins[0]); break;
|
||||
case I_8266_U0_NEO_4: busPtr = new B_8266_U0_NEO_4(len, pins[0]); break;
|
||||
case I_8266_U1_NEO_4: busPtr = new B_8266_U1_NEO_4(len, pins[0]); break;
|
||||
case I_8266_DM_NEO_4: busPtr = new B_8266_DM_NEO_4(len, pins[0]); break;
|
||||
case I_8266_BB_NEO_4: busPtr = new B_8266_BB_NEO_4(len, pins[0]); break;
|
||||
case I_8266_U0_400_3: busPtr = new B_8266_U0_400_3(len, pins[0]); break;
|
||||
case I_8266_U1_400_3: busPtr = new B_8266_U1_400_3(len, pins[0]); break;
|
||||
case I_8266_DM_400_3: busPtr = new B_8266_DM_400_3(len, pins[0]); break;
|
||||
case I_8266_BB_400_3: busPtr = new B_8266_BB_400_3(len, pins[0]); break;
|
||||
case I_8266_U0_TM1_4: busPtr = new B_8266_U0_TM1_4(len, pins[0]); break;
|
||||
case I_8266_U1_TM1_4: busPtr = new B_8266_U1_TM1_4(len, pins[0]); break;
|
||||
case I_8266_DM_TM1_4: busPtr = new B_8266_DM_TM1_4(len, pins[0]); break;
|
||||
case I_8266_BB_TM1_4: busPtr = new B_8266_BB_TM1_4(len, pins[0]); break;
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
case I_32_R0_NEO_3: busPtr = new B_32_R0_NEO_3(len, pins[0]); break;
|
||||
case I_32_R1_NEO_3: busPtr = new B_32_R1_NEO_3(len, pins[0]); break;
|
||||
case I_32_R2_NEO_3: busPtr = new B_32_R2_NEO_3(len, pins[0]); break;
|
||||
case I_32_R3_NEO_3: busPtr = new B_32_R3_NEO_3(len, pins[0]); break;
|
||||
case I_32_R4_NEO_3: busPtr = new B_32_R4_NEO_3(len, pins[0]); break;
|
||||
case I_32_R5_NEO_3: busPtr = new B_32_R5_NEO_3(len, pins[0]); break;
|
||||
case I_32_R6_NEO_3: busPtr = new B_32_R6_NEO_3(len, pins[0]); break;
|
||||
case I_32_R7_NEO_3: busPtr = new B_32_R7_NEO_3(len, pins[0]); break;
|
||||
case I_32_I0_NEO_3: busPtr = new B_32_I0_NEO_3(len, pins[0]); break;
|
||||
case I_32_I1_NEO_3: busPtr = new B_32_I1_NEO_3(len, pins[0]); break;
|
||||
case I_32_R0_NEO_4: busPtr = new B_32_R0_NEO_4(len, pins[0]); break;
|
||||
case I_32_R1_NEO_4: busPtr = new B_32_R1_NEO_4(len, pins[0]); break;
|
||||
case I_32_R2_NEO_4: busPtr = new B_32_R2_NEO_4(len, pins[0]); break;
|
||||
case I_32_R3_NEO_4: busPtr = new B_32_R3_NEO_4(len, pins[0]); break;
|
||||
case I_32_R4_NEO_4: busPtr = new B_32_R4_NEO_4(len, pins[0]); break;
|
||||
case I_32_R5_NEO_4: busPtr = new B_32_R5_NEO_4(len, pins[0]); break;
|
||||
case I_32_R6_NEO_4: busPtr = new B_32_R6_NEO_4(len, pins[0]); break;
|
||||
case I_32_R7_NEO_4: busPtr = new B_32_R7_NEO_4(len, pins[0]); break;
|
||||
case I_32_I0_NEO_4: busPtr = new B_32_I0_NEO_4(len, pins[0]); break;
|
||||
case I_32_I1_NEO_4: busPtr = new B_32_I1_NEO_4(len, pins[0]); break;
|
||||
case I_32_R0_400_3: busPtr = new B_32_R0_400_3(len, pins[0]); break;
|
||||
case I_32_R1_400_3: busPtr = new B_32_R1_400_3(len, pins[0]); break;
|
||||
case I_32_R2_400_3: busPtr = new B_32_R2_400_3(len, pins[0]); break;
|
||||
case I_32_R3_400_3: busPtr = new B_32_R3_400_3(len, pins[0]); break;
|
||||
case I_32_R4_400_3: busPtr = new B_32_R4_400_3(len, pins[0]); break;
|
||||
case I_32_R5_400_3: busPtr = new B_32_R5_400_3(len, pins[0]); break;
|
||||
case I_32_R6_400_3: busPtr = new B_32_R6_400_3(len, pins[0]); break;
|
||||
case I_32_R7_400_3: busPtr = new B_32_R7_400_3(len, pins[0]); break;
|
||||
case I_32_I0_400_3: busPtr = new B_32_I0_400_3(len, pins[0]); break;
|
||||
case I_32_I1_400_3: busPtr = new B_32_I1_400_3(len, pins[0]); break;
|
||||
case I_32_R0_TM1_4: busPtr = new B_32_R0_TM1_4(len, pins[0]); break;
|
||||
case I_32_R1_TM1_4: busPtr = new B_32_R1_TM1_4(len, pins[0]); break;
|
||||
case I_32_R2_TM1_4: busPtr = new B_32_R2_TM1_4(len, pins[0]); break;
|
||||
case I_32_R3_TM1_4: busPtr = new B_32_R3_TM1_4(len, pins[0]); break;
|
||||
case I_32_R4_TM1_4: busPtr = new B_32_R4_TM1_4(len, pins[0]); break;
|
||||
case I_32_R5_TM1_4: busPtr = new B_32_R5_TM1_4(len, pins[0]); break;
|
||||
case I_32_R6_TM1_4: busPtr = new B_32_R6_TM1_4(len, pins[0]); break;
|
||||
case I_32_R7_TM1_4: busPtr = new B_32_R7_TM1_4(len, pins[0]); break;
|
||||
case I_32_I0_TM1_4: busPtr = new B_32_I0_TM1_4(len, pins[0]); break;
|
||||
case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); break;
|
||||
#endif
|
||||
case I_HS_DOT_3: busPtr = new B_HS_DOT_3(len, pins[0], pins[1]); break;
|
||||
case I_SS_DOT_3: busPtr = new B_SS_DOT_3(len, pins[0], pins[1]); break;
|
||||
case I_HS_LPD_3: busPtr = new B_HS_LPD_3(len, pins[0], pins[1]); break;
|
||||
case I_SS_LPD_3: busPtr = new B_SS_LPD_3(len, pins[0], pins[1]); break;
|
||||
case I_HS_WS1_3: busPtr = new B_HS_WS1_3(len, pins[0], pins[1]); break;
|
||||
case I_SS_WS1_3: busPtr = new B_SS_WS1_3(len, pins[0], pins[1]); break;
|
||||
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[0], pins[1]); break;
|
||||
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[0], pins[1]); break;
|
||||
}
|
||||
begin(busPtr, busType);
|
||||
return busPtr;
|
||||
};
|
||||
static void show(void* busPtr, uint8_t busType) {
|
||||
@ -585,7 +659,6 @@ class PolyBus {
|
||||
};
|
||||
static uint32_t getPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint8_t co) {
|
||||
RgbwColor col;
|
||||
col = (static_cast<B_8266_U1_NEO_3*>(busPtr))->GetPixelColor(pix);
|
||||
switch (busType) {
|
||||
case I_NONE: break;
|
||||
#ifdef ESP8266
|
||||
@ -674,6 +747,82 @@ class PolyBus {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cleanup(void* busPtr, uint8_t busType) {
|
||||
if (busPtr == nullptr) return;
|
||||
switch (busType) {
|
||||
case I_NONE: break;
|
||||
#ifdef ESP8266
|
||||
case I_8266_U0_NEO_3: delete (static_cast<B_8266_U0_NEO_3*>(busPtr)); break;
|
||||
case I_8266_U1_NEO_3: delete (static_cast<B_8266_U1_NEO_3*>(busPtr)); break;
|
||||
case I_8266_DM_NEO_3: delete (static_cast<B_8266_DM_NEO_3*>(busPtr)); break;
|
||||
case I_8266_BB_NEO_3: delete (static_cast<B_8266_BB_NEO_3*>(busPtr)); break;
|
||||
case I_8266_U0_NEO_4: delete (static_cast<B_8266_U0_NEO_4*>(busPtr)); break;
|
||||
case I_8266_U1_NEO_4: delete (static_cast<B_8266_U1_NEO_4*>(busPtr)); break;
|
||||
case I_8266_DM_NEO_4: delete (static_cast<B_8266_DM_NEO_4*>(busPtr)); break;
|
||||
case I_8266_BB_NEO_4: delete (static_cast<B_8266_BB_NEO_4*>(busPtr)); break;
|
||||
case I_8266_U0_400_3: delete (static_cast<B_8266_U0_400_3*>(busPtr)); break;
|
||||
case I_8266_U1_400_3: delete (static_cast<B_8266_U1_400_3*>(busPtr)); break;
|
||||
case I_8266_DM_400_3: delete (static_cast<B_8266_DM_400_3*>(busPtr)); break;
|
||||
case I_8266_BB_400_3: delete (static_cast<B_8266_BB_400_3*>(busPtr)); break;
|
||||
case I_8266_U0_TM1_4: delete (static_cast<B_8266_U0_TM1_4*>(busPtr)); break;
|
||||
case I_8266_U1_TM1_4: delete (static_cast<B_8266_U1_TM1_4*>(busPtr)); break;
|
||||
case I_8266_DM_TM1_4: delete (static_cast<B_8266_DM_TM1_4*>(busPtr)); break;
|
||||
case I_8266_BB_TM1_4: delete (static_cast<B_8266_BB_TM1_4*>(busPtr)); break;
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
case I_32_R0_NEO_3: delete (static_cast<B_32_R0_NEO_3*>(busPtr)); break;
|
||||
case I_32_R1_NEO_3: delete (static_cast<B_32_R1_NEO_3*>(busPtr)); break;
|
||||
case I_32_R2_NEO_3: delete (static_cast<B_32_R2_NEO_3*>(busPtr)); break;
|
||||
case I_32_R3_NEO_3: delete (static_cast<B_32_R3_NEO_3*>(busPtr)); break;
|
||||
case I_32_R4_NEO_3: delete (static_cast<B_32_R4_NEO_3*>(busPtr)); break;
|
||||
case I_32_R5_NEO_3: delete (static_cast<B_32_R5_NEO_3*>(busPtr)); break;
|
||||
case I_32_R6_NEO_3: delete (static_cast<B_32_R6_NEO_3*>(busPtr)); break;
|
||||
case I_32_R7_NEO_3: delete (static_cast<B_32_R7_NEO_3*>(busPtr)); break;
|
||||
case I_32_I0_NEO_3: delete (static_cast<B_32_I0_NEO_3*>(busPtr)); break;
|
||||
case I_32_I1_NEO_3: delete (static_cast<B_32_I1_NEO_3*>(busPtr)); break;
|
||||
case I_32_R0_NEO_4: delete (static_cast<B_32_R0_NEO_4*>(busPtr)); break;
|
||||
case I_32_R1_NEO_4: delete (static_cast<B_32_R1_NEO_4*>(busPtr)); break;
|
||||
case I_32_R2_NEO_4: delete (static_cast<B_32_R2_NEO_4*>(busPtr)); break;
|
||||
case I_32_R3_NEO_4: delete (static_cast<B_32_R3_NEO_4*>(busPtr)); break;
|
||||
case I_32_R4_NEO_4: delete (static_cast<B_32_R4_NEO_4*>(busPtr)); break;
|
||||
case I_32_R5_NEO_4: delete (static_cast<B_32_R5_NEO_4*>(busPtr)); break;
|
||||
case I_32_R6_NEO_4: delete (static_cast<B_32_R6_NEO_4*>(busPtr)); break;
|
||||
case I_32_R7_NEO_4: delete (static_cast<B_32_R7_NEO_4*>(busPtr)); break;
|
||||
case I_32_I0_NEO_4: delete (static_cast<B_32_I0_NEO_4*>(busPtr)); break;
|
||||
case I_32_I1_NEO_4: delete (static_cast<B_32_I1_NEO_4*>(busPtr)); break;
|
||||
case I_32_R0_400_3: delete (static_cast<B_32_R0_400_3*>(busPtr)); break;
|
||||
case I_32_R1_400_3: delete (static_cast<B_32_R1_400_3*>(busPtr)); break;
|
||||
case I_32_R2_400_3: delete (static_cast<B_32_R2_400_3*>(busPtr)); break;
|
||||
case I_32_R3_400_3: delete (static_cast<B_32_R3_400_3*>(busPtr)); break;
|
||||
case I_32_R4_400_3: delete (static_cast<B_32_R4_400_3*>(busPtr)); break;
|
||||
case I_32_R5_400_3: delete (static_cast<B_32_R5_400_3*>(busPtr)); break;
|
||||
case I_32_R6_400_3: delete (static_cast<B_32_R6_400_3*>(busPtr)); break;
|
||||
case I_32_R7_400_3: delete (static_cast<B_32_R7_400_3*>(busPtr)); break;
|
||||
case I_32_I0_400_3: delete (static_cast<B_32_I0_400_3*>(busPtr)); break;
|
||||
case I_32_I1_400_3: delete (static_cast<B_32_I1_400_3*>(busPtr)); break;
|
||||
case I_32_R0_TM1_4: delete (static_cast<B_32_R0_TM1_4*>(busPtr)); break;
|
||||
case I_32_R1_TM1_4: delete (static_cast<B_32_R1_TM1_4*>(busPtr)); break;
|
||||
case I_32_R2_TM1_4: delete (static_cast<B_32_R2_TM1_4*>(busPtr)); break;
|
||||
case I_32_R3_TM1_4: delete (static_cast<B_32_R3_TM1_4*>(busPtr)); break;
|
||||
case I_32_R4_TM1_4: delete (static_cast<B_32_R4_TM1_4*>(busPtr)); break;
|
||||
case I_32_R5_TM1_4: delete (static_cast<B_32_R5_TM1_4*>(busPtr)); break;
|
||||
case I_32_R6_TM1_4: delete (static_cast<B_32_R6_TM1_4*>(busPtr)); break;
|
||||
case I_32_R7_TM1_4: delete (static_cast<B_32_R7_TM1_4*>(busPtr)); break;
|
||||
case I_32_I0_TM1_4: delete (static_cast<B_32_I0_TM1_4*>(busPtr)); break;
|
||||
case I_32_I1_TM1_4: delete (static_cast<B_32_I1_TM1_4*>(busPtr)); break;
|
||||
#endif
|
||||
case I_HS_DOT_3: delete (static_cast<B_HS_DOT_3*>(busPtr)); break;
|
||||
case I_SS_DOT_3: delete (static_cast<B_SS_DOT_3*>(busPtr)); break;
|
||||
case I_HS_LPD_3: delete (static_cast<B_HS_LPD_3*>(busPtr)); break;
|
||||
case I_SS_LPD_3: delete (static_cast<B_SS_LPD_3*>(busPtr)); break;
|
||||
case I_HS_WS1_3: delete (static_cast<B_HS_WS1_3*>(busPtr)); break;
|
||||
case I_SS_WS1_3: delete (static_cast<B_SS_WS1_3*>(busPtr)); break;
|
||||
case I_HS_P98_3: delete (static_cast<B_HS_P98_3*>(busPtr)); break;
|
||||
case I_SS_P98_3: delete (static_cast<B_SS_P98_3*>(busPtr)); break;
|
||||
}
|
||||
}
|
||||
|
||||
//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;
|
||||
|
Loading…
Reference in New Issue
Block a user