@
folny Web_Base_WS2812.zip
Посмотреть вложение 478
Задержки у драйвера WS2812 сделаны на fifo шины к GPIO-ports. Это не всегда работает правильно.
Hi pvvx
Great job code works perfectly

fit the control handle up to 1024 pixels ws2812 thank you very much. Will you help me please even modify the code for protocol ArtNet ? I modified the code for a 4 Universe and worked well but I would also like to use it to your code.
here is the original code:
https://github.com/sfranzyshen/EspLightNode/blob/master/user/input_protocols/artnet.c
my code for a 4 Universe
[HASHTAG]#include[/HASHTAG] "ets_sys.h"
[HASHTAG]#include[/HASHTAG] "osapi.h"
[HASHTAG]#include[/HASHTAG] "os_type.h"
[HASHTAG]#include[/HASHTAG] "user_interface.h"
[HASHTAG]#include[/HASHTAG] "espconn.h"
[HASHTAG]#include[/HASHTAG] "ws2812.h"
[HASHTAG]#define[/HASHTAG] ARTNET_Port 0x1936
uint8_t artnet_enabled = 1;
char artnet_shortname[18] = "Pixel Controller";
char artnet_longname[64] = "ArtNet LED Pixel Controller";
uint8_t artnet_net = 0;
uint8_t artnet_subnet= 0;
uint8_t artnet_universe1= 0;
uint8_t artnet_universe2= 1;
uint8_t artnet_universe3= 2;
uint8_t artnet_universe4= 3;
static void ICACHE_FLASH_ATTR artnet_recv_opoutput(unsigned char *packet, unsigned short packetlen)
{
uint8_t SubUni0 = packet[4];
uint8_t Net0 = packet[5];
if (Net0 == artnet_net && (SubUni0 >> 4) == artnet_subnet && (SubUni0 & 0xF) == artnet_universe1)
{
uint16_t Length = ((uint16_t)packet[6] << 8) | packet[7];
if (packetlen >= 8 + Length) {
uint8_t *data = &packet[8];
ws2812_strip1(data,Length);
}
}
uint8_t SubUni1 = packet[4];
uint8_t Net1 = packet[5];
if (Net1 == artnet_net && (SubUni1 >> 4) == artnet_subnet && (SubUni1 & 0xF) == artnet_universe2)
{
uint16_t Length = ((uint16_t)packet[6] << 8) | packet[7];
if (packetlen >= 8 + Length) {
uint8_t *data = &packet[8];
ws2812_strip2(data,Length);
}
}
uint8_t SubUni2 = packet[4];
uint8_t Net2 = packet[5];
if (Net2 == artnet_net && (SubUni2 >> 4) == artnet_subnet && (SubUni2 & 0xF) == artnet_universe3)
{
uint16_t Length = ((uint16_t)packet[6] << 8) | packet[7];
if (packetlen >= 8 + Length) {
uint8_t *data = &packet[8];
ws2812_strip3(data,Length);
}
}
uint8_t SubUni3 = packet[4];
uint8_t Net3 = packet[5];
if (Net3 == artnet_net && (SubUni3 >> 4) == artnet_subnet && (SubUni3 & 0xF) == artnet_universe4)
{
uint16_t Length = ((uint16_t)packet[6] << 8) | packet[7];
if (packetlen >= 8 + Length) {
uint8_t *data = &packet[8];
ws2812_strip4(data,Length);
}
}
}
[HASHTAG]#define[/HASHTAG] ARTNET_OpPoll 0x2000
[HASHTAG]#define[/HASHTAG] ARTNET_OpPollReply 0x2100
[HASHTAG]#define[/HASHTAG] ARTNET_OpOutput 0x5000
[HASHTAG]#define[/HASHTAG] TTM_REPLY_MASK 0
struct ArtNetPollReply {
uint8_t ID[8];
uint8_t OpCode[2]; //low-first
uint8_t IP[4];
uint8_t Port[2]; //Low-first
uint8_t VersInfo[2]; //High-first
uint8_t NetSwitch;
uint8_t SubSwitch;
uint8_t Oem[2]; //High-first
uint8_t Ubea_Version;
uint8_t Status1;
uint8_t EstaMan[2]; //Low-first
uint8_t ShortName[18];
uint8_t LongName[64];
uint8_t NodeReport[64];
uint8_t NumPorts[2]; //High-first
uint8_t PortTypes[4];
uint8_t GoodInput[4];
uint8_t GoodOutput[4];
uint8_t SwIn[4];
uint8_t SwOut[4];
uint8_t SwVideo;
uint8_t SwMacro;
uint8_t SwRemote;
uint8_t Spare[3];
uint8_t Style;
uint8_t MAC[6]; //High-byte first
uint8_t BindIp[4];
uint8_t BindIndex;
uint8_t Status2;
uint8_t Filler[26];
};
[HASHTAG]#define[/HASHTAG] ARTNET_SET_SHORT_LOFIRST(target,value) (target)[0] = (value) & 0xFF; (target)[1] = (value) >> 8;
[HASHTAG]#define[/HASHTAG] ARTNET_SET_SHORT_HIFIRST(target,value) (target)[0] = (value) >> 8; (target)[1] = (value) & 0xFF;
static void ICACHE_FLASH_ATTR artnet_recv_oppoll(struct espconn *conn, unsigned char *packet, unsigned short packetlen) {
if (packetlen >= 3) {
uint16_t ProtVer=((uint16_t)packet[0] << 8) | packet[1];
uint8_t TalkToMe=packet[2];
//TODO
if (TalkToMe & TTM_REPLY_MASK) {
} else {
}
struct ip_info ipconfig;
char hwaddr[6];
wifi_get_ip_info(STATION_IF, &ipconfig);
wifi_get_macaddr(STATION_IF, hwaddr);
struct ArtNetPollReply response;
memset(&response, 0, sizeof(struct ArtNetPollReply));
strcpy((char*)response.ID,"Art-Net");
ARTNET_SET_SHORT_LOFIRST(response.OpCode, ARTNET_OpPollReply);
memcpy(response.IP,&ipconfig.ip.addr,4);
ARTNET_SET_SHORT_LOFIRST(response.Port, ARTNET_Port);
ARTNET_SET_SHORT_HIFIRST(response.VersInfo, 0);
response.NetSwitch = artnet_net;
response.SubSwitch = artnet_subnet;
ARTNET_SET_SHORT_HIFIRST(response.Oem,0);
response.Ubea_Version = 0;
response.Status1 = 0;
ARTNET_SET_SHORT_LOFIRST(response.EstaMan,0);
memcpy(response.ShortName,artnet_shortname, sizeof(response.ShortName));
memcpy(response.LongName,artnet_longname, sizeof(response.LongName));
strcpy(response.NodeReport,"");
ARTNET_SET_SHORT_HIFIRST(response.NumPorts,4);
response.PortTypes[0]=0x80;
response.PortTypes[1]=0x80;
response.PortTypes[2]=0x80;
response.PortTypes[3]=0x80;
//Not set is set to 0
//response.GoodInput = 0;
//response.GoodOutput = 0;
response.SwOut[0] = artnet_universe1;
response.SwOut[1] = artnet_universe2;
response.SwOut[2] = artnet_universe3;
response.SwOut[3] = artnet_universe4;
//response.SwVideo
//response.SwMacro
//response.SwRemote
//response.Style
memcpy(response.MAC,hwaddr,6);
//response.BindIp
//response.BindIndex
//response.Status2
espconn_sent(conn,(char*)&response,sizeof(struct ArtNetPollReply));
} else {
//Invalid length
}
}
static void ICACHE_FLASH_ATTR artnet_recv(void *arg, char *pusrdata, unsigned short length) {
unsigned char *data =(unsigned char *)pusrdata;
if (data && length>=10) {
if (data[0]=='A' && data[1]=='r' && data[2]=='t' && data[3]=='-' && data[4]=='N' && data[5]=='e' && data[6]=='t' && data[7]==0) {
uint16_t OpCode=data[8] | ((uint16_t)data[9] << 8);
switch (OpCode) {
case ARTNET_OpOutput:
return artnet_recv_opoutput(&data[10],length-10);
case ARTNET_OpPoll:
return artnet_recv_oppoll((struct espconn *)arg,&data[10],length-10);
}
} else {
//Header invalid
}
} else {
//Package too small.
}
}
void artnet_init() {
static struct espconn artnetconn;
static esp_udp artnetudp;
artnetconn.type = ESPCONN_UDP;
artnetconn.state = ESPCONN_NONE;
artnetconn.proto.udp = &artnetudp;
artnetudp.local_port=ARTNET_Port;
artnetconn.reverse = NULL;
if (artnet_enabled) {
espconn_regist_recvcb(&artnetconn, artnet_recv);
espconn_create(&artnetconn);
}
}