diff --git a/dmx.cpp b/dmx.cpp index 5129c84..64a722a 100644 --- a/dmx.cpp +++ b/dmx.cpp @@ -57,6 +57,7 @@ for (short tch=0; tch<=3 ; tch++) void DMXUpdate(void) { +#if defined(__AVR_ATmega2560__) int t; for (short tch=0; tch<=3 ; tch++) { @@ -81,6 +82,7 @@ for (short tch=0; tch<=3 ; tch++) } } //Serial.print(D_State,BIN);Serial.println(); +#endif } @@ -88,6 +90,7 @@ for (short tch=0; tch<=3 ; tch++) { // CHSV hsv; // CRGB rgb; +#if defined(__AVR_ATmega2560__) short t,tch; //Here code for semi-immediate update @@ -109,6 +112,7 @@ D_checkT=0; DMXput(); for (int i=1; i<17; i++) {Serial.print(DMXSerial.read(i));Serial.print(";");} Serial.println(); +#endif } @@ -125,14 +129,15 @@ void DMXinSetup(int channels) // //Use digital pin 3 for DMX output. Must be a PWM channel. // DmxSimple.usePin(pin); //DmxSimple.maxChannel(channels); - + #if defined(__AVR_ATmega2560__) + DMXin = new uint8_t [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")); //DMXSerial.maxChannel(channels); DMXSerial.attachOnUpdate(&DMXUpdate); - + #endif // this will be called for each packet received if (artnet) artnet->setArtDmxCallback(onDmxFrame); } diff --git a/dmx.h b/dmx.h index 4ede4bd..8e3c33e 100644 --- a/dmx.h +++ b/dmx.h @@ -29,9 +29,24 @@ e-mail anklimov@gmail.com //#define DMX_OUT_PIN 3 +#if defined(__AVR__) #include +#endif + +#if defined(__ESP__) +#include +#endif + +#if defined(__SAM3X8E__) +#include +#endif + #include + +#if defined(__AVR_ATmega2560__) #include +#endif + #include "aJSON.h" extern aJsonObject *dmxArr; diff --git a/item.cpp b/item.cpp index efae7dd..632ec28 100644 --- a/item.cpp +++ b/item.cpp @@ -20,7 +20,18 @@ e-mail anklimov@gmail.com #include "item.h" #include "aJSON.h" +#if defined(__AVR__) #include +#endif + +#if defined(__ESP__) +#include +#endif + +#if defined(__SAM3X8E__) +#include +#endif + #include "FastLED.h" #include #include @@ -465,12 +476,13 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) //prescaler = 5 ---> PWM frequency is 30 Hz //prescaler = 6 ---> PWM frequency is <20 Hz int tval = 7; // this is 111 in binary and is used as an eraser +#if defined(__AVR_ATmega2560__) TCCR4B &= ~tval; // this operation (AND plus NOT), set the three bits in TCCR2B to 0 TCCR3B &= ~tval; tval=2; TCCR4B|=tval; TCCR3B|=tval; - +#endif if (inverse) k=map(Par[0],100,0,0,255); else k=map(Par[0],0,100,0,255); analogWrite(iaddr,k); @@ -805,7 +817,7 @@ if (node.getResponseBuffer(0) & 8) //Active fault if (result == node.ku8MBSuccess) aJson.addNumberToObject(out,"flt", (int) node.getResponseBuffer(0)); } - +delay(50); result = node.readHoldingRegisters(20-1, 4); // do something with data if read is successful @@ -844,7 +856,8 @@ result = node.readHoldingRegisters(20-1, 4); if (modbusBusy) return -1; modbusBusy=1; - node.begin(9600,SERIAL_8E1,13); + node.begin(9600,SERIAL_8E1,13); + //node.begin(9600,UARTClass::Mode_8E1,13); uint8_t result; diff --git a/lighthub.ino b/lighthub.ino index 4343567..3b370bf 100644 --- a/lighthub.ino +++ b/lighthub.ino @@ -62,12 +62,24 @@ dmx relay out #include "HTTPClient.h" #include #include "stdarg.h" + +#if defined(__AVR__) #include -#include +#include #include "dmx.h" +#endif + +#if defined(__SAM3X8E__) +#include +DueFlashStorage EEPROM; +#else +#include +#endif + + #include "item.h" #include "inputs.h" -#include +#include "dmx.h" // Hardcoded definitions //Thermostate histeresys @@ -302,7 +314,9 @@ break; break; case 2: // IP Ready, Connecting & subscribe //Arming Watchdog +#if defined(__AVR_ATmega2560__) wdt_enable(WDTO_8S); +#endif if (!client.connected() && mqttArr && (aJson.getArraySize(mqttArr)>1)) { char *c=aJson.getArrayItem(mqttArr,1)->valuestring; @@ -354,7 +368,10 @@ break; //if (millis()>mtnCnt) { //mtnCnt=millis()+2; +#if defined(__AVR_ATmega2560__) wdt_disable(); +#endif + switch (Ethernet.maintain()) { case 1: @@ -390,7 +407,9 @@ switch (Ethernet.maintain()) break; } +#if defined(__AVR_ATmega2560__) wdt_enable(WDTO_8S); +#endif } return lanStatus; @@ -655,7 +674,7 @@ void _setConfig(int arg_cnt, char **args) return; } printMACAddress(); - for (short i=0;i<6;i++) { EEPROM.update(i, mac[i]);} + for (short i=0;i<6;i++) { EEPROM.write(i, mac[i]);} Serial.println(F("Updated")); } @@ -773,14 +792,18 @@ void setup() { void loop(){ +#if defined(__AVR_ATmega2560__) wdt_reset(); +#endif //commandLine.update(); cmdPoll(); if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();} if (owReady && owArr) owLoop(); +#if defined(__AVR_ATmega2560__) unsigned long lastpacket = DMXSerial.noDataSince(); +#endif // if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket); DMXCheck(); @@ -793,8 +816,9 @@ if (owReady && owArr) owLoop(); // Idle handlers void owIdle(void) { if (artnet) artnet->read(); +#if defined(__AVR_ATmega2560__) wdt_reset(); - +#endif return;/// Serial.print("o"); @@ -808,8 +832,9 @@ if (lanLoop() == 1) client.loop(); void modbusIdle(void) { //Serial.print("m"); +#if defined(__AVR_ATmega2560__) wdt_reset(); - +#endif if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();} //if (owReady) owLoop(); DMXCheck(); diff --git a/owSwitch.h b/owSwitch.h index 975e9bd..a3df682 100644 --- a/owSwitch.h +++ b/owSwitch.h @@ -19,7 +19,7 @@ e-mail anklimov@gmail.com */ //define APU_OFF -#include +#include #include diff --git a/owTerm.h b/owTerm.h index 5c2494a..2840de0 100644 --- a/owTerm.h +++ b/owTerm.h @@ -52,7 +52,7 @@ e-mail anklimov@gmail.com #define t_max 20 //Maximum number of 1w devices #define TEMPERATURE_PRECISION 9 -#include +#include #include #include "aJSON.h"