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:
7
dmx.cpp
7
dmx.cpp
@@ -57,6 +57,7 @@ for (short tch=0; tch<=3 ; tch++)
|
|||||||
|
|
||||||
void DMXUpdate(void)
|
void DMXUpdate(void)
|
||||||
{
|
{
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
int t;
|
int t;
|
||||||
for (short tch=0; tch<=3 ; tch++)
|
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();
|
//Serial.print(D_State,BIN);Serial.println();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ for (short tch=0; tch<=3 ; tch++)
|
|||||||
{
|
{
|
||||||
// CHSV hsv;
|
// CHSV hsv;
|
||||||
// CRGB rgb;
|
// CRGB rgb;
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
|
|
||||||
short t,tch;
|
short t,tch;
|
||||||
//Here code for semi-immediate update
|
//Here code for semi-immediate update
|
||||||
@@ -109,6 +112,7 @@ D_checkT=0;
|
|||||||
DMXput();
|
DMXput();
|
||||||
for (int i=1; i<17; i++) {Serial.print(DMXSerial.read(i));Serial.print(";");}
|
for (int i=1; i<17; i++) {Serial.print(DMXSerial.read(i));Serial.print(";");}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,6 +129,7 @@ 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(__AVR_ATmega2560__)
|
||||||
|
|
||||||
DMXin = new uint8_t [channels];
|
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"));
|
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);
|
||||||
DMXSerial.attachOnUpdate(&DMXUpdate);
|
DMXSerial.attachOnUpdate(&DMXUpdate);
|
||||||
|
#endif
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|||||||
15
dmx.h
15
dmx.h
@@ -29,9 +29,24 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
//#define DMX_OUT_PIN 3
|
//#define DMX_OUT_PIN 3
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
#include <DmxSimple.h>
|
#include <DmxSimple.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__ESP__)
|
||||||
|
#include <ESP-Dmx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include <DmxSimple.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Artnet.h>
|
#include <Artnet.h>
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
#include <DMXSerial.h>
|
#include <DMXSerial.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
extern aJsonObject *dmxArr;
|
extern aJsonObject *dmxArr;
|
||||||
|
|||||||
19
item.cpp
19
item.cpp
@@ -20,7 +20,18 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
#if defined(__AVR__)
|
||||||
#include <DmxSimple.h>
|
#include <DmxSimple.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__ESP__)
|
||||||
|
#include <ESP-Dmx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include <DmxSimple.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
#include <PubSubClient2.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 = 5 ---> PWM frequency is 30 Hz
|
||||||
//prescaler = 6 ---> PWM frequency is <20 Hz
|
//prescaler = 6 ---> PWM frequency is <20 Hz
|
||||||
int tval = 7; // this is 111 in binary and is used as an eraser
|
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
|
TCCR4B &= ~tval; // this operation (AND plus NOT), set the three bits in TCCR2B to 0
|
||||||
TCCR3B &= ~tval;
|
TCCR3B &= ~tval;
|
||||||
tval=2;
|
tval=2;
|
||||||
TCCR4B|=tval;
|
TCCR4B|=tval;
|
||||||
TCCR3B|=tval;
|
TCCR3B|=tval;
|
||||||
|
#endif
|
||||||
if (inverse) k=map(Par[0],100,0,0,255);
|
if (inverse) k=map(Par[0],100,0,0,255);
|
||||||
else k=map(Par[0],0,100,0,255);
|
else k=map(Par[0],0,100,0,255);
|
||||||
analogWrite(iaddr,k);
|
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));
|
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out,"flt", (int) node.getResponseBuffer(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delay(50);
|
||||||
result = node.readHoldingRegisters(20-1, 4);
|
result = node.readHoldingRegisters(20-1, 4);
|
||||||
|
|
||||||
// do something with data if read is successful
|
// do something with data if read is successful
|
||||||
@@ -844,7 +856,8 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
if (modbusBusy) return -1;
|
if (modbusBusy) return -1;
|
||||||
modbusBusy=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;
|
uint8_t result;
|
||||||
|
|
||||||
|
|||||||
35
lighthub.ino
35
lighthub.ino
@@ -62,12 +62,24 @@ dmx relay out
|
|||||||
#include "HTTPClient.h"
|
#include "HTTPClient.h"
|
||||||
#include <Cmd.h>
|
#include <Cmd.h>
|
||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <EEPROM.h>
|
#include <avr/wdt.h>
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include <DueFlashStorage.h>
|
||||||
|
DueFlashStorage EEPROM;
|
||||||
|
#else
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
#include <avr/wdt.h>
|
#include "dmx.h"
|
||||||
|
|
||||||
// Hardcoded definitions
|
// Hardcoded definitions
|
||||||
//Thermostate histeresys
|
//Thermostate histeresys
|
||||||
@@ -302,7 +314,9 @@ break;
|
|||||||
break;
|
break;
|
||||||
case 2: // IP Ready, Connecting & subscribe
|
case 2: // IP Ready, Connecting & subscribe
|
||||||
//Arming Watchdog
|
//Arming Watchdog
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_enable(WDTO_8S);
|
wdt_enable(WDTO_8S);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!client.connected() && mqttArr && (aJson.getArraySize(mqttArr)>1)) {
|
if (!client.connected() && mqttArr && (aJson.getArraySize(mqttArr)>1)) {
|
||||||
char *c=aJson.getArrayItem(mqttArr,1)->valuestring;
|
char *c=aJson.getArrayItem(mqttArr,1)->valuestring;
|
||||||
@@ -354,7 +368,10 @@ break;
|
|||||||
//if (millis()>mtnCnt)
|
//if (millis()>mtnCnt)
|
||||||
{
|
{
|
||||||
//mtnCnt=millis()+2;
|
//mtnCnt=millis()+2;
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (Ethernet.maintain())
|
switch (Ethernet.maintain())
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -390,7 +407,9 @@ switch (Ethernet.maintain())
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_enable(WDTO_8S);
|
wdt_enable(WDTO_8S);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return lanStatus;
|
return lanStatus;
|
||||||
@@ -655,7 +674,7 @@ void _setConfig(int arg_cnt, char **args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printMACAddress();
|
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"));
|
Serial.println(F("Updated"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -773,14 +792,18 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
//commandLine.update();
|
//commandLine.update();
|
||||||
cmdPoll();
|
cmdPoll();
|
||||||
if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();}
|
if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();}
|
||||||
if (owReady && owArr) owLoop();
|
if (owReady && owArr) owLoop();
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
unsigned long lastpacket = DMXSerial.noDataSince();
|
unsigned long lastpacket = DMXSerial.noDataSince();
|
||||||
|
#endif
|
||||||
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
||||||
|
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
@@ -793,8 +816,9 @@ if (owReady && owArr) owLoop();
|
|||||||
// Idle handlers
|
// Idle handlers
|
||||||
void owIdle(void)
|
void owIdle(void)
|
||||||
{ if (artnet) artnet->read();
|
{ if (artnet) artnet->read();
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
#endif
|
||||||
return;///
|
return;///
|
||||||
Serial.print("o");
|
Serial.print("o");
|
||||||
|
|
||||||
@@ -808,8 +832,9 @@ if (lanLoop() == 1) client.loop();
|
|||||||
void modbusIdle(void)
|
void modbusIdle(void)
|
||||||
{
|
{
|
||||||
//Serial.print("m");
|
//Serial.print("m");
|
||||||
|
#if defined(__AVR_ATmega2560__)
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
#endif
|
||||||
if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();}
|
if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();}
|
||||||
//if (owReady) owLoop();
|
//if (owReady) owLoop();
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ e-mail anklimov@gmail.com
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//define APU_OFF
|
//define APU_OFF
|
||||||
#include <OneWire.h>
|
#include <DS2482_OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
owTerm.h
2
owTerm.h
@@ -52,7 +52,7 @@ e-mail anklimov@gmail.com
|
|||||||
#define t_max 20 //Maximum number of 1w devices
|
#define t_max 20 //Maximum number of 1w devices
|
||||||
#define TEMPERATURE_PRECISION 9
|
#define TEMPERATURE_PRECISION 9
|
||||||
|
|
||||||
#include <OneWire.h>
|
#include <DS2482_OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user