DUE DMX-IN fix

This commit is contained in:
2018-04-17 23:24:29 +03:00
parent 4f340d780f
commit 3a66d916dd
2 changed files with 58 additions and 50 deletions

View File

@@ -49,18 +49,19 @@ extern aJsonObject *dmxArr;
int itemCtrl2(char* name,int r,int g, int b, int w) int itemCtrl2(char* name,int r,int g, int b, int w)
{ {
aJsonObject *itemArr= aJson.getObjectItem(items, name); if (!items) return 0;
aJsonObject *itemArr= aJson.getObjectItem(items, name);
if (itemArr && (itemArr->type==aJson_Array)) if (itemArr && (itemArr->type==aJson_Array))
{ {
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
switch (itemtype){
#ifdef _dmxout
case 0: //Dimmed light
DmxWrite(itemaddr, w); short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
switch (itemtype){
#ifdef _dmxout
case 0: //Dimmed light
DmxWrite(itemaddr, w);
break; break;
@@ -69,15 +70,15 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
case 2: // RGB case 2: // RGB
{ {
DmxWrite(itemaddr, r); DmxWrite(itemaddr, r);
DmxWrite(itemaddr+1, g); DmxWrite(itemaddr+1, g);
DmxWrite(itemaddr+2, b); DmxWrite(itemaddr+2, b);
break; } break; }
#endif #endif
case 7: //Group case 7: //Group
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1); aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
if (groupArr && (groupArr->type==aJson_Array)) if (groupArr && (groupArr->type==aJson_Array))
{ aJsonObject *i =groupArr->child; { aJsonObject *i =groupArr->child;
while (i) while (i)
@@ -87,57 +88,62 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
} }
} //itemtype } //itemtype
// break; // break;
} //if have correct array } //if have correct array
return 1;
} }
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) { void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
//Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT //Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT
if (dmxArr && (dmxArr->type==aJson_Array)) if (dmxArr && (dmxArr->type==aJson_Array))
{ {
char* itemname = aJson.getArrayItem(dmxArr,tch)->valuestring; char* itemname = aJson.getArrayItem(dmxArr,tch)->valuestring;
itemCtrl2(itemname,r,g,b,w); if (itemname) itemCtrl2(itemname,r,g,b,w);
} }
} }
void DMXSemiImmediateUpdate(short tch,short trh, int val) void DMXSemiImmediateUpdate(short tch,short trh, int val)
{ {
//Here any code for passthrow between DMX IN and DMX OUT in idle state //Here any code for passthrow between DMX IN and DMX OUT in idle state
} }
void DMXput(void) void DMXput(void)
{ {
int t; int t;
for (short tch=0; tch<=3 ; tch++) for (short tch=0; tch<=3 ; tch++)
{ {
short base = tch*4; short base = tch*4;
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]); DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
} }
}; };
void DMXUpdate(void) void DMXUpdate(void)
{ {
#if defined(_dmxin) #if defined(_dmxin)
int t; int t;
for (short tch=0; tch<=3 ; tch++) if(!DMXin) return;
#if defined(__SAM3X8E__)
if (dmxin.getRxLength()<16) return;
#endif
for (short tch=0; tch<=3 ; tch++)
{ {
short base = tch*4; short base = tch*4;
bool updated = 0; bool updated = 0;
for (short trh=0; trh<4 ; trh++) for (short trh=0; trh<4 ; trh++)
if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh]) if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh])
{ {
D_State |= (1<<tch); D_State |= (1<<tch);
updated=1; updated=1;
//Serial.print("Changed :"); Serial.print(DMXin[tch*4+trh]); Serial.print(" => "); Serial.print(t);Serial.println(); //Serial.print("Changed :"); Serial.print(DMXin[tch*4+trh]); Serial.print(" => "); Serial.print(t);Serial.println();
DMXin[base+trh]=t; DMXin[base+trh]=t;
//DMXImmediateUpdate(tch,trh,t); //DMXImmediateUpdate(tch,trh,t);
//break; //break;
} }
if (updated) if (updated)
{ {
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]); DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
D_checkT=millis()+D_CHECKT; D_checkT=millis()+D_CHECKT;
@@ -153,19 +159,19 @@ for (short tch=0; tch<=3 ; tch++)
// CHSV hsv; // CHSV hsv;
// CRGB rgb; // CRGB rgb;
#if defined(_dmxin) #if defined(_dmxin)
short t,tch; short t,tch;
//Here code for semi-immediate update //Here code for semi-immediate update
for (t=1,tch=0; t<=8 ; t<<=1,tch++) for (t=1,tch=0; t<=8 ; t<<=1,tch++)
if (D_State & t) if (D_State & t)
{ {
// Serial.print(D_State,BIN);Serial.print(":"); // Serial.print(D_State,BIN);Serial.print(":");
D_State &= ~t; D_State &= ~t;
for (short trh=0; trh<4 ; trh++) for (short trh=0; trh<4 ; trh++)
DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]); DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]);
} }
if ((millis()<D_checkT) || (D_checkT==0)) return; if ((millis()<D_checkT) || (D_checkT==0)) return;
D_checkT=0; D_checkT=0;
@@ -185,9 +191,9 @@ void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* d
#ifdef _dmxout #ifdef _dmxout
for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++) for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
{ {
DmxWrite(i+1,data[i]); DmxWrite(i+1,data[i]);
} }
#endif #endif
} }
void DMXinSetup(int channels) void DMXinSetup(int channels)
@@ -196,10 +202,10 @@ void DMXinSetup(int channels)
// //Use digital pin 3 for DMX output. Must be a PWM channel. // //Use digital pin 3 for DMX output. Must be a PWM channel.
// DmxSimple.usePin(pin); // DmxSimple.usePin(pin);
//DmxSimple.maxChannel(channels); //DmxSimple.maxChannel(channels);
#if defined(_dmxin) #if defined(_dmxin)
DMXin = new uint8_t [channels]; DMXin = new uint8_t [channels];
#if defined(__AVR__) #if defined(__AVR__)
DMXSerial.init(DMXReceiver,0,channels); DMXSerial.init(DMXReceiver,0,channels);
if (DMXSerial.getBuffer()) {Serial.print(F("Init in ch:"));Serial.println(channels);} else Serial.println(F("DMXin Buffer alloc err")); if (DMXSerial.getBuffer()) {Serial.print(F("Init in ch:"));Serial.println(channels);} else Serial.println(F("DMXin Buffer alloc err"));
//DMXSerial.maxChannel(channels); //DMXSerial.maxChannel(channels);
@@ -207,22 +213,21 @@ void DMXinSetup(int channels)
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
dmxin.setRxEvent(DMXUpdate);
dmxin.begin(); dmxin.begin();
dmxin.setRxEvent(DMXUpdate);
#endif #endif
#endif #endif
#ifdef _artnet #ifdef _artnet
// this will be called for each packet received // this will be called for each packet received
if (artnet) artnet->setArtDmxCallback(onDmxFrame); if (artnet) artnet->setArtDmxCallback(onDmxFrame);
#endif #endif
} }
void DMXoutSetup(int channels,int pin) void DMXoutSetup(int channels,int pin)
{ {
#ifdef _dmxout #ifdef _dmxout
#if defined(__AVR__) #if defined(__AVR__)
DmxSimple.usePin(pin); DmxSimple.usePin(pin);
DmxSimple.maxChannel(channels); DmxSimple.maxChannel(channels);
@@ -231,7 +236,7 @@ void DMXoutSetup(int channels,int pin)
#if defined(__ESP__) #if defined(__ESP__)
dmxout.init(channels); dmxout.init(channels);
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
dmxout.begin(); dmxout.begin();

View File

@@ -1,3 +1,8 @@
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved. /* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
* *
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
@@ -550,7 +555,6 @@ void applyConfig() {
Serial.println(maxChannels); Serial.println(maxChannels);
} }
#endif #endif
#ifdef _dmxin #ifdef _dmxin
int itemsCount; int itemsCount;
dmxArr = aJson.getObjectItem(root, "dmxin"); dmxArr = aJson.getObjectItem(root, "dmxin");
@@ -560,7 +564,6 @@ void applyConfig() {
Serial.println(itemsCount * 4); Serial.println(itemsCount * 4);
} }
#endif #endif
#ifdef _modbus #ifdef _modbus
modbusArr = aJson.getObjectItem(root, "modbus"); modbusArr = aJson.getObjectItem(root, "modbus");
#endif #endif