UART methods & HA 1.31 support
- Update UART 1 and 2 methods for NeoPixelBus v2.4.1 - HA E1.31 support
This commit is contained in:
parent
00ff5c3aee
commit
2551240e63
5 changed files with 43 additions and 14 deletions
|
@ -61,7 +61,7 @@
|
|||
#ifdef ENABLE_E131
|
||||
#include <ESPAsyncUDP.h> //https://github.com/me-no-dev/ESPAsyncUDP
|
||||
#include <ESPAsyncE131.h> //https://github.com/forkineye/ESPAsyncE131
|
||||
ESPAsyncE131 e131(UNIVERSE_COUNT);
|
||||
ESPAsyncE131 e131(END_UNIVERSE - START_UNIVERSE + 1);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -96,14 +96,18 @@ WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
|
|||
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||
// on a live circuit...if you must, connect GND first.
|
||||
|
||||
#ifdef USE_WS2812FX_DMA
|
||||
#ifdef USE_WS2812FX_DMA // Uses GPIO3/RXD0/RX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
#include <NeoPixelBus.h>
|
||||
NeoEsp8266Dma800KbpsMethod dma = NeoEsp8266Dma800KbpsMethod(NUMLEDS, 3); //800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
//NeoEsp8266Dma400KbpsMethod dma = NeoEsp8266Dma400KbpsMethod(NUMLEDS, 3); //400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
#endif
|
||||
#ifdef USE_WS2812FX_UART
|
||||
#ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
#include <NeoPixelBus.h>
|
||||
NeoEsp8266Uart800KbpsMethod dma = NeoEsp8266Uart800KbpsMethod(NUMLEDS, 3);
|
||||
NeoEsp8266Uart0800KbpsMethod dma = NeoEsp8266Uart0800KbpsMethod(NUMLEDS, 3);
|
||||
#endif
|
||||
#ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
#include <NeoPixelBus.h>
|
||||
NeoEsp8266Uart1800KbpsMethod dma = NeoEsp8266Uart1800KbpsMethod(NUMLEDS, 3);
|
||||
#endif
|
||||
#if defined(USE_WS2812FX_DMA) or defined(USE_WS2812FX_UART)
|
||||
void DMA_Show(void) {
|
||||
|
@ -925,7 +929,7 @@ void setup() {
|
|||
#ifdef ENABLE_E131
|
||||
// Choose one to begin listening for E1.31 data
|
||||
// if (e131.begin(E131_UNICAST)) // Listen via Unicast
|
||||
if (e131.begin(E131_MULTICAST, UNIVERSE, UNIVERSE_COUNT)) // Listen via Multicast
|
||||
if (e131.begin(E131_MULTICAST, START_UNIVERSE, END_UNIVERSE)) // Listen via Multicast
|
||||
Serial.println(F("Listening for data..."));
|
||||
else
|
||||
Serial.println(F("*** e131.begin failed ***"));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//#define USE_WS2812FX_DMA // Uses PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
//#define USE_WS2812FX_UART // Uses PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
//#define USE_WS2812FX_UART1 // Uses PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
//#define USE_WS2812FX_UART2 // Uses PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
|
||||
// Neopixel
|
||||
#define PIN 14 // PIN (14 / D5) where neopixel / WS2811 strip is attached
|
||||
|
@ -20,8 +21,8 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
|
|||
#define ENABLE_E131 // E1.31 implementation
|
||||
|
||||
#ifdef ENABLE_E131
|
||||
#define UNIVERSE 1 // First DMX Universe to listen for
|
||||
#define UNIVERSE_COUNT 2 // Total number of Universes to listen for, starting at UNIVERSE
|
||||
#define START_UNIVERSE 1 // First DMX Universe to listen for
|
||||
#define END_UNIVERSE 2 // Total number of Universes to listen for, starting at UNIVERSE
|
||||
#endif
|
||||
|
||||
//#define WIFIMGR_PORTAL_TIMEOUT 180
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Request handlers
|
||||
// ***************************************************************************
|
||||
#ifdef ENABLE_E131
|
||||
void checkForRequests(void); //prototype
|
||||
|
||||
void handleE131(){
|
||||
if (!e131.isEmpty())
|
||||
{
|
||||
|
@ -11,7 +13,7 @@ void handleE131(){
|
|||
uint16_t universe = htons(packet.universe);
|
||||
uint8_t *data = packet.property_values + 1;
|
||||
|
||||
if (universe < UNIVERSE || universe > UNIVERSE_COUNT) return; //async will take care about filling the buffer
|
||||
if (universe < START_UNIVERSE || universe > END_UNIVERSE) return; //async will take care about filling the buffer
|
||||
|
||||
// Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
|
||||
// htons(packet.universe), // The Universe for this packet
|
||||
|
@ -20,7 +22,7 @@ void handleE131(){
|
|||
// e131.stats.packet_errors, // Packet error counter
|
||||
// packet.property_values[1]); // Dimmer data for Channel 1
|
||||
|
||||
uint16_t multipacketOffset = (universe - UNIVERSE) * 170; //if more than 170 LEDs (510 channels), client will send in next higher universe
|
||||
uint16_t multipacketOffset = (universe - START_UNIVERSE) * 170; //if more than 170 LEDs (510 channels), client will send in next higher universe
|
||||
if (NUMLEDS <= multipacketOffset) return;
|
||||
uint16_t len = (170 + multipacketOffset > NUMLEDS) ? (NUMLEDS - multipacketOffset) : 170;
|
||||
for (uint16_t i = 0; i < len; i++){
|
||||
|
@ -28,6 +30,7 @@ void handleE131(){
|
|||
strip.setPixelColor(i + multipacketOffset, data[j], data[j + 1], data[j + 2]);
|
||||
}
|
||||
strip.show();
|
||||
checkForRequests();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -839,7 +842,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
|
||||
//char modeName[30];
|
||||
//strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
root["effect"] = strip.getModeName(strip.getMode());
|
||||
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
|
||||
if (mode == E131)
|
||||
root["effect"] = "E131";
|
||||
else
|
||||
root["effect"] = strip.getModeName(strip.getMode());
|
||||
#else
|
||||
root["effect"] = strip.getModeName(strip.getMode());
|
||||
#endif
|
||||
|
||||
char buffer[measureJson(root) + 1];
|
||||
serializeJson(root, buffer, sizeof(buffer));
|
||||
|
@ -918,6 +928,13 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
String effectString = root["effect"].as<String>();
|
||||
|
||||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
#if defined(ENABLE_E131) and defined(ENABLE_HOMEASSISTANT)
|
||||
if(effectString == "E131"){
|
||||
if(strip.isRunning()) strip.stop();
|
||||
mode = E131;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if(String(strip.getModeName(i)) == effectString) {
|
||||
mode = SET_MODE;
|
||||
ws2812fx_mode = i;
|
||||
|
@ -1012,6 +1029,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
effect_list.add(strip.getModeName(i));
|
||||
}
|
||||
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||
effect_list.add("E131");
|
||||
#endif
|
||||
char buffer[measureJson(json) + 1];
|
||||
serializeJson(json, buffer, sizeof(buffer));
|
||||
mqtt_client.publish(String("homeassistant/light/" + String(HOSTNAME) + "/config").c_str(), buffer, true);
|
||||
|
@ -1096,6 +1116,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||
effect_list.add(strip.getModeName(i));
|
||||
}
|
||||
#if defined(ENABLE_E131) and defined(MQTT_HOME_ASSISTANT_SUPPORT)
|
||||
effect_list.add("E131");
|
||||
#endif
|
||||
char buffer[measureJson(json) + 1];
|
||||
serializeJson(json, buffer, sizeof(buffer));
|
||||
DBG_OUTPUT_PORT.println(buffer);
|
||||
|
|
|
@ -63,6 +63,7 @@ light:
|
|||
- "Bicolor Chase"
|
||||
- "Tricolor Chase"
|
||||
- "ICU"
|
||||
- "E131"
|
||||
brightness: true
|
||||
color_temp: true
|
||||
rgb: true
|
||||
|
@ -79,7 +80,7 @@ input_number:
|
|||
step: 5
|
||||
|
||||
automation:
|
||||
- id: 71938579813759813757
|
||||
- id: "71938579813759813757"
|
||||
alias: NeoPixel Animation Speed Send
|
||||
initial_state: true
|
||||
hide_entity: false
|
||||
|
@ -93,7 +94,7 @@ automation:
|
|||
topic: home/McLighting01_ha/state/in
|
||||
service: mqtt.publish
|
||||
|
||||
- id: 93786598732698756967
|
||||
- id: "93786598732698756967"
|
||||
alias: NeoPixel Animation Speed Receive
|
||||
trigger:
|
||||
- platform: mqtt
|
||||
|
|
|
@ -51,7 +51,7 @@ lib_deps =
|
|||
AsyncMqttClient
|
||||
https://github.com/bblanchon/ArduinoJson.git#v6.7.0-beta
|
||||
WS2812FX
|
||||
NeoPixelBus
|
||||
NeoPixelBus@2.4.1
|
||||
WebSockets
|
||||
ESPAsyncE131
|
||||
ESPAsyncUDP
|
Loading…
Reference in a new issue