mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ab78ab2ae | |||
| 4d909dd449 | |||
|
|
b3db766b1a | ||
| 080cdd4e22 | |||
| 91d5acf619 | |||
| 454b88fbbf | |||
| 6e283e32db | |||
| 18fbc783b5 | |||
|
|
5235bb67c1 | ||
| 9683e51c18 | |||
| fd65c1a3a1 | |||
| 90298cd5a3 | |||
| 5719ba209a | |||
| 2e21362fd8 | |||
| fe054c3c4e | |||
| e3d84a1a02 | |||
| ca457a2a05 | |||
| 6d4f76c642 |
@@ -40,3 +40,4 @@
|
|||||||
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
||||||
-D MERCURY_ENABLE
|
-D MERCURY_ENABLE
|
||||||
#-D IPMODBUS
|
#-D IPMODBUS
|
||||||
|
-D CONFIG_CLEAN_PIN=2
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
-DAC_DISABLE
|
-DAC_DISABLE
|
||||||
-DSYSLOG_ENABLE
|
-DSYSLOG_ENABLE
|
||||||
-DPID_DISABLE
|
-DPID_DISABLE
|
||||||
-DWiz5100
|
#-DWiz5100
|
||||||
-DMOTOR_DISABLE
|
-DMOTOR_DISABLE
|
||||||
-DOTA
|
-DOTA
|
||||||
-DARDUINO_OTA_MDNS_DISABLE
|
-DARDUINO_OTA_MDNS_DISABLE
|
||||||
@@ -27,4 +27,4 @@
|
|||||||
-DPID_DISABLE
|
-DPID_DISABLE
|
||||||
-DPWM_DISABLE
|
-DPWM_DISABLE
|
||||||
-DSPILED_DISABLE
|
-DSPILED_DISABLE
|
||||||
-DOW_DEVICES_LIMIT=17
|
#-DOW_DEVICES_LIMIT=17
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,3 @@
|
|||||||
export PORT=cu.usbmodem14101
|
export PORT=cu.usbmodem141101
|
||||||
echo . | stty -f /dev/$PORT speed 1200
|
echo . | stty -f /dev/$PORT speed 1200
|
||||||
../tools/mac/tool-bossac/bossac -U false -p $PORT -i -e -w -v -b firmware.bin -R
|
../tools/mac/tool-bossac/bossac -U false -p $PORT -i -w -v -b firmware.bin -R
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
compiled/mega2560slim/firmware.bin
Executable file
BIN
compiled/mega2560slim/firmware.bin
Executable file
Binary file not shown.
7124
compiled/mega2560slim/firmware.hex
Normal file
7124
compiled/mega2560slim/firmware.hex
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
0
compiled/tools/arduinoOTA
Normal file → Executable file
0
compiled/tools/arduinoOTA
Normal file → Executable file
@@ -1,8 +1,8 @@
|
|||||||
copy ..\.pio\build\due\firmware.bin due
|
copy ..\.pio\build\due\firmware.bin due
|
||||||
copy ..\.pio\build\controllino\firmware.hex controllino
|
copy ..\.pio\build\controllino\firmware.hex controllino
|
||||||
copy ..\.pio\build\m5stack\firmware.bin m5stack
|
copy ..\.pio\build\m5stack\firmware.bin m5stack
|
||||||
copy ..\.pio\build\mega2560slim-5100\firmware.hex mega2560slim-5100
|
copy ..\.pio\build\mega2560slim\firmware.hex mega2560slim
|
||||||
copy ..\.pio\build\mega2560slim-5100\firmware.bin mega2560slim-5100
|
copy ..\.pio\build\mega2560slim\firmware.bin mega2560slim
|
||||||
copy ..\.pio\build\mega2560slim2\firmware.hex mega2560slim2
|
copy ..\.pio\build\mega2560slim2\firmware.hex mega2560slim2
|
||||||
copy ..\.pio\build\mega2560slim2\firmware.bin mega2560slim2
|
copy ..\.pio\build\mega2560slim2\firmware.bin mega2560slim2
|
||||||
copy ..\.pio\build\due-5100\firmware.bin due-5100
|
copy ..\.pio\build\due-5100\firmware.bin due-5100
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
cp ../.pio/build/due/firmware.bin due
|
cp ../.pio/build/due/firmware.bin due
|
||||||
cp ../.pio/build/controllino/firmware.hex controllino
|
cp ../.pio/build/controllino/firmware.hex controllino
|
||||||
cp ../.pio/build/m5stack/firmware.bin m5stack
|
cp ../.pio/build/m5stack/firmware.bin m5stack
|
||||||
cp ../.pio/build/mega2560slim-5100/firmware.hex mega2560slim-5100
|
cp ../.pio/build/mega2560slim/firmware.hex mega2560slim
|
||||||
cp ../.pio/build/mega2560slim-5100/firmware.bin mega2560slim-5100
|
cp ../.pio/build/mega2560slim/firmware.bin mega2560slim
|
||||||
cp ../.pio/build/mega2560-optiboot/firmware.hex mega2560-optiboot
|
cp ../.pio/build/mega2560-optiboot/firmware.hex mega2560-optiboot
|
||||||
cp ../.pio/build/mega2560-optiboot/firmware.bin mega2560-optiboot
|
cp ../.pio/build/mega2560-optiboot/firmware.bin mega2560-optiboot
|
||||||
cp ../.pio/build/mega2560-5100/firmware.hex mega2560-5100
|
cp ../.pio/build/mega2560-5100/firmware.hex mega2560-5100
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define CST_UNKNOWN 0
|
#define CST_UNKNOWN 0
|
||||||
#define CST_INITIALIZED 1
|
#define CST_FAILED 1
|
||||||
#define CST_FAILED -1
|
#define CST_INITIALIZED 2
|
||||||
|
#define CST_USER 3
|
||||||
|
|
||||||
class abstractCh {
|
class abstractCh {
|
||||||
public:
|
public:
|
||||||
@@ -11,9 +12,10 @@ public:
|
|||||||
virtual ~abstractCh(){};
|
virtual ~abstractCh(){};
|
||||||
virtual int Poll(short cause) {return 0;}
|
virtual int Poll(short cause) {return 0;}
|
||||||
virtual int Setup() =0; //Should initialize hardware and reserve resources
|
virtual int Setup() =0; //Should initialize hardware and reserve resources
|
||||||
virtual int Anounce () {return 0;};
|
// virtual int Anounce () {return 0;};
|
||||||
virtual int Stop() {return 0;}; //Should free resources
|
virtual int Stop() {return 0;}; //Should free resources
|
||||||
virtual int Status() {return CST_UNKNOWN;}
|
virtual int Status() {return CST_UNKNOWN;}
|
||||||
|
virtual void setStatus(uint8_t status) {}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "abstractout.h"
|
#include "abstractout.h"
|
||||||
#include "itemCmd.h"
|
#include "itemCmd.h"
|
||||||
@@ -25,3 +26,15 @@ int abstractOut::Setup()
|
|||||||
if (item && (item->getCmd()==-1)) item->setCmd(CMD_OFF);
|
if (item && (item->getCmd()==-1)) item->setCmd(CMD_OFF);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int abstractOut::Status()
|
||||||
|
{
|
||||||
|
if (item && item->itemArr)
|
||||||
|
return item->itemArr->subtype;
|
||||||
|
return CST_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void abstractOut::setStatus(uint8_t status)
|
||||||
|
{
|
||||||
|
if (item && item->itemArr) item->itemArr->subtype = status & 0xF;
|
||||||
|
}
|
||||||
@@ -13,7 +13,9 @@ public:
|
|||||||
virtual bool isAllowed(itemCmd cmd){return true;};
|
virtual bool isAllowed(itemCmd cmd){return true;};
|
||||||
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};
|
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};
|
||||||
virtual int getChanType(){return 0;}
|
virtual int getChanType(){return 0;}
|
||||||
virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead
|
// virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead
|
||||||
|
virtual int Status() override;
|
||||||
|
virtual void setStatus(uint8_t status) override;
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
protected:
|
protected:
|
||||||
Item * item;
|
Item * item;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ short colorChannel::getChannelAddr(short n)
|
|||||||
return item->getArg(n);
|
return item->getArg(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int colorChannel::getDefaultStorageType()
|
int colorChannel::getDefaultStorageType()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ int colorChannel::getDefaultStorageType()
|
|||||||
return ST_VOID;
|
return ST_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int colorChannel::isActive()
|
int colorChannel::isActive()
|
||||||
{
|
{
|
||||||
itemCmd st;
|
itemCmd st;
|
||||||
@@ -58,7 +58,6 @@ case S_NOTFOUND:
|
|||||||
// turn on and set
|
// turn on and set
|
||||||
toExecute = true;
|
toExecute = true;
|
||||||
case S_SET:
|
case S_SET:
|
||||||
//case S_ESET:
|
|
||||||
case S_HSV:
|
case S_HSV:
|
||||||
PixelCtrl(cmd, subItem, toExecute, authorized);
|
PixelCtrl(cmd, subItem, toExecute, authorized);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public:
|
|||||||
numArgs = item->getArgCount(); // and how many addresses is configured
|
numArgs = item->getArgCount(); // and how many addresses is configured
|
||||||
};
|
};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override;
|
||||||
int getDefaultStorageType()override;
|
//int getDefaultStorageType()override;
|
||||||
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0;
|
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0;
|
||||||
short getChannelAddr(short n =0);
|
short getChannelAddr(short n =0);
|
||||||
// int isActive() override;
|
// int isActive() override;
|
||||||
|
|||||||
169
lighthub/dmx.cpp
169
lighthub/dmx.cpp
@@ -47,6 +47,7 @@ volatile uint32_t checkTimestamp=0L;
|
|||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
volatile uint32_t D_State=0;
|
volatile uint32_t D_State=0;
|
||||||
volatile unsigned long D_checkT=0;
|
volatile unsigned long D_checkT=0;
|
||||||
|
uint8_t DMXINChannels=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
@@ -61,6 +62,61 @@ extern aJsonObject *items;
|
|||||||
extern aJsonObject *dmxArr;
|
extern aJsonObject *dmxArr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
itemCmd rgb2hsv(itemCmd in)
|
||||||
|
{
|
||||||
|
itemCmd out;
|
||||||
|
out.setArgType(ST_HSV255);
|
||||||
|
|
||||||
|
double min, max, delta;
|
||||||
|
|
||||||
|
double inr=in.param.r/255;
|
||||||
|
double ing=in.param.g/255;
|
||||||
|
double inb=in.param.b/255;
|
||||||
|
double inw=in.param.w/255;
|
||||||
|
|
||||||
|
min = inr < ing ? inr : ing;
|
||||||
|
min = min < inb ? min : inb;
|
||||||
|
|
||||||
|
max = inr > ing ? inr : ing;
|
||||||
|
max = max > inb ? max : inb;
|
||||||
|
max = max > inw ? max : inw;
|
||||||
|
|
||||||
|
out.param.v = max*255; // v
|
||||||
|
delta = max - min;
|
||||||
|
if (delta < 0.00001)
|
||||||
|
{
|
||||||
|
out.param.s = 0;
|
||||||
|
out.param.h = 0; // undefined, maybe nan?
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
if( max > 0.0 ) { // NOTE: if Max is == 0, this divide would cause a crash
|
||||||
|
out.param.s = (delta / max)*100; // s
|
||||||
|
} else {
|
||||||
|
// if max is 0, then r = g = b = 0
|
||||||
|
// s = 0, h is undefined
|
||||||
|
out.param.s = 0;
|
||||||
|
out.param.h = 0; // its now undefined
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
double outh;
|
||||||
|
if( inr >= max ) // > is bogus, just keeps compilor happy
|
||||||
|
outh = ( ing - inb ) / delta; // between yellow & magenta
|
||||||
|
else
|
||||||
|
if( ing >= max )
|
||||||
|
outh = 2.0 + ( inb - inr ) / delta; // between cyan & yellow
|
||||||
|
else
|
||||||
|
outh = 4.0 + ( inr - ing ) / delta; // between magenta & cyan
|
||||||
|
|
||||||
|
outh *= 60.0; // degrees
|
||||||
|
|
||||||
|
if( outh < 0.0 )
|
||||||
|
outh += 360.0;
|
||||||
|
out.param.h=outh;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int itemCtrl2(char* name,int r,int g, int b, int w)
|
int itemCtrl2(char* name,int r,int g, int b, int w)
|
||||||
{
|
{
|
||||||
if (!items) return 0;
|
if (!items) return 0;
|
||||||
@@ -68,7 +124,6 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
|
|
||||||
if (itemArr && (itemArr->type==aJson_Array))
|
if (itemArr && (itemArr->type==aJson_Array))
|
||||||
{
|
{
|
||||||
|
|
||||||
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
||||||
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
||||||
switch (itemtype){
|
switch (itemtype){
|
||||||
@@ -84,7 +139,6 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
|
|
||||||
case CH_RGB: // RGB
|
case CH_RGB: // RGB
|
||||||
{
|
{
|
||||||
|
|
||||||
DmxWrite(itemaddr, r);
|
DmxWrite(itemaddr, r);
|
||||||
DmxWrite(itemaddr+1, g);
|
DmxWrite(itemaddr+1, g);
|
||||||
DmxWrite(itemaddr+2, b);
|
DmxWrite(itemaddr+2, b);
|
||||||
@@ -96,7 +150,7 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
if (groupArr && (groupArr->type==aJson_Array))
|
if (groupArr && (groupArr->type==aJson_Array))
|
||||||
{ aJsonObject *i =groupArr->child;
|
{ aJsonObject *i =groupArr->child;
|
||||||
while (i)
|
while (i)
|
||||||
{ //Serial.println(i->valuestring);
|
{
|
||||||
if (i->type == aJson_String) itemCtrl2(i->valuestring,r,g,b,w);
|
if (i->type == aJson_String) itemCtrl2(i->valuestring,r,g,b,w);
|
||||||
i=i->next;}
|
i=i->next;}
|
||||||
}
|
}
|
||||||
@@ -119,9 +173,34 @@ void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXSemiImmediateUpdate(short tch,short trh, int val)
|
void DMXSemiImmediateUpdate(short tch,short r, short g, short b, short w)
|
||||||
{
|
{
|
||||||
//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
|
||||||
|
if (dmxArr && (dmxArr->type==aJson_Array))
|
||||||
|
|
||||||
|
{
|
||||||
|
aJsonObject *DMXch = aJson.getArrayItem(dmxArr,tch);
|
||||||
|
char* itemname = NULL;
|
||||||
|
if (DMXch->type == aJson_String) itemname=DMXch->valuestring;
|
||||||
|
if (itemname)
|
||||||
|
{
|
||||||
|
Item it(itemname);
|
||||||
|
if (!r && !g && !b && !w) it.Ctrl(itemCmd().Cmd(CMD_OFF).setSuffix(S_CMD));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
CRGB rgb;
|
||||||
|
rgb.r = r;
|
||||||
|
rgb.g = g;
|
||||||
|
rgb.b = b;
|
||||||
|
CHSV hsv = rgb2hsv_approximate(rgb);
|
||||||
|
it.Ctrl(itemCmd().HSV255(hsv.h,hsv.s,hsv.v).setSuffix(S_SET)); */
|
||||||
|
it.Ctrl(itemCmd().RGBW(r,g,b,w).setSuffix(S_SET));
|
||||||
|
//it.Ctrl(rgb2hsv(itemCmd().RGBW(r,g,b,w)).setSuffix(S_SET));
|
||||||
|
it.Ctrl(itemCmd().Cmd(CMD_ON).setSuffix(S_CMD));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXput(void)
|
void DMXput(void)
|
||||||
@@ -132,6 +211,7 @@ 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]);
|
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern volatile uint8_t timerHandlerBusy;
|
extern volatile uint8_t timerHandlerBusy;
|
||||||
@@ -140,81 +220,62 @@ extern volatile uint8_t timerHandlerBusy;
|
|||||||
volatile int DMXinDoublecheck=0;
|
volatile int DMXinDoublecheck=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// INVOKED BY INTERRUPTS - MUST BE SAFE CODE
|
||||||
void DMXUpdate(void)
|
void DMXUpdate(void)
|
||||||
{
|
{
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
int t;
|
|
||||||
if(!DMXin) return;
|
if(!DMXin) return;
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
if (dmxin.getRxLength()<16) return;
|
if (dmxin.getRxLength()<DMXINChannels) return;
|
||||||
#endif
|
#endif
|
||||||
for (short tch=0; tch<=3 ; tch++)
|
|
||||||
|
uint8_t RGBWChannels=DMXINChannels >> 2;
|
||||||
|
for (short tch=0; tch<RGBWChannels ; tch++)
|
||||||
{
|
{
|
||||||
short base = tch*4;
|
short base = tch*4;
|
||||||
bool updated = 0;
|
bool updated = false;
|
||||||
bool confirmed = 0;
|
int t;
|
||||||
|
|
||||||
for (short trh=0; trh<4 ; trh++)
|
for (short trh=0; trh<4 ; trh++)
|
||||||
if (((t=dmxin.read(base+trh+1)) != DMXin[base+trh]))
|
if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh])
|
||||||
{
|
{
|
||||||
|
D_State |= (1<<tch);
|
||||||
updated=1;
|
updated=1;
|
||||||
if (DMXinDoublecheck>2)
|
DMXin[base+trh]=t;
|
||||||
{
|
|
||||||
D_State |= (1<<tch);
|
|
||||||
DMXin[base+trh]=t;
|
|
||||||
confirmed = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (updated)
|
||||||
if (updated) DMXinDoublecheck++; else DMXinDoublecheck=0;
|
|
||||||
|
|
||||||
|
|
||||||
if (confirmed)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||||
//for (int i=1; i<17; i++) {debugSerial.print(dmxin.read(i));debugSerial.print("-");};debugSerial.print("|");
|
|
||||||
D_checkT=millisNZ();
|
D_checkT=millisNZ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Serial.print(D_State,BIN);Serial.println();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// INVOKED in safe loop
|
||||||
void DMXCheck(void)
|
void DMXCheck(void)
|
||||||
{
|
{
|
||||||
// CHSV hsv;
|
|
||||||
// CRGB rgb;
|
|
||||||
DMXOUT_propagate();
|
DMXOUT_propagate();
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
|
if ( (!D_checkT) || (!isTimeOver(D_checkT,millis(),D_CHECKT))) return;
|
||||||
short t,tch;
|
|
||||||
//Here code for semi-immediate update
|
|
||||||
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++)
|
|
||||||
DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//if ((millis()<D_checkT) || (D_checkT==0)) return;
|
|
||||||
if ( (!D_checkT) || (!isTimeOver(D_checkT,millis(),D_CHECKT))) return;
|
|
||||||
D_checkT=0;
|
D_checkT=0;
|
||||||
|
uint8_t RGBWChannels=DMXINChannels >> 2;
|
||||||
|
for (short rgbwChan=0; rgbwChan < RGBWChannels; rgbwChan++)
|
||||||
|
{
|
||||||
|
short base = rgbwChan*4;
|
||||||
|
short bitMask = 1 << rgbwChan;
|
||||||
|
if (D_State & bitMask)
|
||||||
|
{
|
||||||
|
D_State &= ~bitMask;
|
||||||
|
DMXSemiImmediateUpdate(rgbwChan,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Here code for network update
|
//#ifdef _dmxout
|
||||||
//int ch = 0;
|
//for (int i=1; i<17; i++) {debugSerial.print(dmxin.read(i));debugSerial.print(";");}
|
||||||
|
//debugSerial.println();
|
||||||
DMXput();
|
//#endif
|
||||||
|
|
||||||
#ifdef _dmxout
|
|
||||||
for (int i=1; i<17; i++) {debugSerial.print(dmxin.read(i));debugSerial.print(";");}
|
|
||||||
debugSerial.println();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -238,7 +299,9 @@ void DMXinSetup(int channels)
|
|||||||
//DmxSimple.maxChannel(channels);
|
//DmxSimple.maxChannel(channels);
|
||||||
|
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
|
if (channels>(32*4)) channels = 32*4;
|
||||||
DMXin = new uint8_t [channels];
|
DMXin = new uint8_t [channels];
|
||||||
|
DMXINChannels=channels;
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
DMXSerial.init(DMXReceiver,0,channels);
|
DMXSerial.init(DMXReceiver,0,channels);
|
||||||
if (DMXSerial.getBuffer()) {debugSerial.print(F("Init in ch:"));debugSerial.println(channels);} else debugSerial.println(F("DMXin Buffer alloc err"));
|
if (DMXSerial.getBuffer()) {debugSerial.print(F("Init in ch:"));debugSerial.println(channels);} else debugSerial.println(F("DMXin Buffer alloc err"));
|
||||||
|
|||||||
@@ -104,8 +104,15 @@ int subitem2cmd(char *payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int txt2subItem(char *payload) {
|
int txt2subItem(char *payload) {
|
||||||
int cmd = S_NOTFOUND;
|
|
||||||
if (!payload || !strlen(payload)) return S_NOTFOUND;
|
if (!payload || !strlen(payload)) return S_NOTFOUND;
|
||||||
|
for(uint8_t i=1; i<suffixNum ;i++)
|
||||||
|
if (strcmp_P(payload, suffix_P[i]) == 0)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return S_NOTFOUND;
|
||||||
|
/*
|
||||||
|
int cmd = S_NOTFOUND;
|
||||||
// Check for command
|
// Check for command
|
||||||
if (strcmp_P(payload, SET_P) == 0) cmd = S_SET;
|
if (strcmp_P(payload, SET_P) == 0) cmd = S_SET;
|
||||||
else if (strcmp_P(payload, CTRL_P) == 0) cmd = S_CTRL;
|
else if (strcmp_P(payload, CTRL_P) == 0) cmd = S_CTRL;
|
||||||
@@ -120,7 +127,8 @@ int txt2subItem(char *payload) {
|
|||||||
else if (strcmp_P(payload, VAL_P) == 0) cmd = S_VAL;
|
else if (strcmp_P(payload, VAL_P) == 0) cmd = S_VAL;
|
||||||
else if (strcmp_P(payload, DEL_P) == 0) cmd = S_DELAYED;
|
else if (strcmp_P(payload, DEL_P) == 0) cmd = S_DELAYED;
|
||||||
else if (strcmp_P(payload, _RAW_P) == 0) cmd = S_RAW;
|
else if (strcmp_P(payload, _RAW_P) == 0) cmd = S_RAW;
|
||||||
return cmd;
|
return cmd; */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//const short defval[4] = {0, 0, 0, 0}; //Type,Arg,Val,Cmd
|
//const short defval[4] = {0, 0, 0, 0}; //Type,Arg,Val,Cmd
|
||||||
@@ -487,7 +495,7 @@ void Item::setExt(long int par) // Only store if VAL is int (autogenerated or c
|
|||||||
if(itemExt->type == aJson_NULL) itemExt->type=aJson_Int;
|
if(itemExt->type == aJson_NULL) itemExt->type=aJson_Int;
|
||||||
else if(itemExt->type != aJson_Int ) return;
|
else if(itemExt->type != aJson_Int ) return;
|
||||||
itemExt->valueint = par;
|
itemExt->valueint = par;
|
||||||
debugSerial<<F("Stored EXT:")<<par<<endl;
|
//debugSerial<<F("Stored EXT:")<<par<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -908,6 +916,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
uint16_t status2Send = 0;
|
uint16_t status2Send = 0;
|
||||||
uint8_t command2Set = 0;
|
uint8_t command2Set = 0;
|
||||||
|
itemCmd originalCmd = cmd;
|
||||||
|
|
||||||
/// Common (GRP & NO GRP) commands
|
/// Common (GRP & NO GRP) commands
|
||||||
switch (cmd.getCmd())
|
switch (cmd.getCmd())
|
||||||
@@ -1063,7 +1072,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
|
|
||||||
if ((suffixCode==S_CMD) && cmd.isValue())
|
if ((suffixCode==S_CMD) && cmd.isValue())
|
||||||
{
|
{
|
||||||
scheduleOppositeCommand(cmd,chActive,authorized);
|
scheduleOppositeCommand(originalCmd,chActive,authorized);
|
||||||
scheduledOppositeCommand = true;
|
scheduledOppositeCommand = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1372,7 +1381,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
|
|||||||
|
|
||||||
if (oppositeCommandToBeSchedulled) //invoked not as group part, delayed
|
if (oppositeCommandToBeSchedulled) //invoked not as group part, delayed
|
||||||
{
|
{
|
||||||
scheduleOppositeCommand(cmd,chActive,authorized);
|
scheduleOppositeCommand(originalCmd,chActive,authorized);
|
||||||
status2Send &=~FLAG_PARAMETERS;
|
status2Send &=~FLAG_PARAMETERS;
|
||||||
}
|
}
|
||||||
} // NO GROUP
|
} // NO GROUP
|
||||||
@@ -1464,7 +1473,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
if (!tStore.timestamp16) mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
if (!tStore.timestamp16) mqttClient.publish("/alarmoff/snsr", itemArr->name);
|
||||||
tStore.tempX100=cmd.getFloat()*100.; //Save measurement
|
tStore.tempX100=cmd.getFloat()*100.; //Save measurement
|
||||||
tStore.timestamp16=millisNZ(8) & 0xFFFF; //And timestamp
|
tStore.timestamp16=millisNZ(8) & 0xFFFF; //And timestamp
|
||||||
debugSerial<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
//debugSerial<<F(" T:")<<tStore.tempX100<<F(" TS:")<<tStore.timestamp16<<endl;
|
||||||
setExt(tStore.asint);
|
setExt(tStore.asint);
|
||||||
res=1;
|
res=1;
|
||||||
}
|
}
|
||||||
@@ -1801,9 +1810,14 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
|
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
|
|
||||||
|
// if (sendFlags & FLAG_SEND_DELAYED)
|
||||||
|
// strncat_P(addrstr, DEL_P, sizeof(addrstr)-1);
|
||||||
|
// else strncat_P(addrstr, SET_P, sizeof(addrstr)-1);
|
||||||
|
|
||||||
if (sendFlags & FLAG_SEND_DELAYED)
|
if (sendFlags & FLAG_SEND_DELAYED)
|
||||||
strncat_P(addrstr, DEL_P, sizeof(addrstr)-1);
|
strncat_P(addrstr, suffix_P[S_DELAYED], sizeof(addrstr)-1);
|
||||||
else strncat_P(addrstr, SET_P, sizeof(addrstr)-1);
|
else strncat_P(addrstr, suffix_P[S_SET], sizeof(addrstr)-1);
|
||||||
|
|
||||||
|
|
||||||
// Preparing parameters payload //////////
|
// Preparing parameters payload //////////
|
||||||
switch (st.getArgType()) {
|
switch (st.getArgType()) {
|
||||||
@@ -1872,7 +1886,8 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
||||||
}
|
}
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
strncat_P(addrstr, CMD_P, sizeof(addrstr)-1);
|
// strncat_P(addrstr, CMD_P, sizeof(addrstr)-1);
|
||||||
|
strncat_P(addrstr, suffix_P[S_CMD], sizeof(addrstr)-1);
|
||||||
|
|
||||||
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
@@ -1909,7 +1924,8 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
strncat(addrstr, subItem, sizeof(addrstr)-1);
|
||||||
}
|
}
|
||||||
strncat(addrstr, "/", sizeof(addrstr)-1);
|
strncat(addrstr, "/", sizeof(addrstr)-1);
|
||||||
strncat_P(addrstr, CTRL_P, sizeof(addrstr)-1);
|
//strncat_P(addrstr, CTRL_P, sizeof(addrstr)-1);
|
||||||
|
strncat_P(addrstr, suffix_P[S_CTRL], sizeof(addrstr)-1);
|
||||||
|
|
||||||
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
@@ -1936,7 +1952,7 @@ return itemType;
|
|||||||
|
|
||||||
// Setup FLAG_SEND_RETRY flag to repeat unsucsessfull modbus tranzaction after release line
|
// Setup FLAG_SEND_RETRY flag to repeat unsucsessfull modbus tranzaction after release line
|
||||||
void Item::mb_fail(int result) {
|
void Item::mb_fail(int result) {
|
||||||
debugSerial<<F("Modbus op failed:")<<_HEX(result)<<endl;
|
debugSerial<<F("Modbus op ")<<itemArr->name<<F(" failed:")<<_HEX(result)<<endl;
|
||||||
setFlag(FLAG_SEND_RETRY);
|
setFlag(FLAG_SEND_RETRY);
|
||||||
// isPendedModbusWrites=true;
|
// isPendedModbusWrites=true;
|
||||||
}
|
}
|
||||||
@@ -2006,38 +2022,6 @@ int Item::checkRetry() {
|
|||||||
return M_CLEAN;
|
return M_CLEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool Item::resumeModbus()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (modbusBusy) return false;
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
//debugSerial<<F("Pushing MB: ");
|
|
||||||
configLocked++;
|
|
||||||
if (items) {
|
|
||||||
aJsonObject * item = items->child;
|
|
||||||
while (items && item)
|
|
||||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
|
||||||
Item it(item);
|
|
||||||
if (it.isValid()) {
|
|
||||||
|
|
||||||
short res = it.checkModbusRetry();
|
|
||||||
if (res<=0) success = false;
|
|
||||||
|
|
||||||
} //isValid
|
|
||||||
yield();
|
|
||||||
item = item->next;
|
|
||||||
} //if
|
|
||||||
debugSerial<<endl;
|
|
||||||
}
|
|
||||||
configLocked--;
|
|
||||||
if (success) isPendedModbusWrites=false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
||||||
|
|
||||||
|
|
||||||
@@ -2132,7 +2116,7 @@ int Item::VacomSetFan(itemCmd st) {
|
|||||||
}
|
}
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
int addr = getArg();
|
int addr = getArg();
|
||||||
debugSerial<<F("VC#")<<addr<<F("=")<<val<<endl;
|
debugSerial<<F("MB: VC#")<<addr<<F("=")<<val<<endl;
|
||||||
if (modbusBusy) {
|
if (modbusBusy) {
|
||||||
// setCmd(cmd);
|
// setCmd(cmd);
|
||||||
// setVal(val);
|
// setVal(val);
|
||||||
@@ -2152,7 +2136,7 @@ int Item::VacomSetFan(itemCmd st) {
|
|||||||
//node.writeSingleRegister(2001-1,1);
|
//node.writeSingleRegister(2001-1,1);
|
||||||
} else result=node.writeSingleRegister(2001 - 1, 0);
|
} else result=node.writeSingleRegister(2001 - 1, 0);
|
||||||
delay(100);
|
delay(100);
|
||||||
if (result == node.ku8MBSuccess) debugSerial << F("MB ok")<<endl;
|
if (result == node.ku8MBSuccess) debugSerial << F("MB: ok")<<endl;
|
||||||
result = node.writeSingleRegister(2003 - 1, val * 100);
|
result = node.writeSingleRegister(2003 - 1, val * 100);
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
//resumeModbus();
|
//resumeModbus();
|
||||||
@@ -2165,7 +2149,7 @@ int Item::VacomSetFan(itemCmd st) {
|
|||||||
#define a 0.1842f
|
#define a 0.1842f
|
||||||
#define b -36.68f
|
#define b -36.68f
|
||||||
|
|
||||||
///move to float todo
|
|
||||||
int Item::VacomSetHeat(itemCmd st)
|
int Item::VacomSetHeat(itemCmd st)
|
||||||
{
|
{
|
||||||
float val=st.getFloat();
|
float val=st.getFloat();
|
||||||
@@ -2176,10 +2160,13 @@ int addr;
|
|||||||
if (itemArg->type != aJson_String) return 0;
|
if (itemArg->type != aJson_String) return 0;
|
||||||
|
|
||||||
Item it(itemArg->valuestring);
|
Item it(itemArg->valuestring);
|
||||||
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
if (it.isValid() && it.itemType == CH_VC)
|
||||||
|
{
|
||||||
|
addr=it.getArg();
|
||||||
|
}
|
||||||
else return 0;
|
else return 0;
|
||||||
|
|
||||||
debugSerial<<F("VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
debugSerial<<F("MB: VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||||
if (modbusBusy) {
|
if (modbusBusy) {
|
||||||
//setCmd(cmd);
|
//setCmd(cmd);
|
||||||
//setVal(val);
|
//setVal(val);
|
||||||
@@ -2197,17 +2184,18 @@ int addr;
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
|
case CMD_FAN:
|
||||||
regval = 0;
|
regval = 0;
|
||||||
|
it.itemArr->subtype = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
it.itemArr->subtype = 1;
|
||||||
regval = round(( val - b) * 10 / a);
|
regval = round(( val - b) * 10 / a);
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugSerial<<regval);
|
|
||||||
result=node.writeSingleRegister(2004 - 1, regval);
|
result=node.writeSingleRegister(2004 - 1, regval);
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
//resumeModbus();
|
|
||||||
if (result == node.ku8MBSuccess) return 1;
|
if (result == node.ku8MBSuccess) return 1;
|
||||||
mb_fail(result);
|
mb_fail(result);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2219,7 +2207,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
|||||||
if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) {
|
if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
debugSerial<<F("MB: Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
||||||
if (modbusBusy) {
|
if (modbusBusy) {
|
||||||
mb_fail();
|
mb_fail();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2251,7 +2239,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
debugSerial<<F("Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
|
||||||
switch (_regType) {
|
switch (_regType) {
|
||||||
case MODBUS_HOLDING_REG_TYPE:
|
case MODBUS_HOLDING_REG_TYPE:
|
||||||
result = node.writeSingleRegister(_reg, value);
|
result = node.writeSingleRegister(_reg, value);
|
||||||
@@ -2260,7 +2248,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
|||||||
result = node.writeSingleCoil(_reg, value);
|
result = node.writeSingleCoil(_reg, value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugSerial<<F("Not supported reg type\n");
|
debugSerial<<F("MB: Not supported reg type\n");
|
||||||
}
|
}
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
//resumeModbus();
|
//resumeModbus();
|
||||||
@@ -2297,12 +2285,13 @@ int Item::checkFM() {
|
|||||||
modbusSerial.begin(MODBUS_FM_BAUD, MODBUS_FM_PARAM);
|
modbusSerial.begin(MODBUS_FM_BAUD, MODBUS_FM_PARAM);
|
||||||
node.begin(getArg(), modbusSerial);
|
node.begin(getArg(), modbusSerial);
|
||||||
|
|
||||||
|
debugSerial << F("MB: polling FM ") << itemArr->name<< endl;
|
||||||
|
delay(50);
|
||||||
result = node.readHoldingRegisters(2101 - 1, 10);
|
result = node.readHoldingRegisters(2101 - 1, 10);
|
||||||
|
|
||||||
// do something with data if read is successful
|
// do something with data if read is successful
|
||||||
if (result == node.ku8MBSuccess) {
|
if (result == node.ku8MBSuccess) {
|
||||||
debugSerial<<F(" FM Val :");
|
debugSerial<<F("MB: FM Val :");
|
||||||
for (j = 0; j < 10; j++) {
|
for (j = 0; j < 10; j++) {
|
||||||
data = node.getResponseBuffer(j);
|
data = node.getResponseBuffer(j);
|
||||||
debugSerial<<_HEX(data)<<F("-");
|
debugSerial<<_HEX(data)<<F("-");
|
||||||
@@ -2330,10 +2319,12 @@ int Item::checkFM() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||||
|
|
||||||
if (node.getResponseBuffer(0) & 8) //Active fault
|
if (node.getResponseBuffer(0) & 8) //Active fault
|
||||||
{
|
{
|
||||||
|
debugSerial << F("MB: polling FM fault ") << itemArr->name<< endl;
|
||||||
|
delay(50);
|
||||||
result = node.readHoldingRegisters(2111 - 1, 1);
|
result = node.readHoldingRegisters(2111 - 1, 1);
|
||||||
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (long int) node.getResponseBuffer(0));
|
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (long int) node.getResponseBuffer(0));
|
||||||
modbusBusy=0;
|
modbusBusy=0;
|
||||||
@@ -2343,12 +2334,13 @@ int Item::checkFM() {
|
|||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
} else aJson.addNumberToObject(out, "flt", (long int)0);
|
} else aJson.addNumberToObject(out, "flt", (long int)0);
|
||||||
|
|
||||||
|
debugSerial << F("MB: polling PI ") << itemArr->name<< endl;
|
||||||
delay(50);
|
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
|
||||||
if (result == node.ku8MBSuccess) {
|
if (result == node.ku8MBSuccess) {
|
||||||
debugSerial << F(" PI Val :");
|
debugSerial << F("MB: PI Val :");
|
||||||
for (j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
data = node.getResponseBuffer(j);
|
data = node.getResponseBuffer(j);
|
||||||
debugSerial << data << F("-");
|
debugSerial << data << F("-");
|
||||||
@@ -2371,7 +2363,8 @@ int Item::checkFM() {
|
|||||||
Off(); //Shut down
|
Off(); //Shut down
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
debugSerial << F("Modbus polling error=") << _HEX(result);
|
debugSerial << F("MB: polling PI ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||||
|
|
||||||
outch = aJson.print(out);
|
outch = aJson.print(out);
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
mqttClient.publish(addrstr, outch);
|
mqttClient.publish(addrstr, outch);
|
||||||
@@ -2388,7 +2381,7 @@ int Item::checkModbusDimmer() {
|
|||||||
|
|
||||||
short numpar = 0;
|
short numpar = 0;
|
||||||
if ((itemArg->type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) {
|
if ((itemArg->type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) {
|
||||||
debugSerial<<F("Illegal arguments\n");
|
debugSerial<<F("MB: Illegal arguments\n");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2400,14 +2393,6 @@ int Item::checkModbusDimmer() {
|
|||||||
uint16_t reg = getArg(MODBUS_CMD_ARG_REG);
|
uint16_t reg = getArg(MODBUS_CMD_ARG_REG);
|
||||||
int _regType = MODBUS_HOLDING_REG_TYPE;
|
int _regType = MODBUS_HOLDING_REG_TYPE;
|
||||||
if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint;
|
if (numpar >= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint;
|
||||||
// short mask = getArg(2);
|
|
||||||
// debugSerial<<F("Modbus polling "));
|
|
||||||
// debugSerial<<addr);
|
|
||||||
// debugSerial<<F("=>"));
|
|
||||||
// debugSerial<<reg, HEX);
|
|
||||||
// debugSerial<<F("(T:"));
|
|
||||||
// debugSerial<<_regType);
|
|
||||||
// debugSerial<<F(")"));
|
|
||||||
|
|
||||||
int data;
|
int data;
|
||||||
|
|
||||||
@@ -2415,7 +2400,7 @@ int Item::checkModbusDimmer() {
|
|||||||
|
|
||||||
modbusSerial.begin(MODBUS_SERIAL_BAUD, MODBUS_SERIAL_PARAM);
|
modbusSerial.begin(MODBUS_SERIAL_BAUD, MODBUS_SERIAL_PARAM);
|
||||||
node.begin(addr, modbusSerial);
|
node.begin(addr, modbusSerial);
|
||||||
|
debugSerial << F("MB: polling dimmer ") << itemArr->name<< endl;
|
||||||
switch (_regType) {
|
switch (_regType) {
|
||||||
case MODBUS_HOLDING_REG_TYPE:
|
case MODBUS_HOLDING_REG_TYPE:
|
||||||
result = node.readHoldingRegisters(reg, 1);
|
result = node.readHoldingRegisters(reg, 1);
|
||||||
@@ -2430,7 +2415,7 @@ int Item::checkModbusDimmer() {
|
|||||||
result = node.readInputRegisters(reg, 1);
|
result = node.readInputRegisters(reg, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugSerial<<F("Not supported reg type\n");
|
debugSerial<<F("MB: Not supported reg type\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == node.ku8MBSuccess) {
|
if (result == node.ku8MBSuccess) {
|
||||||
@@ -2448,7 +2433,8 @@ int Item::checkModbusDimmer() {
|
|||||||
pollingItem = items->child;
|
pollingItem = items->child;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||||
|
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
//resumeModbus();
|
//resumeModbus();
|
||||||
|
|
||||||
@@ -2457,6 +2443,8 @@ return 1;
|
|||||||
|
|
||||||
|
|
||||||
int Item::checkModbusDimmer(int data) {
|
int Item::checkModbusDimmer(int data) {
|
||||||
|
if (getFlag(FLAG_SEND_RETRY)) return 0; //Active send transaction
|
||||||
|
|
||||||
short mask = getArg(2);
|
short mask = getArg(2);
|
||||||
itemCmd st;
|
itemCmd st;
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ e-mail anklimov@gmail.com
|
|||||||
#define S_TEMP 12
|
#define S_TEMP 12
|
||||||
#define S_RAW 13
|
#define S_RAW 13
|
||||||
|
|
||||||
|
typedef char suffixstr[5];
|
||||||
|
const suffixstr suffix_P[] PROGMEM =
|
||||||
|
{"","cmd","set","val","del","HSV","RGB","fan","mode","ctrl","hue","sat","temp","raw"};
|
||||||
|
#define suffixNum sizeof(suffix_P)/sizeof(suffixstr)
|
||||||
|
|
||||||
#define S_ADDITIONAL 13
|
#define S_ADDITIONAL 13
|
||||||
|
|
||||||
#define CH_DIMMER 0 //DMX 1-4 ch
|
#define CH_DIMMER 0 //DMX 1-4 ch
|
||||||
@@ -63,16 +68,6 @@ e-mail anklimov@gmail.com
|
|||||||
#define CH_HUMIDIFIER 21
|
#define CH_HUMIDIFIER 21
|
||||||
#define CH_MERCURY 22
|
#define CH_MERCURY 22
|
||||||
|
|
||||||
//#define CHANNEL_TYPES 13
|
|
||||||
|
|
||||||
//static uint32_t pollInterval[CHANNEL_TYPES] = {0,0,0,0,MODB};
|
|
||||||
//static uint32_t nextPollTime[CHANNEL_TYPES] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
||||||
|
|
||||||
#define CH_WHITE 127//
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define POLLING_SLOW 1
|
#define POLLING_SLOW 1
|
||||||
#define POLLING_FAST 2
|
#define POLLING_FAST 2
|
||||||
#define POLLING_INT 3
|
#define POLLING_INT 3
|
||||||
@@ -157,24 +152,16 @@ class Item
|
|||||||
int VacomSetFan (itemCmd st);
|
int VacomSetFan (itemCmd st);
|
||||||
int VacomSetHeat(itemCmd st);
|
int VacomSetHeat(itemCmd st);
|
||||||
int modbusDimmerSet(itemCmd st);
|
int modbusDimmerSet(itemCmd st);
|
||||||
|
|
||||||
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
|
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
|
||||||
void mb_fail(int result=0);
|
void mb_fail(int result=0);
|
||||||
void Parse();
|
void Parse();
|
||||||
int checkModbusDimmer();
|
int checkModbusDimmer();
|
||||||
int checkModbusDimmer(int data);
|
int checkModbusDimmer(int data);
|
||||||
|
|
||||||
int checkRetry();
|
int checkRetry();
|
||||||
//boolean checkVCRetry();
|
|
||||||
//boolean checkHeatRetry();
|
|
||||||
void sendDelayedStatus();
|
void sendDelayedStatus();
|
||||||
//bool resumeModbus();
|
|
||||||
|
|
||||||
|
|
||||||
int checkFM();
|
int checkFM();
|
||||||
char defaultSubItem[16];
|
char defaultSubItem[16];
|
||||||
int defaultSuffixCode;
|
int defaultSuffixCode;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ volatile unsigned long timerCount=0;
|
|||||||
volatile int16_t timerNumber=-1;
|
volatile int16_t timerNumber=-1;
|
||||||
volatile int8_t timerHandlerBusy=0;
|
volatile int8_t timerHandlerBusy=0;
|
||||||
volatile uint32_t cryptoSalt=0;
|
volatile uint32_t cryptoSalt=0;
|
||||||
|
//uint32_t timerCtr=0;
|
||||||
|
|
||||||
aJsonObject *pollingItem = NULL;
|
aJsonObject *pollingItem = NULL;
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
|||||||
topics = NULL;
|
topics = NULL;
|
||||||
mqttArr = NULL;
|
mqttArr = NULL;
|
||||||
deviceName = NULL;
|
deviceName = NULL;
|
||||||
topics = NULL;
|
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
dmxArr = NULL;
|
dmxArr = NULL;
|
||||||
#endif
|
#endif
|
||||||
@@ -1358,7 +1359,7 @@ setupSyslog();
|
|||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
owArr = aJson.getObjectItem(root, "ow");
|
owArr = aJson.getObjectItem(root, "ow");
|
||||||
if (owArr && !owReady) {
|
if (owArr && !owReady) {
|
||||||
aJsonObject *item = owArr->child;
|
//aJsonObject *item = owArr->child;
|
||||||
owReady = owSetup();
|
owReady = owSetup();
|
||||||
if (owReady) infoSerial<<F("One wire Ready\n");
|
if (owReady) infoSerial<<F("One wire Ready\n");
|
||||||
}
|
}
|
||||||
@@ -1978,18 +1979,19 @@ void postTransmission() {
|
|||||||
|
|
||||||
void TimerHandler(void)
|
void TimerHandler(void)
|
||||||
{
|
{
|
||||||
timerHandlerBusy++;
|
|
||||||
interrupts();
|
|
||||||
timerCount=micros();
|
timerCount=micros();
|
||||||
if (configLoaded && !timerHandlerBusy)
|
if (configLoaded && !timerHandlerBusy)
|
||||||
{
|
{
|
||||||
|
timerHandlerBusy++;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
inputLoop(CHECK_INTERRUPT);
|
inputLoop(CHECK_INTERRUPT);
|
||||||
#ifdef DMX_SMOOTH
|
#ifdef DMX_SMOOTH
|
||||||
DMXOUT_propagate();
|
DMXOUT_propagate();
|
||||||
#endif
|
#endif
|
||||||
|
timerHandlerBusy--;
|
||||||
}
|
}
|
||||||
timerCount=micros()-timerCount;
|
timerCount=micros()-timerCount;
|
||||||
timerHandlerBusy--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) && defined (TIMER_INT)
|
#if defined(__SAM3X8E__) && defined (TIMER_INT)
|
||||||
@@ -2001,6 +2003,10 @@ int16_t attachTimer(double microseconds, timerCallback callback, const char* Tim
|
|||||||
dueTimerInterrupt.attachInterruptInterval(microseconds, callback);
|
dueTimerInterrupt.attachInterruptInterval(microseconds, callback);
|
||||||
timerNumber = dueTimerInterrupt.getTimerNumber();
|
timerNumber = dueTimerInterrupt.getTimerNumber();
|
||||||
debugSerial<<TimerName<<F(" attached to Timer(")<<timerNumber<<F(")")<<endl;
|
debugSerial<<TimerName<<F(" attached to Timer(")<<timerNumber<<F(")")<<endl;
|
||||||
|
//DueTimer.Timers[timerNumber].irq
|
||||||
|
NVIC_SetPriority(TC0_IRQn,2);
|
||||||
|
debugSerial << "USART0 prio:" << NVIC_GetPriority (USART0_IRQn)<< " TC0 prio:" << NVIC_GetPriority (TC0_IRQn)<<endl;
|
||||||
|
|
||||||
return timerNumber;
|
return timerNumber;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2273,9 +2279,7 @@ while ((digitalRead(CONFIG_CLEAN_PIN)==LOW) && !needClean)
|
|||||||
delay(20);
|
delay(20);
|
||||||
//owReady = 0;
|
//owReady = 0;
|
||||||
|
|
||||||
#ifdef _owire
|
|
||||||
setupOwIdle(&owIdle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mqttClient.setCallback(mqttCallback);
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|
||||||
@@ -2493,6 +2497,11 @@ infoSerial<<F("\nNOSERIAL");
|
|||||||
infoSerial<<F("\n(+)ELEVATOR");
|
infoSerial<<F("\n(+)ELEVATOR");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MERCURY_ENABLE
|
||||||
|
infoSerial<<F("\n(+)MERCURY");
|
||||||
|
#else
|
||||||
|
infoSerial<<F("\n(-)MERCURY");
|
||||||
|
#endif
|
||||||
//#ifdef IPMODBUS
|
//#ifdef IPMODBUS
|
||||||
//infoSerial<<F("\n(+)IPMODBUS");
|
//infoSerial<<F("\n(+)IPMODBUS");
|
||||||
//#endif
|
//#endif
|
||||||
@@ -2661,6 +2670,8 @@ void loop_main() {
|
|||||||
yield();
|
yield();
|
||||||
inputLoop(CHECK_INPUT);
|
inputLoop(CHECK_INPUT);
|
||||||
|
|
||||||
|
yield();
|
||||||
|
inputSensorsLoop();
|
||||||
#if defined (_espdmx)
|
#if defined (_espdmx)
|
||||||
yield();
|
yield();
|
||||||
dmxout.update();
|
dmxout.update();
|
||||||
@@ -2672,13 +2683,32 @@ if (initializedListeners) ipmodbusLoop();
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//static uint32_t tm=0;
|
||||||
|
|
||||||
void owIdle(void) {
|
void owIdle(void) {
|
||||||
|
// timerCtr++;
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet && (lanStatus>=HAVE_IP_ADDRESS)) artnet->read();
|
if (artnet && (lanStatus>=HAVE_IP_ADDRESS)) artnet->read();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wdt_res();
|
wdt_res();
|
||||||
inputLoop(CHECK_INTERRUPT);
|
inputLoop(CHECK_INPUT);
|
||||||
|
//inputLoop(CHECK_INTERRUPT);
|
||||||
|
/*
|
||||||
|
if (isTimeOver(tm,millis(),100))
|
||||||
|
{
|
||||||
|
tm=millis();
|
||||||
|
debugSerial<<F("1WT: Tick")<<endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (_espdmx)
|
||||||
|
yield();
|
||||||
|
dmxout.update();
|
||||||
|
#endif
|
||||||
|
|
||||||
return; //?????
|
return; //?????
|
||||||
|
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
@@ -2686,10 +2716,7 @@ inputLoop(CHECK_INTERRUPT);
|
|||||||
DMXCheck();
|
DMXCheck();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (_espdmx)
|
|
||||||
yield();
|
|
||||||
dmxout.update();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IPMODBUS
|
#ifdef IPMODBUS
|
||||||
if (initializedListeners) ipmodbusLoop();
|
if (initializedListeners) ipmodbusLoop();
|
||||||
@@ -2705,7 +2732,9 @@ ethernetIdleCount++;
|
|||||||
ethernetIdleCount--;
|
ethernetIdleCount--;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void modbusIdle(void) {
|
void modbusIdle(void) {
|
||||||
|
|
||||||
wdt_res();
|
wdt_res();
|
||||||
statusLED.poll();
|
statusLED.poll();
|
||||||
yield();
|
yield();
|
||||||
@@ -2782,9 +2811,16 @@ configLocked++;
|
|||||||
if (cause != CHECK_INTERRUPT) timerInputCheck = millis();// + INTERVAL_CHECK_INPUT;
|
if (cause != CHECK_INTERRUPT) timerInputCheck = millis();// + INTERVAL_CHECK_INPUT;
|
||||||
inCache.invalidateInputCache();
|
inCache.invalidateInputCache();
|
||||||
}
|
}
|
||||||
|
configLocked--;
|
||||||
|
inputLoopBusy--;
|
||||||
|
}
|
||||||
|
|
||||||
//if (millis() > timerSensorCheck)
|
|
||||||
if (cause != CHECK_INTERRUPT && isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
|
void inputSensorsLoop() {
|
||||||
|
if (!inputs || inputLoopBusy) return;
|
||||||
|
//inputLoopBusy++;
|
||||||
|
configLocked++;
|
||||||
|
if (isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
|
||||||
{
|
{
|
||||||
aJsonObject *input = inputs->child;
|
aJsonObject *input = inputs->child;
|
||||||
while (input) {
|
while (input) {
|
||||||
@@ -2793,16 +2829,19 @@ configLocked++;
|
|||||||
in.Poll(CHECK_SENSOR);
|
in.Poll(CHECK_SENSOR);
|
||||||
}
|
}
|
||||||
yield();
|
yield();
|
||||||
|
inputLoop(CHECK_INPUT);
|
||||||
input = input->next;
|
input = input->next;
|
||||||
}
|
}
|
||||||
timerSensorCheck = millis();// + INTERVAL_CHECK_SENSOR;
|
timerSensorCheck = millis();
|
||||||
}
|
}
|
||||||
configLocked--;
|
configLocked--;
|
||||||
inputLoopBusy--;
|
//inputLoopBusy--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void inputSetup(void) {
|
void inputSetup(void) {
|
||||||
|
infoSerial<<F("Initializing Inputs")<<endl;
|
||||||
if (!inputs) return;
|
if (!inputs) return;
|
||||||
configLocked++;
|
configLocked++;
|
||||||
aJsonObject *input = inputs->child;
|
aJsonObject *input = inputs->child;
|
||||||
|
|||||||
@@ -287,6 +287,8 @@ void modbusIdle(void);
|
|||||||
|
|
||||||
void inputLoop(short);
|
void inputLoop(short);
|
||||||
|
|
||||||
|
void inputSensorsLoop();
|
||||||
|
|
||||||
void inputSetup(void);
|
void inputSetup(void);
|
||||||
|
|
||||||
void pollingLoop(void);
|
void pollingLoop(void);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
#include <M5Stack.h>
|
#include <M5Stack.h>
|
||||||
@@ -21,14 +22,14 @@ static bool CCS811ready = false;
|
|||||||
|
|
||||||
int in_ccs811::Setup()
|
int in_ccs811::Setup()
|
||||||
{
|
{
|
||||||
if (CCS811ready) {errorSerial<<F("ccs811 is already initialized")<<endl; return 0;}
|
if (CCS811ready) {errorSerial<<F("CCS811: Already initialized")<<endl; return 0;}
|
||||||
|
|
||||||
#ifdef WAK_PIN
|
#ifdef WAK_PIN
|
||||||
pinMode(WAK_PIN,OUTPUT);
|
pinMode(WAK_PIN,OUTPUT);
|
||||||
digitalWrite(WAK_PIN,LOW);
|
digitalWrite(WAK_PIN,LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
infoSerial.println("CCS811 Init");
|
infoSerial.println(F("CCS811: Init"));
|
||||||
|
|
||||||
#if defined (TWI_SCL) && defined (TWI_SDA)
|
#if defined (TWI_SCL) && defined (TWI_SDA)
|
||||||
Wire.begin(TWI_SDA,TWI_SCL); //Inialize I2C Harware
|
Wire.begin(TWI_SDA,TWI_SCL); //Inialize I2C Harware
|
||||||
@@ -36,7 +37,9 @@ Wire.begin(TWI_SDA,TWI_SCL); //Inialize I2C Harware
|
|||||||
Wire.begin(); //Inialize I2C Harware
|
Wire.begin(); //Inialize I2C Harware
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Wire.setClock(4000);
|
#ifdef I2C_CLOCK
|
||||||
|
Wire.setClock(I2C_CLOCK);
|
||||||
|
#endif
|
||||||
|
|
||||||
//It is recommended to check return status on .begin(), but it is not
|
//It is recommended to check return status on .begin(), but it is not
|
||||||
//required.
|
//required.
|
||||||
@@ -45,8 +48,7 @@ Wire.setClock(4000);
|
|||||||
if (returnCode != CCS811Core::SENSOR_SUCCESS)
|
if (returnCode != CCS811Core::SENSOR_SUCCESS)
|
||||||
//if (returnCode != CCS811Core::CCS811_Stat_SUCCESS)
|
//if (returnCode != CCS811Core::CCS811_Stat_SUCCESS)
|
||||||
{
|
{
|
||||||
errorSerial.print("CCS811 Init error ");
|
errorSerial.print(F("CCS811: Init error "));
|
||||||
//debugSerial.println(ccs811.statusString(returnCode));
|
|
||||||
printDriverError(returnCode);
|
printDriverError(returnCode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -63,46 +65,41 @@ delay(2000); */
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int in_hdc1080::Setup()
|
int in_hdc1080::Setup()
|
||||||
{
|
{
|
||||||
if (HDC1080ready) {debugSerial<<F("hdc1080 is already initialized")<<endl; return 0;}
|
//i2cReset();
|
||||||
debugSerial.println("HDC1080 Init ");
|
if (HDC1080ready) {debugSerial<<F("HDC1080: Already initialized")<<endl; return 0;}
|
||||||
|
debugSerial.print(F("HDC1080: Init. "));
|
||||||
Wire.begin(); //Inialize I2C Harware
|
Wire.begin(); //Inialize I2C Harware
|
||||||
// Default settings:
|
// Default settings:
|
||||||
// - Heater off
|
// - Heater off
|
||||||
// - 14 bit Temperature and Humidity Measurement Resolutions
|
// - 14 bit Temperature and Humidity Measurement Resolutions
|
||||||
hdc1080.begin(0x40);
|
hdc1080.begin(0x40);
|
||||||
debugSerial.print("Manufacturer ID=0x");
|
debugSerial.print(F("Manufacturer ID=0x"));
|
||||||
debugSerial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
|
debugSerial.print(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
|
||||||
debugSerial.print("Device ID=0x");
|
debugSerial.print(F(" Device ID=0x"));
|
||||||
debugSerial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
|
debugSerial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
|
||||||
printSerialNumber();
|
printSerialNumber();
|
||||||
HDC1080ready = true;
|
HDC1080ready = true;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2cReset(){
|
|
||||||
Wire.endTransmission(true);
|
|
||||||
#if defined (SCL_RESET)
|
|
||||||
SCL_LOW();
|
|
||||||
delay(300);
|
|
||||||
SCL_HIGH();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int in_hdc1080::Poll(short cause)
|
int in_hdc1080::Poll(short cause)
|
||||||
{
|
{
|
||||||
float h,t;
|
float h,t;
|
||||||
int reg;
|
int reg;
|
||||||
if (cause!=POLLING_SLOW) return 0;
|
if (cause!=POLLING_SLOW) return 0;
|
||||||
if (!HDC1080ready) {debugSerial<<F("HDC1080 not initialized")<<endl; return 0;}
|
if (!HDC1080ready) {errorSerial<<F("HDC1080: Not initialized")<<endl; return 0;}
|
||||||
debugSerial.print("HDC Status=");
|
debugSerial.print(F("HDC1080: Status="));
|
||||||
debugSerial.println(reg=hdc1080.readRegister().rawData,HEX);
|
debugSerial.print(reg=hdc1080.readRegister().rawData,HEX);
|
||||||
if (reg!=0xff)
|
if (reg!=0xff)
|
||||||
{
|
{
|
||||||
debugSerial.print(" T=");
|
debugSerial.print(" T=");
|
||||||
debugSerial.print(t=hdc1080.readTemperature());
|
debugSerial.print(t=hdc1080.readTemperature());
|
||||||
debugSerial.print("C, RH=");
|
debugSerial.print(F("C, RH="));
|
||||||
debugSerial.print(h=hdc1080.readHumidity());
|
debugSerial.print(h=hdc1080.readHumidity());
|
||||||
debugSerial.println("%");
|
debugSerial.println("%");
|
||||||
|
|
||||||
@@ -130,7 +127,7 @@ if (reg!=0xff)
|
|||||||
}
|
}
|
||||||
else //ESP I2C glitch
|
else //ESP I2C glitch
|
||||||
{
|
{
|
||||||
debugSerial.println("I2C Reset");
|
debugSerial.println();
|
||||||
i2cReset();
|
i2cReset();
|
||||||
}
|
}
|
||||||
return INTERVAL_SLOW_POLLING;
|
return INTERVAL_SLOW_POLLING;
|
||||||
@@ -152,14 +149,14 @@ int in_ccs811::Poll(short cause)
|
|||||||
CCS811Core::status returnCode = ccs811.readAlgorithmResults();
|
CCS811Core::status returnCode = ccs811.readAlgorithmResults();
|
||||||
printDriverError(returnCode);
|
printDriverError(returnCode);
|
||||||
float co2,tvoc;
|
float co2,tvoc;
|
||||||
debugSerial.print(" CO2[");
|
debugSerial.print(F(" CO2["));
|
||||||
//Returns calculated CO2 reading
|
//Returns calculated CO2 reading
|
||||||
debugSerial.print(co2 = ccs811.getCO2());
|
debugSerial.print(co2 = ccs811.getCO2());
|
||||||
debugSerial.print("] tVOC[");
|
debugSerial.print(F("] tVOC["));
|
||||||
//Returns calculated TVOC reading
|
//Returns calculated TVOC reading
|
||||||
|
|
||||||
debugSerial.print(tvoc = ccs811.getTVOC());
|
debugSerial.print(tvoc = ccs811.getTVOC());
|
||||||
debugSerial.print("] baseline[");
|
debugSerial.print(F("] baseline["));
|
||||||
debugSerial.print(ccs811Baseline = ccs811.getBaseline());
|
debugSerial.print(ccs811Baseline = ccs811.getBaseline());
|
||||||
|
|
||||||
#ifdef M5STACK
|
#ifdef M5STACK
|
||||||
@@ -197,11 +194,11 @@ int in_ccs811::Poll(short cause)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void in_hdc1080::printSerialNumber() {
|
void in_hdc1080::printSerialNumber() {
|
||||||
debugSerial.print("Device Serial Number=");
|
infoSerial.print(F("Device Serial Number="));
|
||||||
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
|
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
|
||||||
char format[16];
|
char format[16];
|
||||||
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
|
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
|
||||||
debugSerial.println(format);
|
infoSerial.println(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printDriverError decodes the CCS811Core::status type and prints the
|
//printDriverError decodes the CCS811Core::status type and prints the
|
||||||
@@ -211,25 +208,26 @@ debugSerial.println(format);
|
|||||||
//to this function to see what the output was.
|
//to this function to see what the output was.
|
||||||
void in_ccs811::printDriverError( CCS811Core::status errorCode )
|
void in_ccs811::printDriverError( CCS811Core::status errorCode )
|
||||||
{
|
{
|
||||||
|
debugSerial.print(F("CCS811: "));
|
||||||
switch ( errorCode )
|
switch ( errorCode )
|
||||||
{
|
{
|
||||||
case CCS811Core::SENSOR_SUCCESS:
|
case CCS811Core::SENSOR_SUCCESS:
|
||||||
debugSerial.print("SUCCESS");
|
debugSerial.print(F("SUCCESS"));
|
||||||
break;
|
break;
|
||||||
case CCS811Core::SENSOR_ID_ERROR:
|
case CCS811Core::SENSOR_ID_ERROR:
|
||||||
debugSerial.print("ID_ERROR");
|
debugSerial.print(F("ID_ERROR"));
|
||||||
break;
|
break;
|
||||||
case CCS811Core::SENSOR_I2C_ERROR:
|
case CCS811Core::SENSOR_I2C_ERROR:
|
||||||
debugSerial.print("I2C_ERROR");
|
debugSerial.print(F("I2C_ERROR"));
|
||||||
break;
|
break;
|
||||||
case CCS811Core::SENSOR_INTERNAL_ERROR:
|
case CCS811Core::SENSOR_INTERNAL_ERROR:
|
||||||
debugSerial.print("INTERNAL_ERROR");
|
debugSerial.print(F("INTERNAL_ERROR"));
|
||||||
break;
|
break;
|
||||||
case CCS811Core::SENSOR_GENERIC_ERROR:
|
case CCS811Core::SENSOR_GENERIC_ERROR:
|
||||||
debugSerial.print("GENERIC_ERROR");
|
debugSerial.print(F("GENERIC_ERROR"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugSerial.print("Unspecified error.");
|
debugSerial.print(F("Unspecified error."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,18 +239,18 @@ void in_ccs811::printSensorError()
|
|||||||
|
|
||||||
if ( error == 0xFF ) //comm error
|
if ( error == 0xFF ) //comm error
|
||||||
{
|
{
|
||||||
debugSerial.println("Failed to get ERROR_ID register.");
|
errorSerial.println(F("CCS811: Failed to get ERROR_ID register."));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//debugSerial.print("");
|
if (error) errorSerial.print(F("CCS811: Error "));
|
||||||
if (error & 1 << 5) debugSerial.print("Error: HeaterSupply");
|
if (error & 1 << 5) errorSerial.print(F("HeaterSupply"));
|
||||||
if (error & 1 << 4) debugSerial.print("Error: HeaterFault");
|
if (error & 1 << 4) errorSerial.print(F("HeaterFault"));
|
||||||
if (error & 1 << 3) debugSerial.print("Error: MaxResistance");
|
if (error & 1 << 3) errorSerial.print(F("MaxResistance"));
|
||||||
if (error & 1 << 2) debugSerial.print("Error: MeasModeInvalid");
|
if (error & 1 << 2) errorSerial.print(F("MeasModeInvalid"));
|
||||||
if (error & 1 << 1) debugSerial.print("Error: ReadRegInvalid");
|
if (error & 1 << 1) errorSerial.print(F("ReadRegInvalid"));
|
||||||
if (error & 1 << 0) debugSerial.print("Error: MsgInvalid");
|
if (error & 1 << 0) errorSerial.print(F("MsgInvalid"));
|
||||||
debugSerial.println();
|
if (error) errorSerial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
#include "ClosedCube_HDC1080.h"
|
#include "ClosedCube_HDC1080.h"
|
||||||
#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811
|
#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811
|
||||||
|
|
||||||
|
//#ifndef I2C_CLOCK
|
||||||
|
//#define I2C_CLOCK 4000
|
||||||
|
//#endif
|
||||||
|
|
||||||
//#define CCS811_ADDR 0x5B //Default I2C Address
|
//#define CCS811_ADDR 0x5B //Default I2C Address
|
||||||
#define CCS811_ADDR 0x5A //Alternate I2C Address
|
#define CCS811_ADDR 0x5A //Alternate I2C Address
|
||||||
|
|
||||||
@@ -28,13 +32,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
#if defined (__SAM3X8E__)
|
|
||||||
#define SCL_LOW() digitalWrite(21,LOW)
|
|
||||||
#define SCL_HIGH() digitalWrite(21,HIGH)
|
|
||||||
#define SCL_RESET
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined (ARDUINO_ARCH_ESP32)
|
#if defined (ARDUINO_ARCH_ESP32)
|
||||||
#undef WAK_PIN
|
#undef WAK_PIN
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ extern bool disableCMD;
|
|||||||
|
|
||||||
#define INTERVAL_AC_POLLING 5000L
|
#define INTERVAL_AC_POLLING 5000L
|
||||||
|
|
||||||
#define AC_FAILED 15
|
#define AC_FAILED CST_FAILED
|
||||||
#define AC_UNKNOWN CST_UNKNOWN
|
#define AC_UNKNOWN CST_UNKNOWN
|
||||||
#define AC_IDLE CST_INITIALIZED
|
#define AC_IDLE CST_INITIALIZED
|
||||||
#define AC_SENDING 2
|
#define AC_SENDING CST_USER
|
||||||
|
|
||||||
//byte inCheck = 0;
|
//byte inCheck = 0;
|
||||||
byte qstn[] = {255,255,10,0,0,0,0,0,1,1,77,1,90}; // Команда опроса
|
byte qstn[] = {255,255,10,0,0,0,0,0,1,1,77,1,90}; // Команда опроса
|
||||||
@@ -273,7 +273,7 @@ byte getCRC(byte req[], size_t size){
|
|||||||
|
|
||||||
void out_AC::SendData(byte req[], size_t size){
|
void out_AC::SendData(byte req[], size_t size){
|
||||||
if (!store || !item) return;
|
if (!store || !item) return;
|
||||||
if (item->itemArr->subtype == AC_SENDING)
|
if (Status() == AC_SENDING)
|
||||||
{
|
{
|
||||||
while (store->timestamp && !isTimeOver(store->timestamp,millis(),150)) yield();
|
while (store->timestamp && !isTimeOver(store->timestamp,millis(),150)) yield();
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ if (item->itemArr->subtype == AC_SENDING)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
debugSerial.println();
|
debugSerial.println();
|
||||||
item->itemArr->subtype = AC_SENDING;
|
setStatus(AC_SENDING);
|
||||||
// #if defined (__SAM3X8E__)
|
// #if defined (__SAM3X8E__)
|
||||||
// if (item->getArg(0)==2) postTransmission();
|
// if (item->getArg(0)==2) postTransmission();
|
||||||
// #endif
|
// #endif
|
||||||
@@ -340,9 +340,9 @@ if (!portNum)// && (g_APinDescription[0].ulPinType == PIO_PA8A_URXD))
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ACSerial->begin(9600);
|
ACSerial->begin(9600);
|
||||||
item->itemArr->subtype = AC_IDLE;
|
setStatus (AC_IDLE);
|
||||||
|
|
||||||
|
|
||||||
//driverStatus = CST_INITIALIZED;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,10 +353,11 @@ debugSerial<<F("AC: De-Init: ")<<portNum<<endl;
|
|||||||
delete store;
|
delete store;
|
||||||
item->setPersistent(NULL);
|
item->setPersistent(NULL);
|
||||||
store = NULL;
|
store = NULL;
|
||||||
item->itemArr->subtype = CST_UNKNOWN;
|
setStatus (CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int out_AC::Status()
|
int out_AC::Status()
|
||||||
{
|
{
|
||||||
if (!item) return 0;
|
if (!item) return 0;
|
||||||
@@ -368,7 +369,8 @@ default:
|
|||||||
return CST_INITIALIZED;
|
return CST_INITIALIZED;
|
||||||
//return item->itemArr->subtype;
|
//return item->itemArr->subtype;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
int out_AC::isActive()
|
int out_AC::isActive()
|
||||||
{
|
{
|
||||||
if (!store) return 0;
|
if (!store) return 0;
|
||||||
@@ -379,7 +381,7 @@ int out_AC::Poll(short cause)
|
|||||||
{
|
{
|
||||||
if (!store) return -1;
|
if (!store) return -1;
|
||||||
|
|
||||||
switch (item->itemArr->subtype)
|
switch (Status())
|
||||||
{
|
{
|
||||||
case AC_FAILED: return -1;
|
case AC_FAILED: return -1;
|
||||||
case AC_UNKNOWN: return -1;
|
case AC_UNKNOWN: return -1;
|
||||||
@@ -387,7 +389,7 @@ case AC_SENDING:
|
|||||||
{
|
{
|
||||||
if (store->timestamp && isTimeOver(store->timestamp,millis(),150))
|
if (store->timestamp && isTimeOver(store->timestamp,millis(),150))
|
||||||
{
|
{
|
||||||
item->itemArr->subtype = AC_IDLE;
|
setStatus(AC_IDLE);
|
||||||
store->timestamp=millisNZ();
|
store->timestamp=millisNZ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -395,7 +397,7 @@ case AC_SENDING:
|
|||||||
|
|
||||||
if (cause!=POLLING_SLOW) return false;
|
if (cause!=POLLING_SLOW) return false;
|
||||||
|
|
||||||
if ((item->itemArr->subtype == AC_IDLE) && isTimeOver(store->timestamp,millis(),INTERVAL_AC_POLLING))
|
if ((Status() == AC_IDLE) && isTimeOver(store->timestamp,millis(),INTERVAL_AC_POLLING))
|
||||||
{
|
{
|
||||||
debugSerial.println(F("AC: Polling"));
|
debugSerial.println(F("AC: Polling"));
|
||||||
SendData(qstn, sizeof(qstn)/sizeof(byte)); //Опрос кондиционера
|
SendData(qstn, sizeof(qstn)/sizeof(byte)); //Опрос кондиционера
|
||||||
|
|||||||
@@ -40,10 +40,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
// int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
void SubmitParameters(const char * name, itemCmd value);
|
void SubmitParameters(const char * name, itemCmd value);
|
||||||
|
|
||||||
|
|||||||
@@ -8,25 +8,20 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
int out_counter::Setup()
|
int out_counter::Setup()
|
||||||
{
|
{
|
||||||
abstractOut::Setup();
|
abstractOut::Setup();
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_counter::Stop()
|
int out_counter::Stop()
|
||||||
{
|
{
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_counter::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int out_counter::Poll(short cause)
|
int out_counter::Poll(short cause)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,28 +9,22 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
int out_dmx::Setup()
|
int out_dmx::Setup()
|
||||||
{
|
{
|
||||||
abstractOut::Setup();
|
abstractOut::Setup();
|
||||||
debugSerial<<F("DMX-Out Init: ")<< item->itemArr->name <<endl;
|
debugSerial<<F("DMX-Out Init: ")<< item->itemArr->name <<endl;
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_dmx::Stop()
|
int out_dmx::Stop()
|
||||||
{
|
{
|
||||||
debugSerial<<F("DMX-Out stop: ")<< item->itemArr->name << endl;
|
debugSerial<<F("DMX-Out stop: ")<< item->itemArr->name << endl;
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_dmx::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
int out_dmx::getChanType()
|
int out_dmx::getChanType()
|
||||||
{
|
{
|
||||||
if (item)
|
if (item)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public:
|
|||||||
out_dmx(Item * _item):colorChannel(_item){};
|
out_dmx(Item * _item):colorChannel(_item){};
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
// int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
// int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||||
|
|||||||
@@ -78,14 +78,14 @@ store->timestamp=millisNZ();
|
|||||||
if (getConfig())
|
if (getConfig())
|
||||||
{
|
{
|
||||||
infoSerial<<F("Mercury: config loaded ")<< item->itemArr->name<<endl;
|
infoSerial<<F("Mercury: config loaded ")<< item->itemArr->name<<endl;
|
||||||
store->driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
store->lastSuccessTS = 0;
|
store->lastSuccessTS = 0;
|
||||||
initLine(true);
|
initLine(true);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ errorSerial<<F("Mercury: config error")<<endl;
|
{ errorSerial<<F("Mercury: config error")<<endl;
|
||||||
store->driverStatus = CST_FAILED;
|
setStatus(CST_FAILED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,22 +97,11 @@ debugSerial.println("Mercury: De-Init");
|
|||||||
disconnectMercury();
|
disconnectMercury();
|
||||||
delete store;
|
delete store;
|
||||||
item->setPersistent(NULL);
|
item->setPersistent(NULL);
|
||||||
|
setStatus(CST_UNKNOWN);
|
||||||
store = NULL;
|
store = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Mercury::Status()
|
|
||||||
{
|
|
||||||
if (store)
|
|
||||||
return store->driverStatus;
|
|
||||||
return CST_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void out_Mercury::setStatus(short status)
|
|
||||||
{
|
|
||||||
if (store) store->driverStatus=status;
|
|
||||||
}
|
|
||||||
|
|
||||||
short out_Mercury::connectMercury()
|
short out_Mercury::connectMercury()
|
||||||
{
|
{
|
||||||
@@ -337,7 +326,7 @@ int out_Mercury::Poll(short cause)
|
|||||||
//bool lineInitialized = false;
|
//bool lineInitialized = false;
|
||||||
if (cause==POLLING_SLOW) return 0;
|
if (cause==POLLING_SLOW) return 0;
|
||||||
if (modbusBusy || ( mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100))) return 0;
|
if (modbusBusy || ( mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100))) return 0;
|
||||||
if (store->driverStatus == CST_FAILED) return 0;
|
if (Status() == CST_FAILED) return 0;
|
||||||
if (!getConfig()) return 0;
|
if (!getConfig()) return 0;
|
||||||
|
|
||||||
switch (Status())
|
switch (Status())
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
class mercuryPersistent : public chPersistent {
|
class mercuryPersistent : public chPersistent {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int8_t driverStatus;
|
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
uint32_t lastSuccessTS;
|
uint32_t lastSuccessTS;
|
||||||
};
|
};
|
||||||
@@ -21,16 +20,16 @@ public:
|
|||||||
#define MB_SEND_ERROR 4
|
#define MB_SEND_ERROR 4
|
||||||
#define MB_SEND_ATTEMPTS 3
|
#define MB_SEND_ATTEMPTS 3
|
||||||
|
|
||||||
#define M_CONNECTING 10
|
#define M_CONNECTING CST_USER+0
|
||||||
#define M_CONNECTED 11
|
#define M_CONNECTED CST_USER+1
|
||||||
#define M_POLLING1 12
|
#define M_POLLING1 CST_USER+2
|
||||||
#define M_POLLING2 13
|
#define M_POLLING2 CST_USER+3
|
||||||
#define M_POLLING3 14
|
#define M_POLLING3 CST_USER+4
|
||||||
#define M_POLLING4 15
|
#define M_POLLING4 CST_USER+5
|
||||||
#define M_POLLING5 16
|
#define M_POLLING5 CST_USER+6
|
||||||
#define M_POLLING6 17
|
#define M_POLLING6 CST_USER+7
|
||||||
#define M_POLLING7 18
|
#define M_POLLING7 CST_USER+8
|
||||||
#define M_POLLING8 19
|
#define M_POLLING8 CST_USER+9
|
||||||
|
|
||||||
#define RET_SUCCESS 0
|
#define RET_SUCCESS 0
|
||||||
#define RET_INVALID_PARAM 1
|
#define RET_INVALID_PARAM 1
|
||||||
@@ -47,10 +46,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -58,7 +56,6 @@ protected:
|
|||||||
uint16_t pollingInterval;
|
uint16_t pollingInterval;
|
||||||
bool getConfig();
|
bool getConfig();
|
||||||
void initLine(bool full = false);
|
void initLine(bool full = false);
|
||||||
void setStatus(short);
|
|
||||||
short connectMercury();
|
short connectMercury();
|
||||||
short disconnectMercury();
|
short disconnectMercury();
|
||||||
short getCurrentVal12(byte param, String topic,int divisor=1);
|
short getCurrentVal12(byte param, String topic,int divisor=1);
|
||||||
|
|||||||
@@ -180,12 +180,12 @@ store->timestamp=millisNZ();
|
|||||||
if (getConfig())
|
if (getConfig())
|
||||||
{
|
{
|
||||||
infoSerial<<F("MBUS: config loaded ")<< item->itemArr->name<<endl;
|
infoSerial<<F("MBUS: config loaded ")<< item->itemArr->name<<endl;
|
||||||
store->driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ errorSerial<<F("MBUS: config error")<<endl;
|
{ errorSerial<<F("MBUS: config error")<<endl;
|
||||||
store->driverStatus = CST_FAILED;
|
setStatus(CST_FAILED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +202,6 @@ store = NULL;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Modbus::Status()
|
|
||||||
{
|
|
||||||
if (store)
|
|
||||||
return store->driverStatus;
|
|
||||||
return CST_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -333,7 +327,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
mappedParam.Int((uint32_t)param);
|
mappedParam.Int((uint32_t)param);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial << F("MBUSD: got ")<<mappedParam.toString(buf,sizeof(buf))<< F(" from type ")<<parType<<F(":")<<paramObj->name<<endl;
|
traceSerial << F("MBUSD: got ")<<mappedParam.toString(buf,sizeof(buf))<< F(" from type ")<<parType<<F(":")<<paramObj->name<<endl;
|
||||||
|
|
||||||
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
||||||
{
|
{
|
||||||
@@ -407,7 +401,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
|
|
||||||
aJsonObject * nestedMapObj = aJson.getObjectItem(templateParObj, "map");
|
aJsonObject * nestedMapObj = aJson.getObjectItem(templateParObj, "map");
|
||||||
if (nestedMapObj && (nestedMapObj->type==aJson_Array || nestedMapObj->type==aJson_Object)) mappedParam=mappedParam.doReverseMapping(nestedMapObj);
|
if (nestedMapObj && (nestedMapObj->type==aJson_Array || nestedMapObj->type==aJson_Object)) mappedParam=mappedParam.doReverseMapping(nestedMapObj);
|
||||||
debugSerial << F("MBUSD: NestedMapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
traceSerial << F("MBUSD: NestedMapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
||||||
|
|
||||||
if (!(lastMeasured->subtype & MB_VALUE_OUTDATED))
|
if (!(lastMeasured->subtype & MB_VALUE_OUTDATED))
|
||||||
{
|
{
|
||||||
@@ -455,7 +449,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debugSerial << F("MBUSD: Mapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
traceSerial << F("MBUSD: Mapped:")<<mappedParam.toString(buf,sizeof(buf))<<endl;
|
||||||
} //mapping
|
} //mapping
|
||||||
|
|
||||||
if (doExecution && idObj && idObj->type==aJson_Int)
|
if (doExecution && idObj && idObj->type==aJson_Int)
|
||||||
@@ -511,7 +505,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
|
|||||||
aJsonObject *settedValue = aJson.getObjectItem(markObj,"@V");
|
aJsonObject *settedValue = aJson.getObjectItem(markObj,"@V");
|
||||||
if (settedValue && settedValue->type==aJson_Int && (settedValue->valueint == param))
|
if (settedValue && settedValue->type==aJson_Int && (settedValue->valueint == param))
|
||||||
{
|
{
|
||||||
debugSerial<<F("MBUSD: Ignored - equal with setted val")<<endl;
|
traceSerial<<F("MBUSD: Ignored - equal with setted val")<<endl;
|
||||||
*submitParam=false;
|
*submitParam=false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -725,7 +719,7 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
|||||||
// if some polling configured
|
// if some polling configured
|
||||||
if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store->poolingDiscreteIns)
|
if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store->poolingDiscreteIns)
|
||||||
{
|
{
|
||||||
debugSerial<<F("MBUSD: Poll ")<< item->itemArr->name << endl;
|
traceSerial<<F("MBUSD: Poll ")<< item->itemArr->name << endl;
|
||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
|
|
||||||
if (!lineInitialized)
|
if (!lineInitialized)
|
||||||
@@ -738,7 +732,7 @@ if (store->pollingRegisters || store->pollingIrs || store->pollingCoils || store
|
|||||||
pollModbus(store->pollingIrs,MODBUS_INPUT_REG_TYPE);
|
pollModbus(store->pollingIrs,MODBUS_INPUT_REG_TYPE);
|
||||||
pollModbus(store->pollingCoils,MODBUS_COIL_REG_TYPE);
|
pollModbus(store->pollingCoils,MODBUS_COIL_REG_TYPE);
|
||||||
pollModbus(store->poolingDiscreteIns ,MODBUS_DISCRETE_REG_TYPE);
|
pollModbus(store->poolingDiscreteIns ,MODBUS_DISCRETE_REG_TYPE);
|
||||||
debugSerial<<F("MBUSD: endPoll ")<< item->itemArr->name << endl;
|
traceSerial<<F("MBUSD: endPoll ")<< item->itemArr->name << endl;
|
||||||
|
|
||||||
//Non blocking waiting to release line
|
//Non blocking waiting to release line
|
||||||
uint32_t time = millis();
|
uint32_t time = millis();
|
||||||
@@ -800,7 +794,7 @@ aJsonObject * mapObj = aJson.getObjectItem(templateParamObj, "map");
|
|||||||
Value=cmdValue.getTens_raw()*(100/TENS_BASE);
|
Value=cmdValue.getTens_raw()*(100/TENS_BASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial<<F("MBUSD: suffix:")<<suffixStr<< F(" Val: ")<<Value<<endl;
|
traceSerial<<F("MBUSD: suffix:")<<suffixStr<< F(" Val: ")<<Value<<endl;
|
||||||
aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
|
aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
|
||||||
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
class mbPersistent : public chPersistent {
|
class mbPersistent : public chPersistent {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// int addr
|
|
||||||
int8_t driverStatus;
|
|
||||||
int baud;
|
int baud;
|
||||||
serialParamType serialParam;
|
serialParamType serialParam;
|
||||||
uint16_t pollingInterval;
|
uint16_t pollingInterval;
|
||||||
@@ -37,10 +36,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
void out_Motor::getConfig()
|
void out_Motor::getConfig()
|
||||||
{
|
{
|
||||||
@@ -64,7 +63,7 @@ pinMode(pinFeedback, INPUT);
|
|||||||
item->setExt(0);
|
item->setExt(0);
|
||||||
item->clearFlag(FLAG_ACTION_NEEDED);
|
item->clearFlag(FLAG_ACTION_NEEDED);
|
||||||
item->clearFlag(FLAG_ACTION_IN_PROCESS);
|
item->clearFlag(FLAG_ACTION_IN_PROCESS);
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
motorQuote = MOTOR_QUOTE;
|
motorQuote = MOTOR_QUOTE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -73,7 +72,7 @@ int out_Motor::Stop()
|
|||||||
{
|
{
|
||||||
debugSerial.println("Motor: De-Init");
|
debugSerial.println("Motor: De-Init");
|
||||||
item->setExt(0);
|
item->setExt(0);
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
|
|
||||||
if (isProtectedPin(pinUp)||isProtectedPin(pinDown)) {errorSerial<<F("pin disabled")<<endl;return 0;}
|
if (isProtectedPin(pinUp)||isProtectedPin(pinDown)) {errorSerial<<F("pin disabled")<<endl;return 0;}
|
||||||
digitalWrite(pinUp,INACTIVE);
|
digitalWrite(pinUp,INACTIVE);
|
||||||
@@ -82,26 +81,6 @@ digitalWrite(pinDown,INACTIVE);
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Motor::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
int out_Motor::isActive()
|
|
||||||
{
|
|
||||||
itemCmd st;
|
|
||||||
switch (item->getCmd())
|
|
||||||
{
|
|
||||||
case CMD_OFF:
|
|
||||||
case CMD_HALT:
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
st.loadItem(item);
|
|
||||||
return st.getPercents255();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
int out_Motor::Poll(short cause)
|
int out_Motor::Poll(short cause)
|
||||||
{
|
{
|
||||||
if (cause==POLLING_SLOW) return 0;
|
if (cause==POLLING_SLOW) return 0;
|
||||||
|
|||||||
@@ -24,10 +24,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
//int isActive() override;
|
//int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
//int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
void out_Multivent::getConfig()
|
void out_Multivent::getConfig()
|
||||||
{
|
{
|
||||||
@@ -46,7 +45,7 @@ if (gatesObj /*&& aJson.getArraySize(item->itemArg)>=2*/)
|
|||||||
i=i->next;
|
i=i->next;
|
||||||
}
|
}
|
||||||
debugSerial << F ("MultiVent init")<< endl;
|
debugSerial << F ("MultiVent init")<< endl;
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,30 +57,10 @@ return 0;
|
|||||||
int out_Multivent::Stop()
|
int out_Multivent::Stop()
|
||||||
{
|
{
|
||||||
debugSerial << F ("Multivent De-Init") << endl;
|
debugSerial << F ("Multivent De-Init") << endl;
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Multivent::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
int out_Multivent::isActive()
|
|
||||||
{
|
|
||||||
itemCmd st;
|
|
||||||
switch (item->getCmd())
|
|
||||||
{
|
|
||||||
case CMD_OFF:
|
|
||||||
case CMD_HALT:
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
st.loadItem(item);
|
|
||||||
return st.getPercents255();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
int out_Multivent::Poll(short cause)
|
int out_Multivent::Poll(short cause)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@@ -93,7 +72,6 @@ int out_Multivent::getChanType()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized)
|
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
//int isActive() override;
|
//int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
//int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
protected:
|
protected:
|
||||||
void getConfig();
|
void getConfig();
|
||||||
|
|||||||
@@ -125,12 +125,12 @@ if (getConfig())
|
|||||||
// if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
// if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
||||||
// if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
// if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
||||||
store->prevOut = -2.0;
|
store->prevOut = -2.0;
|
||||||
store->driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ errorSerial<<F("PID: config error")<<endl;
|
{ errorSerial<<F("PID: config error")<<endl;
|
||||||
store->driverStatus = CST_FAILED;
|
setStatus(CST_FAILED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +147,6 @@ store = NULL;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_pid::Status()
|
|
||||||
{
|
|
||||||
if (store)
|
|
||||||
return store->driverStatus;
|
|
||||||
return CST_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
int out_pid::isActive()
|
int out_pid::isActive()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public:
|
|||||||
double input;
|
double input;
|
||||||
double setpoint;
|
double setpoint;
|
||||||
float prevOut;
|
float prevOut;
|
||||||
int driverStatus;
|
|
||||||
uint32_t alarmTimer;
|
uint32_t alarmTimer;
|
||||||
bool alarmArmed;
|
bool alarmArmed;
|
||||||
uint16_t alarmTimeout; //in sec
|
uint16_t alarmTimeout; //in sec
|
||||||
@@ -30,10 +29,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int isActive() override;
|
int isActive() override;
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int getDefaultStorageType(){return ST_FLOAT;};
|
//int getDefaultStorageType(){return ST_FLOAT;};
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
void alarm(bool);
|
void alarm(bool);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
void analogWrite(int pin, int val)
|
void analogWrite(int pin, int val)
|
||||||
@@ -55,7 +54,7 @@ switch (getChanType())
|
|||||||
TCCR3B |= tval;
|
TCCR3B |= tval;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,15 +74,10 @@ switch (getChanType())
|
|||||||
default:
|
default:
|
||||||
pinMode(iaddr, INPUT);
|
pinMode(iaddr, INPUT);
|
||||||
}
|
}
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_pwm::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int out_pwm::getChanType()
|
int out_pwm::getChanType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
out_pwm(Item * _item):colorChannel(_item){numChannels=0;};
|
out_pwm(Item * _item):colorChannel(_item){numChannels=0;};
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
void out_relay::getConfig()
|
void out_relay::getConfig()
|
||||||
{
|
{
|
||||||
@@ -43,7 +42,7 @@ digitalWrite(pin,INACTIVE);
|
|||||||
if (item) item->setExt(0);
|
if (item) item->setExt(0);
|
||||||
//if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
//if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
||||||
//if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
//if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
if (item->isActive()>0) ///????
|
if (item->isActive()>0) ///????
|
||||||
{
|
{
|
||||||
item->setExt(millisNZ());
|
item->setExt(millisNZ());
|
||||||
@@ -55,24 +54,10 @@ int out_relay::Stop()
|
|||||||
{
|
{
|
||||||
debugSerial<<F("Relay-Out #")<<pin<<F(" stop")<<endl;
|
debugSerial<<F("Relay-Out #")<<pin<<F(" stop")<<endl;
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_relay::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
const char action_P[] PROGMEM = "action";
|
|
||||||
const char cooling_P[] PROGMEM = "cooling";
|
|
||||||
const char heating_P[] PROGMEM = "heating";
|
|
||||||
const char drying_P[] PROGMEM = "drying";
|
|
||||||
const char idle_P[] PROGMEM = "idle";
|
|
||||||
const char fan_P[] PROGMEM = "fan";
|
|
||||||
const char off_P[] PROGMEM = "off";
|
|
||||||
*/
|
|
||||||
|
|
||||||
void out_relay::relay(bool state)
|
void out_relay::relay(bool state)
|
||||||
{
|
{
|
||||||
char subtopic[10]="/";
|
char subtopic[10]="/";
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ static CRGB *leds = NULL;
|
|||||||
|
|
||||||
#define NUM_LEDS 43
|
#define NUM_LEDS 43
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
|
||||||
|
|
||||||
void out_SPILed::getConfig()
|
void out_SPILed::getConfig()
|
||||||
{
|
{
|
||||||
@@ -63,7 +62,7 @@ FastLED.addLeds<CONTROLLER, DATA_PIN, ORDER>(leds, numLeds);
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,15 +77,11 @@ delete leds;
|
|||||||
FastLED.clear(true);
|
FastLED.clear(true);
|
||||||
delete [] leds;
|
delete [] leds;
|
||||||
#endif
|
#endif
|
||||||
driverStatus = CST_UNKNOWN;
|
setStatus(CST_UNKNOWN);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_SPILed::Status()
|
|
||||||
{
|
|
||||||
return driverStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int out_SPILed::getChanType()
|
int out_SPILed::getChanType()
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ public:
|
|||||||
out_SPILed(Item * _item):colorChannel(_item){getConfig();};
|
out_SPILed(Item * _item):colorChannel(_item){getConfig();};
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||||
|
|||||||
@@ -121,12 +121,12 @@ if (!store)
|
|||||||
if (getConfig())
|
if (getConfig())
|
||||||
{
|
{
|
||||||
infoSerial<<F("UARTbridge config loaded ")<< item->itemArr->name<<endl;
|
infoSerial<<F("UARTbridge config loaded ")<< item->itemArr->name<<endl;
|
||||||
store->driverStatus = CST_INITIALIZED;
|
setStatus(CST_INITIALIZED)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ errorSerial<<F("UARTbridge config error")<<endl;
|
{ errorSerial<<F("UARTbridge config error")<<endl;
|
||||||
store->driverStatus = CST_FAILED;
|
setStatus(CST_FAILED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +146,6 @@ store = NULL;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_UARTbridge::Status()
|
|
||||||
{
|
|
||||||
if (store)
|
|
||||||
return store->driverStatus;
|
|
||||||
return CST_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
String _RR_A;
|
String _RR_A;
|
||||||
String _WR_A;
|
String _WR_A;
|
||||||
|
|||||||
@@ -43,8 +43,7 @@
|
|||||||
class ubPersistent : public chPersistent {
|
class ubPersistent : public chPersistent {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// int addr
|
|
||||||
int8_t driverStatus;
|
|
||||||
int baud;
|
int baud;
|
||||||
serialParamType serialParam;
|
serialParamType serialParam;
|
||||||
//uint16_t pollingInterval;
|
//uint16_t pollingInterval;
|
||||||
@@ -63,10 +62,9 @@ public:
|
|||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll(short cause) override;
|
int Poll(short cause) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
int Status() override;
|
|
||||||
int getChanType() override;
|
int getChanType() override;
|
||||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||||
int getDefaultStorageType(){return ST_INT32;};
|
//int getDefaultStorageType(){return ST_INT32;};
|
||||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
extern aJsonObject *owArr;
|
extern aJsonObject *owArr;
|
||||||
|
//extern uint32_t timerCtr;
|
||||||
aJsonObject *dev2Check = NULL;
|
aJsonObject *dev2Check = NULL;
|
||||||
|
|
||||||
OneWire *oneWire = NULL;
|
OneWire *oneWire = NULL;
|
||||||
@@ -60,7 +61,7 @@ char * getReadableNote(aJsonObject * owObj)
|
|||||||
void processTemp(aJsonObject * owObj, float currentTemp) {
|
void processTemp(aJsonObject * owObj, float currentTemp) {
|
||||||
if (!owObj || !owArr) return;
|
if (!owObj || !owArr) return;
|
||||||
char* note = getReadableNote(owObj);
|
char* note = getReadableNote(owObj);
|
||||||
debugSerial<<endl<<F("1WT:")<<currentTemp<<F(" <")<<owObj->name<<F("> ");
|
debugSerial <<F("1WT:")<<currentTemp<<F(" <")<<owObj->name<<F("> ");
|
||||||
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
||||||
{
|
{
|
||||||
if (note) debugSerial<<note;
|
if (note) debugSerial<<note;
|
||||||
@@ -96,6 +97,7 @@ int owUpdate() {
|
|||||||
while (oneWire->wireSearch(dev) > 0)
|
while (oneWire->wireSearch(dev) > 0)
|
||||||
{
|
{
|
||||||
wdt_res();
|
wdt_res();
|
||||||
|
// owIdle();
|
||||||
char addrstr[17];
|
char addrstr[17];
|
||||||
SetBytes(dev, 8, addrstr);
|
SetBytes(dev, 8, addrstr);
|
||||||
addrstr[16] = 0;
|
addrstr[16] = 0;
|
||||||
@@ -112,45 +114,7 @@ int owUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (oneWire) oneWire->reset_search();
|
|
||||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
|
||||||
|
|
||||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && !isTimeOver(finish,millis(), OW_UPDATE_INTERVAL))//&& finish > millis())
|
|
||||||
{
|
|
||||||
short ifind = -1;
|
|
||||||
if (oneWire->crc8(term[t_count], 7) == term[t_count][7]) {
|
|
||||||
for (short i = 0; i < t_count; i++)
|
|
||||||
if (!memcmp(term[i], term[t_count], 8)) {
|
|
||||||
ifind = i;
|
|
||||||
wstat[i] |= SW_FIND;
|
|
||||||
debugSerial.print(F(" Node:"));
|
|
||||||
PrintBytes(term[t_count], 8,0);
|
|
||||||
processTemp(-1, term[t_count], 0.0); //print note
|
|
||||||
debugSerial.println(F(" alive"));
|
|
||||||
break;
|
|
||||||
}; //alive
|
|
||||||
if (ifind < 0 && sensors && !zero(term[t_count],8))
|
|
||||||
{
|
|
||||||
wstat[t_count] = SW_FIND; //Newly detected
|
|
||||||
debugSerial<<F("dev#")<<t_count<<F(" Addr:");
|
|
||||||
PrintBytes(term[t_count], 8,0);
|
|
||||||
if processTemp(-1, term[t_count], 0.0); //print note
|
|
||||||
debugSerial.println();
|
|
||||||
if (term[t_count][0] == 0x28) {
|
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
|
||||||
oneWire->setStrongPullup();
|
|
||||||
#endif
|
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
|
||||||
}
|
|
||||||
t_count++;
|
|
||||||
}
|
|
||||||
}//if
|
|
||||||
} //while
|
|
||||||
|
|
||||||
debugSerial<<F("1-wire count: ")<<t_count<<endl;
|
|
||||||
*/
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -161,8 +125,9 @@ int owSetup() {
|
|||||||
//// todo - move memory allocation to here
|
//// todo - move memory allocation to here
|
||||||
if (oneWire) return true; // Already initialized
|
if (oneWire) return true; // Already initialized
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
|
||||||
debugSerial<<F("Free:")<<freeRam()<<endl;
|
debugSerial<<F("1WT: DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
||||||
|
//debugSerial<<F("Free:")<<freeRam()<<endl;
|
||||||
oneWire = new OneWire;
|
oneWire = new OneWire;
|
||||||
#else
|
#else
|
||||||
debugSerial.print(F("One wire setup on PIN:"));
|
debugSerial.print(F("One wire setup on PIN:"));
|
||||||
@@ -176,24 +141,11 @@ if (!oneWire)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
term = new DeviceAddress[t_max];
|
|
||||||
debugSerial<<F("Term. Free:")<<freeRam()<<endl;
|
|
||||||
//regs = new int [t_max];
|
|
||||||
wstat = new uint16_t[t_max];
|
|
||||||
debugSerial<<F("wstat. Free:")<<freeRam()<<endl;
|
|
||||||
if (!term || ! wstat)
|
|
||||||
{
|
|
||||||
errorSerial<<F("Error 1-w init #2 Free:")<<freeRam()<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
owChanged = owCh;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
if (oneWire->checkPresence()) {
|
if (oneWire->checkPresence()) {
|
||||||
debugSerial.println(F("DS2482-100 present"));
|
infoSerial.println(F("1WT: DS2482-100 present, reset"));
|
||||||
oneWire->deviceReset();
|
oneWire->deviceReset();
|
||||||
#ifdef APU_OFF
|
#ifdef APU_OFF
|
||||||
debugSerial.println(F("APU off"));
|
debugSerial.println(F("APU off"));
|
||||||
@@ -201,22 +153,61 @@ if (!term || ! wstat)
|
|||||||
oneWire->setActivePullup();
|
oneWire->setActivePullup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
// debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||||
if (oneWire->wireReset())
|
if (oneWire->wireReset())
|
||||||
debugSerial.println(F("\tReset done"));
|
debugSerial.println(F("1WT: Bus Reset done"));
|
||||||
return true;
|
else
|
||||||
|
debugSerial.println(F("1WT: Bus reset error"));
|
||||||
|
//return true;
|
||||||
}
|
}
|
||||||
debugSerial.println(F("\tDS2482 reset error"));
|
else
|
||||||
return true;
|
{
|
||||||
|
i2cReset();
|
||||||
|
if (oneWire->checkPresence())
|
||||||
|
infoSerial<<F("1WT: DS2482-100 I2C restored")<<endl;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorSerial.println(F("1WT: DS2482-100 not present"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// software driver
|
// software driver
|
||||||
oneWire->reset();
|
oneWire->reset();
|
||||||
delay(500);
|
delay(500);
|
||||||
return true;
|
// return true;
|
||||||
#endif //DS2482-100
|
#endif //DS2482-100
|
||||||
|
|
||||||
#endif //1w is not disabled
|
if (!owArr) return false;
|
||||||
|
|
||||||
|
if (!sensors)
|
||||||
|
{
|
||||||
|
// Setup sensors library and resolution
|
||||||
|
sensors = new DallasTemperature(oneWire);
|
||||||
|
sensors->begin();
|
||||||
|
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
||||||
|
|
||||||
|
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
|
||||||
|
sensors->setWaitForConversion(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
aJsonObject *item = owArr->child;
|
||||||
|
DeviceAddress curDev;
|
||||||
|
while (owArr && item && SetAddr(item->name,curDev) )
|
||||||
|
{
|
||||||
|
debugSerial<<F("1WT: setup resolution ")<<item->name<<endl;
|
||||||
|
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
|
||||||
|
item=item->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
//owUpdate();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
#else //1w is not disabled
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -234,34 +225,33 @@ int sensors_loop(void) {
|
|||||||
|
|
||||||
case DS2482_ERROR_CONFIG:
|
case DS2482_ERROR_CONFIG:
|
||||||
errorSerial<<F("1WT: DS2482_ERROR_CONFIG")<<endl;
|
errorSerial<<F("1WT: DS2482_ERROR_CONFIG")<<endl;
|
||||||
oneWire->wireReset();
|
i2cReset();
|
||||||
return INTERVAL_1W;
|
break;
|
||||||
|
|
||||||
case DS2482_ERROR_TIMEOUT:
|
case DS2482_ERROR_TIMEOUT: //Busy over time
|
||||||
errorSerial<<F("1WT: 1-wire shorted")<<endl;
|
errorSerial<<F("1WT: BUSY timeout")<<endl;
|
||||||
oneWire->wireReset();
|
i2cReset();
|
||||||
return INTERVAL_1W;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errorSerial<<F("1WT: error")<<endl;
|
break;
|
||||||
oneWire->wireReset();
|
}
|
||||||
return INTERVAL_1W;
|
/*
|
||||||
|
if (!oneWire->checkPresence())
|
||||||
|
{
|
||||||
|
infoSerial.println(F("1WT: lost DS2482-100"));
|
||||||
|
i2cReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!sensors || !owArr)
|
||||||
if (!sensors)
|
{
|
||||||
{
|
errorSerial<<F("1WT: not init")<<endl;
|
||||||
// Setup sensors library and resolution
|
return INTERVAL_1W;
|
||||||
sensors = new DallasTemperature(oneWire);
|
}
|
||||||
sensors->begin();
|
|
||||||
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
|
||||||
|
|
||||||
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
|
|
||||||
sensors->setWaitForConversion(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dev2Check && owArr)
|
if (!dev2Check && owArr)
|
||||||
{
|
{
|
||||||
@@ -269,13 +259,8 @@ if (!sensors)
|
|||||||
///owUpdate(); //every check circle - scan for new devices
|
///owUpdate(); //every check circle - scan for new devices
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (si >= t_count) {
|
setupOwIdle(&owIdle);
|
||||||
owUpdate(); //every check circle - scan for new devices
|
|
||||||
si = 0;
|
|
||||||
return 8000;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
DeviceAddress curDev;
|
DeviceAddress curDev;
|
||||||
|
|
||||||
if (dev2Check && SetAddr(dev2Check->name,curDev))
|
if (dev2Check && SetAddr(dev2Check->name,curDev))
|
||||||
@@ -284,12 +269,17 @@ if (!sensors)
|
|||||||
switch (curDev[0]) {
|
switch (curDev[0]) {
|
||||||
|
|
||||||
case 0x28: // Thermomerer
|
case 0x28: // Thermomerer
|
||||||
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
|
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||||
|
|
||||||
t = sensors->getTempC(curDev);//*10.0;
|
t = sensors->getTempC(curDev);//*10.0;
|
||||||
|
//owIdle();
|
||||||
|
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||||
processTemp(dev2Check, t);
|
processTemp(dev2Check, t);
|
||||||
sensors->requestTemperaturesByAddress(curDev);
|
//owIdle();
|
||||||
|
|
||||||
|
sensors->requestTemperaturesByAddress(curDev);
|
||||||
|
//owIdle();
|
||||||
|
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||||
} //switch
|
} //switch
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,34 +298,7 @@ void owLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int owFind(DeviceAddress addr) {
|
|
||||||
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void owAdd(DeviceAddress addr) {
|
|
||||||
#ifndef OWIRE_DISABLE
|
|
||||||
infoSerial<<F("dev#")<<t_count<<F(" Addr:");
|
|
||||||
PrintBytes(term[t_count], 8,0);
|
|
||||||
infoSerial<<endl;
|
|
||||||
|
|
||||||
if (t_count>=t_max) return;
|
|
||||||
if (zero(term[t_count],8)) return;
|
|
||||||
|
|
||||||
wstat[t_count] = SW_FIND; //Newly detected
|
|
||||||
memcpy(term[t_count], addr, 8);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
|
||||||
if (term[t_count][0] == 0x28)
|
|
||||||
oneWire->setStrongPullup();
|
|
||||||
#endif
|
|
||||||
t_count++;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setupOwIdle (void (*ptr)())
|
void setupOwIdle (void (*ptr)())
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ extern uint8_t udpDebugLevel;
|
|||||||
#define SerialPortType HardwareSerial
|
#define SerialPortType HardwareSerial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LOG_TRACE 9
|
||||||
#define LOG_DEBUG 7
|
#define LOG_DEBUG 7
|
||||||
#define LOG_INFO 6
|
#define LOG_INFO 6
|
||||||
#define LOG_ERROR 3
|
#define LOG_ERROR 3
|
||||||
|
|
||||||
|
#define traceSerial if (serialDebugLevel>=LOG_TRACE || udpDebugLevel>=LOG_TRACE) debugSerial
|
||||||
class Streamlog : public Print
|
class Streamlog : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
0
lighthub/templateStr.cpp
Normal file
0
lighthub/templateStr.cpp
Normal file
110
lighthub/templateStr.h
Normal file
110
lighthub/templateStr.h
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#ifndef _TEMPLATE_STREAM_H_
|
||||||
|
#define _TEMPLATE_STREAM_H_
|
||||||
|
|
||||||
|
#include <Stream.h>
|
||||||
|
#include <aJSON.h>
|
||||||
|
#include <streamlog.h>
|
||||||
|
//#define KEYLEN 8
|
||||||
|
extern aJsonObject * topics;
|
||||||
|
|
||||||
|
class templateStream : public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
templateStream(char *s, short sfx=0) : str(s), pos(0), val(NULL), valpos(0), bucket(0),suffix(sfx) { }
|
||||||
|
|
||||||
|
// Stream methods
|
||||||
|
virtual int available() { return str[pos]; }
|
||||||
|
virtual int read() {
|
||||||
|
if (bucket)
|
||||||
|
|
||||||
|
{ int ch = bucket;
|
||||||
|
bucket=0;
|
||||||
|
return ch;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (str[pos]=='$')
|
||||||
|
{
|
||||||
|
if (str[pos+1]=='{')
|
||||||
|
{
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (str[pos+2+i] && str[pos+2+i]!='}') i++;
|
||||||
|
if (i && (str[pos+2+i]=='}'))
|
||||||
|
{
|
||||||
|
str[pos+2+i]='\0';
|
||||||
|
val=resolveKey(str+pos+2);
|
||||||
|
valpos=0;
|
||||||
|
str[pos+2+i]='}';
|
||||||
|
pos+=3+i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val)
|
||||||
|
{
|
||||||
|
char ch = val[valpos];
|
||||||
|
if (ch)
|
||||||
|
{
|
||||||
|
valpos++;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
else val = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
char ch = str[pos];
|
||||||
|
if (ch)
|
||||||
|
{
|
||||||
|
pos++;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str=NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual int peek()
|
||||||
|
{
|
||||||
|
int bucket = read();
|
||||||
|
return bucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void flush() { };
|
||||||
|
// Print methods
|
||||||
|
virtual size_t write(uint8_t c) { return 0; };
|
||||||
|
virtual char * resolveKey(char *key)
|
||||||
|
{
|
||||||
|
if (topics && topics->type == aJson_Object)
|
||||||
|
{
|
||||||
|
aJsonObject *valObj = aJson.getObjectItem(topics, key);
|
||||||
|
if (valObj->type == aJson_String) return valObj->valuestring;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (suffix && (suffix<suffixNum) && !strcmp(key,"sfx"))
|
||||||
|
{
|
||||||
|
//debugSerial<<F("Template: Suffix=")<<suffix<<endl;
|
||||||
|
buffer[0]='/';
|
||||||
|
strncpy_P(buffer+1,suffix_P[suffix],sizeof(buffer)-2);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char *str;
|
||||||
|
unsigned int pos;
|
||||||
|
char *val;
|
||||||
|
unsigned int valpos;
|
||||||
|
int bucket;
|
||||||
|
short suffix;
|
||||||
|
char buffer[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _TEMPLATE_STREAM_H_
|
||||||
@@ -82,17 +82,29 @@ const char on_P[] PROGMEM = "on";
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define ON_P commands_P[CMD_ON]
|
||||||
|
#define OFF_P commands_P[CMD_OFF]
|
||||||
|
#define REST_P commands_P[CMD_RESTORE]
|
||||||
|
#define TOGGLE_P commands_P[CMD_TOGGLE]
|
||||||
|
#define HALT_P commands_P[CMD_HALT]
|
||||||
|
#define XON_P commands_P[CMD_XON]
|
||||||
|
#define XOFF_P commands_P[CMD_XOFF]
|
||||||
|
#define HEAT_P commands_P[CMD_HEAT]
|
||||||
|
#define COOL_P commands_P[CMD_COOL]
|
||||||
|
#define AUTO_P commands_P[CMD_AUTO]
|
||||||
|
#define FAN_ONLY_P commands_P[CMD_FAN]
|
||||||
|
#define DRY_P commands_P[CMD_DRY]
|
||||||
|
#define HIGH_P commands_P[CMD_HIGH]
|
||||||
|
#define MED_P commands_P[CMD_MED]
|
||||||
|
#define LOW_P commands_P[CMD_LOW]
|
||||||
|
#define ENABLE_P commands_P[CMD_ENABLE]
|
||||||
|
#define DISABLE_P commands_P[CMD_DISABLE]
|
||||||
|
#define FREEZE_P commands_P[CMD_FREEZE]
|
||||||
|
#define UNFREEZE_P commands_P[CMD_UNFREEZE]
|
||||||
|
|
||||||
|
const char ERROR_P[] PROGMEM = "ERR";
|
||||||
|
|
||||||
//Commands
|
//Commands
|
||||||
|
|
||||||
const char ON_P[] PROGMEM = "ON";
|
|
||||||
const char OFF_P[] PROGMEM = "OFF";
|
|
||||||
const char REST_P[] PROGMEM = "REST";
|
|
||||||
const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
|
||||||
const char HALT_P[] PROGMEM = "HALT";
|
|
||||||
const char XON_P[] PROGMEM = "XON";
|
|
||||||
const char XOFF_P[] PROGMEM = "XOFF";
|
|
||||||
/*
|
/*
|
||||||
const char INCREASE_P[] PROGMEM = "INCREASE";
|
const char INCREASE_P[] PROGMEM = "INCREASE";
|
||||||
const char DECREASE_P[] PROGMEM = "DECREASE";
|
const char DECREASE_P[] PROGMEM = "DECREASE";
|
||||||
@@ -102,6 +114,15 @@ const char FALSE_P[] PROGMEM = "FALSE";
|
|||||||
const char ENABLED_P[] PROGMEM = "ENABLED";
|
const char ENABLED_P[] PROGMEM = "ENABLED";
|
||||||
const char DISABLED_P[] PROGMEM = "DISABLED";
|
const char DISABLED_P[] PROGMEM = "DISABLED";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const char ON_P[] PROGMEM = "ON";
|
||||||
|
const char OFF_P[] PROGMEM = "OFF";
|
||||||
|
const char REST_P[] PROGMEM = "REST";
|
||||||
|
const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
||||||
|
const char HALT_P[] PROGMEM = "HALT";
|
||||||
|
const char XON_P[] PROGMEM = "XON";
|
||||||
|
const char XOFF_P[] PROGMEM = "XOFF";
|
||||||
const char HEAT_P[] PROGMEM = "HEAT";
|
const char HEAT_P[] PROGMEM = "HEAT";
|
||||||
const char COOL_P[] PROGMEM = "COOL";
|
const char COOL_P[] PROGMEM = "COOL";
|
||||||
const static char AUTO_P[] PROGMEM = "AUTO";
|
const static char AUTO_P[] PROGMEM = "AUTO";
|
||||||
@@ -112,13 +133,15 @@ const char DRY_P[] PROGMEM = "DRY";
|
|||||||
const char HIGH_P[] PROGMEM = "HIGH";
|
const char HIGH_P[] PROGMEM = "HIGH";
|
||||||
const char MED_P[] PROGMEM = "MEDIUM";
|
const char MED_P[] PROGMEM = "MEDIUM";
|
||||||
const char LOW_P[] PROGMEM = "LOW";
|
const char LOW_P[] PROGMEM = "LOW";
|
||||||
const char ERROR_P[] PROGMEM = "ERR";
|
|
||||||
const char ENABLE_P[] PROGMEM = "ENABLE";
|
const char ENABLE_P[] PROGMEM = "ENABLE";
|
||||||
const char DISABLE_P[] PROGMEM = "DISABLE";
|
const char DISABLE_P[] PROGMEM = "DISABLE";
|
||||||
const char FREEZE_P[] PROGMEM = "FREEZE";
|
const char FREEZE_P[] PROGMEM = "FREEZE";
|
||||||
const char UNFREEZE_P[] PROGMEM = "UNFREEZE";
|
const char UNFREEZE_P[] PROGMEM = "UNFREEZE";
|
||||||
|
*/
|
||||||
|
|
||||||
// SubTopics
|
// SubTopics
|
||||||
|
/*
|
||||||
const char SET_P[] PROGMEM = "set";
|
const char SET_P[] PROGMEM = "set";
|
||||||
const char CMD_P[] PROGMEM = "cmd";
|
const char CMD_P[] PROGMEM = "cmd";
|
||||||
const char MODE_P[] PROGMEM = "mode";
|
const char MODE_P[] PROGMEM = "mode";
|
||||||
@@ -132,7 +155,7 @@ const char VAL_P[] PROGMEM = "val";
|
|||||||
const char DEL_P[] PROGMEM = "del";
|
const char DEL_P[] PROGMEM = "del";
|
||||||
const char _RAW_P[] PROGMEM = "raw";
|
const char _RAW_P[] PROGMEM = "raw";
|
||||||
const char CTRL_P[] PROGMEM = "ctrl";
|
const char CTRL_P[] PROGMEM = "ctrl";
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
const char RPM_P[] PROGMEM = "rpm";
|
const char RPM_P[] PROGMEM = "rpm";
|
||||||
const char STATE_P[] PROGMEM = "state";
|
const char STATE_P[] PROGMEM = "state";
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
#include "templateStr.h"
|
||||||
|
|
||||||
#ifdef CRYPT
|
#ifdef CRYPT
|
||||||
#include "SHA256.h"
|
#include "SHA256.h"
|
||||||
@@ -690,8 +691,22 @@ switch (cmdType)
|
|||||||
//else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
//else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
|
||||||
char * emitCommand;
|
char * emitCommand;
|
||||||
|
short suffix=0;
|
||||||
|
// aJsonObject * dict=NULL;
|
||||||
|
|
||||||
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
||||||
else emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
else
|
||||||
|
{
|
||||||
|
emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer));
|
||||||
|
// dict = aJson.createObject();
|
||||||
|
// aJson.addStringToObject(dict, "sfx", )
|
||||||
|
suffix=_itemCmd.getSuffix();
|
||||||
|
if (!suffix)
|
||||||
|
{
|
||||||
|
if (_itemCmd.isCommand()) suffix=S_CMD;
|
||||||
|
else if (_itemCmd.isValue()) suffix = S_SET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
||||||
if (item) {
|
if (item) {
|
||||||
@@ -705,7 +720,12 @@ switch (cmdType)
|
|||||||
|
|
||||||
|
|
||||||
if (emit && emitCommand && emit->type == aJson_String) {
|
if (emit && emitCommand && emit->type == aJson_String) {
|
||||||
debugSerial << F("Emit: ")<<emit->valuestring<< F(" -> ")<<emitCommand<<endl;
|
|
||||||
|
templateStream ts(emit->valuestring,suffix);
|
||||||
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
|
//ts.setTimeout(0);
|
||||||
|
addrstr[ts.readBytesUntil('\0',addrstr,sizeof(addrstr))]='\0';
|
||||||
|
debugSerial << F("Emit: <")<<emit->valuestring<<"> "<<addrstr<< F(" -> ")<<emitCommand<<endl;
|
||||||
/*
|
/*
|
||||||
TODO implement
|
TODO implement
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
@@ -720,8 +740,8 @@ switch (cmdType)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
char addrstr[MQTT_TOPIC_LENGTH];
|
|
||||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
//strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
{
|
{
|
||||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
@@ -876,5 +896,51 @@ bool checkToken(char * token, char * data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool i2cReset(){
|
||||||
|
debugSerial.println(F("I2C Reset"));
|
||||||
|
|
||||||
|
Wire.endTransmission(true);
|
||||||
|
#if !defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
Wire.end();
|
||||||
|
#endif
|
||||||
|
pinMode(SCL,OUTPUT);
|
||||||
|
pinMode(SDA,INPUT);
|
||||||
|
//10 сигналов клок
|
||||||
|
bool pulse=false;
|
||||||
|
for (int i=0; i<20;i++) {
|
||||||
|
//i2c_scl_toggle(i2c);
|
||||||
|
digitalWrite(SCL,pulse?HIGH:LOW);
|
||||||
|
pulse=!pulse;
|
||||||
|
delay(10);//10us мкс
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(20);
|
||||||
|
Wire.begin();
|
||||||
|
|
||||||
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
|
if (oneWire && oneWire->checkPresence())
|
||||||
|
{
|
||||||
|
oneWire->deviceReset();
|
||||||
|
debugSerial.println(F("1WT: DS2482 present, reset"));
|
||||||
|
#ifndef APU_OFF
|
||||||
|
oneWire->setActivePullup();
|
||||||
|
#endif
|
||||||
|
if (oneWire->wireReset())
|
||||||
|
debugSerial.println(F("1WT: Bus Reset done"));
|
||||||
|
else
|
||||||
|
debugSerial.println(F("1WT: Bus reset error"));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||||
|
|||||||
@@ -79,3 +79,5 @@ bool getPinVal(uint8_t pin);
|
|||||||
int str2regSize(char * str);
|
int str2regSize(char * str);
|
||||||
bool checkToken(char * token, char * data);
|
bool checkToken(char * token, char * data);
|
||||||
bool isProtectedPin(short pin);
|
bool isProtectedPin(short pin);
|
||||||
|
bool i2cReset();
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ src_dir = lighthub
|
|||||||
default_envs =
|
default_envs =
|
||||||
; ****** UNCOMMENT single environment name for target platform below *******
|
; ****** UNCOMMENT single environment name for target platform below *******
|
||||||
|
|
||||||
; Arduino Mega compact build + Ethernet shield Wiznet 5100, 1-wire, thermostates.
|
; Arduino Mega compact build + Ethernet shield Wiznet 5X00, 1-wire, thermostates.
|
||||||
; Without DMX, Wiznet 5100 network driver
|
; Without DMX, Wiznet network driver
|
||||||
; mega2560slim-5100
|
; mega2560slim
|
||||||
|
|
||||||
; Another Arduino Mega compact build without 1-wire, DMX, but with OTA
|
; Another Arduino Mega compact build without 1-wire, DMX, but with OTA
|
||||||
; OPTIBOOT bootloader required! https://github.com/MCUdude/MegaCore
|
; OPTIBOOT bootloader required! https://github.com/MCUdude/MegaCore
|
||||||
@@ -328,13 +328,13 @@ lib_deps =
|
|||||||
rweather/Crypto
|
rweather/Crypto
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
[env:mega2560slim-5100]
|
[env:mega2560slim]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = megaatmega2560
|
board = megaatmega2560
|
||||||
upload_port = net:192.168.88.2:23000
|
upload_port = net:192.168.88.2:23000
|
||||||
_upload_command = custom-build-flags/upload_mega2560slim-5100 $SOURCE
|
_upload_command = custom-build-flags/upload_mega2560slim $SOURCE
|
||||||
framework = arduino
|
framework = arduino
|
||||||
build_flags = !python get_build_flags.py mega2560slim-5100
|
build_flags = !python get_build_flags.py mega2560slim
|
||||||
extra_scripts = post:toBin.py
|
extra_scripts = post:toBin.py
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
||||||
@@ -369,8 +369,9 @@ lib_deps =
|
|||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
;https://github.com/anklimov/ModbusMaster
|
;https://github.com/anklimov/ModbusMaster
|
||||||
;https://github.com/anklimov/DMXSerial
|
;https://github.com/anklimov/DMXSerial
|
||||||
https://github.com/anklimov/Ethernet5100
|
;https://github.com/anklimov/Ethernet5100
|
||||||
;5100 lib have ~90 bytes less footprint of RAM
|
;5100 lib have ~90 bytes less footprint of RAM
|
||||||
|
https://github.com/anklimov/Ethernet.git
|
||||||
https://github.com/anklimov/pubsubclient.git
|
https://github.com/anklimov/pubsubclient.git
|
||||||
;https://github.com/anklimov/Artnet.git
|
;https://github.com/anklimov/Artnet.git
|
||||||
;FastLED@3.3.2
|
;FastLED@3.3.2
|
||||||
|
|||||||
Reference in New Issue
Block a user