mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
preparing code to AVR and ESP portation
This commit is contained in:
9
dmx.cpp
9
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);
|
||||
}
|
||||
|
||||
15
dmx.h
15
dmx.h
@@ -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;
|
||||
|
||||
19
item.cpp
19
item.cpp
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
35
lighthub.ino
35
lighthub.ino
@@ -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();
|
||||
|
||||
@@ -19,7 +19,7 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
|
||||
//define APU_OFF
|
||||
#include <OneWire.h>
|
||||
#include <DS2482_OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user