preparing code to AVR and ESP portation

This commit is contained in:
2017-11-17 03:34:24 +03:00
parent 4e5300134e
commit d1e0a96747
6 changed files with 70 additions and 12 deletions

View File

@@ -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,6 +129,7 @@ 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];
@@ -132,7 +137,7 @@ void DMXinSetup(int 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);
}

15
dmx.h
View File

@@ -29,9 +29,24 @@ e-mail anklimov@gmail.com
//#define DMX_OUT_PIN 3
#if defined(__AVR__)
#include <DmxSimple.h>
#endif
#if defined(__ESP__)
#include <ESP-Dmx.h>
#endif
#if defined(__SAM3X8E__)
#include <DmxSimple.h>
#endif
#include <Artnet.h>
#if defined(__AVR_ATmega2560__)
#include <DMXSerial.h>
#endif
#include "aJSON.h"
extern aJsonObject *dmxArr;

View File

@@ -20,7 +20,18 @@ e-mail anklimov@gmail.com
#include "item.h"
#include "aJSON.h"
#if defined(__AVR__)
#include <DmxSimple.h>
#endif
#if defined(__ESP__)
#include <ESP-Dmx.h>
#endif
#if defined(__SAM3X8E__)
#include <DmxSimple.h>
#endif
#include "FastLED.h"
#include <ModbusMaster.h>
#include <PubSubClient2.h>
@@ -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
@@ -845,6 +857,7 @@ result = node.readHoldingRegisters(20-1, 4);
modbusBusy=1;
node.begin(9600,SERIAL_8E1,13);
//node.begin(9600,UARTClass::Mode_8E1,13);
uint8_t result;

View File

@@ -62,12 +62,24 @@ dmx relay out
#include "HTTPClient.h"
#include <Cmd.h>
#include "stdarg.h"
#if defined(__AVR__)
#include <avr/pgmspace.h>
#include <EEPROM.h>
#include <avr/wdt.h>
#include "dmx.h"
#endif
#if defined(__SAM3X8E__)
#include <DueFlashStorage.h>
DueFlashStorage EEPROM;
#else
#include <EEPROM.h>
#endif
#include "item.h"
#include "inputs.h"
#include <avr/wdt.h>
#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();

View File

@@ -19,7 +19,7 @@ e-mail anklimov@gmail.com
*/
//define APU_OFF
#include <OneWire.h>
#include <DS2482_OneWire.h>
#include <DallasTemperature.h>

View File

@@ -52,7 +52,7 @@ e-mail anklimov@gmail.com
#define t_max 20 //Maximum number of 1w devices
#define TEMPERATURE_PRECISION 9
#include <OneWire.h>
#include <DS2482_OneWire.h>
#include <DallasTemperature.h>
#include "aJSON.h"