diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index 07bbf9b..efe9740 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -49,18 +49,19 @@ extern aJsonObject *dmxArr; 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)) - { - - 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; @@ -69,15 +70,15 @@ int itemCtrl2(char* name,int r,int g, int b, int w) case 2: // RGB { - + DmxWrite(itemaddr, r); DmxWrite(itemaddr+1, g); DmxWrite(itemaddr+2, b); - - break; } -#endif + + break; } +#endif case 7: //Group - aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1); + aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1); if (groupArr && (groupArr->type==aJson_Array)) { aJsonObject *i =groupArr->child; while (i) @@ -87,57 +88,62 @@ int itemCtrl2(char* name,int r,int g, int b, int w) } } //itemtype // break; - } //if have correct array + } //if have correct array +return 1; } 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 if (dmxArr && (dmxArr->type==aJson_Array)) - - { + + { 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) { 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]); } -}; - +}; + void DMXUpdate(void) { #if defined(_dmxin) 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; - - for (short trh=0; trh<4 ; trh++) + + for (short trh=0; trh<4 ; trh++) if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh]) { D_State |= (1< "); Serial.print(t);Serial.println(); DMXin[base+trh]=t; - //DMXImmediateUpdate(tch,trh,t); + //DMXImmediateUpdate(tch,trh,t); //break; } - - if (updated) + + if (updated) { DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]); D_checkT=millis()+D_CHECKT; @@ -153,19 +159,19 @@ for (short tch=0; tch<=3 ; tch++) // CHSV hsv; // CRGB rgb; #if defined(_dmxin) - + short t,tch; //Here code for semi-immediate update - for (t=1,tch=0; t<=8 ; t<<=1,tch++) - if (D_State & t) + for (t=1,tch=0; t<=8 ; t<<=1,tch++) + if (D_State & t) { // Serial.print(D_State,BIN);Serial.print(":"); - D_State &= ~t; - for (short trh=0; trh<4 ; trh++) + D_State &= ~t; + for (short trh=0; trh<4 ; trh++) DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]); - + } - + if ((millis()setArtDmxCallback(onDmxFrame); - #endif + #endif } void DMXoutSetup(int channels,int pin) { -#ifdef _dmxout +#ifdef _dmxout #if defined(__AVR__) DmxSimple.usePin(pin); DmxSimple.maxChannel(channels); @@ -231,7 +236,7 @@ void DMXoutSetup(int channels,int pin) #if defined(__ESP__) dmxout.init(channels); -#endif +#endif #if defined(__SAM3X8E__) dmxout.begin(); diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 5e2ea3b..69c8812 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1,3 +1,8 @@ + + + + + /* Copyright © 2017-2018 Andrey Klimov. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -550,7 +555,6 @@ void applyConfig() { Serial.println(maxChannels); } #endif - #ifdef _dmxin int itemsCount; dmxArr = aJson.getObjectItem(root, "dmxin"); @@ -560,7 +564,6 @@ void applyConfig() { Serial.println(itemsCount * 4); } #endif - #ifdef _modbus modbusArr = aJson.getObjectItem(root, "modbus"); #endif