mirror of
https://github.com/anklimov/lighthub
synced 2025-12-09 13:19:50 +03:00
refactoring. help cmd improved. Removed newline from freeMem periodical print.
This commit is contained in:
@@ -23,7 +23,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
extern PubSubClient client;
|
extern PubSubClient mqttClient;
|
||||||
|
|
||||||
Input::Input(char * name) //Constructor
|
Input::Input(char * name) //Constructor
|
||||||
{
|
{
|
||||||
@@ -121,11 +121,11 @@ void Input::Changed (int val)
|
|||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
{ //send set command
|
{ //send set command
|
||||||
if (!scmd) client.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) client.publish(emit->valuestring,scmd->valuestring);
|
if (!scmd) mqttClient.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) mqttClient.publish(emit->valuestring,scmd->valuestring);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //send reset command
|
{ //send reset command
|
||||||
if (!rcmd) client.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) client.publish(emit->valuestring,rcmd->valuestring);
|
if (!rcmd) mqttClient.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) mqttClient.publish(emit->valuestring,rcmd->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ e-mail anklimov@gmail.com
|
|||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
|
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
@@ -37,15 +39,15 @@ extern aJsonObject * modbusitem;
|
|||||||
|
|
||||||
|
|
||||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
||||||
extern PubSubClient client;
|
|
||||||
|
extern PubSubClient mqttClient;
|
||||||
//extern const char* outprefix;
|
//extern const char* outprefix;
|
||||||
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
||||||
|
|
||||||
static unsigned long lastctrl = 0;
|
static unsigned long lastctrl = 0;
|
||||||
static aJsonObject *lastobj = NULL;
|
static aJsonObject *lastobj = NULL;
|
||||||
|
|
||||||
int txt2cmd (char * payload)
|
int txt2cmd(char *payload) {
|
||||||
{
|
|
||||||
int cmd = -1;
|
int cmd = -1;
|
||||||
|
|
||||||
// Check for command
|
// Check for command
|
||||||
@@ -68,12 +70,12 @@ Item::Item(aJsonObject * obj)//Constructor
|
|||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::Parse()
|
void Item::Parse() {
|
||||||
{
|
if (isValid()) {
|
||||||
if (isValid())
|
|
||||||
{
|
|
||||||
// Todo - avoid static enlarge for every types
|
// Todo - avoid static enlarge for every types
|
||||||
for (int i=aJson.getArraySize(itemArr);i<4;i++) aJson.addItemToArray(itemArr,aJson.createItem(int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
for (int i = aJson.getArraySize(itemArr); i < 4; i++)
|
||||||
|
aJson.addItemToArray(itemArr, aJson.createItem(
|
||||||
|
int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
||||||
|
|
||||||
|
|
||||||
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
|
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
|
||||||
@@ -82,8 +84,11 @@ void Item::Parse()
|
|||||||
|
|
||||||
|
|
||||||
Serial.print(F(" Item:"));
|
Serial.print(F(" Item:"));
|
||||||
Serial.print(itemArr->name);Serial.print(F(" T:"));
|
Serial.print(itemArr->name);
|
||||||
Serial.print(itemType);Serial.print(F(" ="));Serial.println(getArg());
|
Serial.print(F(" T:"));
|
||||||
|
Serial.print(itemType);
|
||||||
|
Serial.print(F(" ="));
|
||||||
|
Serial.println(getArg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +101,7 @@ Item::Item(char * name) //Constructor
|
|||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Item::getCmd()
|
uint8_t Item::getCmd() {
|
||||||
{
|
|
||||||
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
|
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
|
||||||
if (t)
|
if (t)
|
||||||
return t->valueint;
|
return t->valueint;
|
||||||
@@ -105,19 +109,20 @@ uint8_t Item::getCmd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item::setCmd(uint8_t cmd)
|
void Item::setCmd(uint8_t cmd) {
|
||||||
{
|
|
||||||
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
|
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
|
||||||
if (t)
|
if (t)
|
||||||
t->valueint = cmd;
|
t->valueint = cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::getArg(short n) //Return arg int or first array element if Arg is array
|
int Item::getArg(short n) //Return arg int or first array element if Arg is array
|
||||||
{ if (!itemArg) return -1;
|
{
|
||||||
|
if (!itemArg) return -1;
|
||||||
if (itemArg->type == aJson_Int) return itemArg->valueint;
|
if (itemArg->type == aJson_Int) return itemArg->valueint;
|
||||||
else if (itemArg->type == aJson_Array) return aJson.getArrayItem(itemArg, n)->valueint;
|
else if (itemArg->type == aJson_Array) return aJson.getArrayItem(itemArg, n)->valueint;
|
||||||
else return -2;
|
else return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int Item::getVal(short n) //Return Val from Value array
|
int Item::getVal(short n) //Return Val from Value array
|
||||||
{ if (!itemVal) return -1;
|
{ if (!itemVal) return -1;
|
||||||
@@ -132,16 +137,16 @@ int Item::getVal(short n) //Return Val from Value array
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
long int Item::getVal() //Return Val if val is int or first elem of Value array
|
long int Item::getVal() //Return Val if val is int or first elem of Value array
|
||||||
{ if (!itemVal) return -1;
|
|
||||||
if (itemVal->type==aJson_Int) return itemVal->valueint;
|
|
||||||
else if (itemVal->type==aJson_Array)
|
|
||||||
{
|
{
|
||||||
|
if (!itemVal) return -1;
|
||||||
|
if (itemVal->type == aJson_Int) return itemVal->valueint;
|
||||||
|
else if (itemVal->type == aJson_Array) {
|
||||||
aJsonObject *t = aJson.getArrayItem(itemVal, 0);
|
aJsonObject *t = aJson.getArrayItem(itemVal, 0);
|
||||||
if (t) return t->valueint;
|
if (t) return t->valueint;
|
||||||
else return -3;
|
else return -3;
|
||||||
|
} else return -2;
|
||||||
}
|
}
|
||||||
else return -2;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
void Item::setVal(short n, int par) // Only store if VAL is array defined in config to avoid waste of RAM
|
void Item::setVal(short n, int par) // Only store if VAL is array defined in config to avoid waste of RAM
|
||||||
{
|
{
|
||||||
@@ -157,13 +162,14 @@ void Item::setVal(short n, int par) // Only store if VAL is array defined in c
|
|||||||
void Item::setVal(long int par) // Only store if VAL is int (autogenerated or config-defined)
|
void Item::setVal(long int par) // Only store if VAL is int (autogenerated or config-defined)
|
||||||
{
|
{
|
||||||
if (!itemVal || itemVal->type != aJson_Int) return;
|
if (!itemVal || itemVal->type != aJson_Int) return;
|
||||||
Serial.print(F(" Store "));Serial.print(F(" Val="));Serial.println(par);
|
Serial.print(F(" Store "));
|
||||||
|
Serial.print(F(" Val="));
|
||||||
|
Serial.println(par);
|
||||||
itemVal->valueint = par;
|
itemVal->valueint = par;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean Item::isValid ()
|
boolean Item::isValid() {
|
||||||
{
|
|
||||||
return (itemArr && (itemArr->type == aJson_Array));
|
return (itemArr && (itemArr->type == aJson_Array));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,15 +191,14 @@ void analogWrite(int pin, int val)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
boolean Item::getEnableCMD(int delta)
|
boolean Item::getEnableCMD(int delta) {
|
||||||
{
|
|
||||||
return ((millis() - lastctrl > (unsigned long) delta));//|| (itemArr!=lastobj));
|
return ((millis() - lastctrl > (unsigned long) delta));//|| (itemArr!=lastobj));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
int Item::Ctrl(short cmd, short n, int *Par, boolean send) {
|
||||||
{
|
|
||||||
|
|
||||||
Serial.print(F("Cmd="));Serial.println(cmd);
|
Serial.print(F("Cmd="));
|
||||||
|
Serial.println(cmd);
|
||||||
//va_list vl;
|
//va_list vl;
|
||||||
|
|
||||||
int _Par[3] = {0, 0, 0};
|
int _Par[3] = {0, 0, 0};
|
||||||
@@ -205,19 +210,19 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
int t;
|
int t;
|
||||||
case CMD_TOGGLE:
|
case CMD_TOGGLE:
|
||||||
if (isActive()) cmd=CMD_OFF; else cmd=CMD_ON;
|
if (isActive()) cmd = CMD_OFF;
|
||||||
|
else cmd = CMD_ON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_RESTORE:
|
case CMD_RESTORE:
|
||||||
if (itemType != CH_GROUP) //individual threating of channels. Ignore restore command for groups
|
if (itemType != CH_GROUP) //individual threating of channels. Ignore restore command for groups
|
||||||
switch (t=getCmd())
|
switch (t = getCmd()) {
|
||||||
{
|
|
||||||
case CMD_HALT: //previous command was HALT ?
|
case CMD_HALT: //previous command was HALT ?
|
||||||
Serial.print(F("Restored from:"));Serial.println(t);
|
Serial.print(F("Restored from:"));
|
||||||
|
Serial.println(t);
|
||||||
cmd = CMD_ON; //turning on
|
cmd = CMD_ON; //turning on
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -225,14 +230,12 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
}//switch old cmd
|
}//switch old cmd
|
||||||
} //switch cmd
|
} //switch cmd
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case 0: //no command
|
case 0: //no command
|
||||||
|
|
||||||
setCmd(CMD_SET);
|
setCmd(CMD_SET);
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType) {
|
||||||
{
|
|
||||||
|
|
||||||
case CH_RGBW: //only if configured VAL array
|
case CH_RGBW: //only if configured VAL array
|
||||||
if (!Par[1]) itemType = CH_WHITE;
|
if (!Par[1]) itemType = CH_WHITE;
|
||||||
@@ -262,16 +265,13 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
if (getCmd()!=CMD_ON)
|
if (getCmd() != CMD_ON) {
|
||||||
|
|
||||||
{
|
|
||||||
short params = 0;
|
short params = 0;
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
st.aslong = getVal();
|
st.aslong = getVal();
|
||||||
if (st.aslong > 0) //Stored smthng
|
if (st.aslong > 0) //Stored smthng
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType) {
|
||||||
{
|
|
||||||
//case CH_GROUP:
|
//case CH_GROUP:
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
case CH_RGB:
|
case CH_RGB:
|
||||||
@@ -301,13 +301,11 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
default:
|
default:
|
||||||
SendCmd(cmd); // Just send ON
|
SendCmd(cmd); // Just send ON
|
||||||
}//itemtype
|
}//itemtype
|
||||||
else
|
else {// Default settings
|
||||||
{// Default settings
|
|
||||||
Serial.print(st.aslong);
|
Serial.print(st.aslong);
|
||||||
Serial.println(F(": No stored values - default"));
|
Serial.println(F(": No stored values - default"));
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType) {
|
||||||
{
|
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
Par[0] = 20;
|
Par[0] = 20;
|
||||||
break;
|
break;
|
||||||
@@ -319,18 +317,17 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (short i=0;i<params ;i++)
|
for (short i = 0; i < params; i++) {
|
||||||
{
|
Serial.print(F("Restored: "));
|
||||||
Serial.print(F("Restored: "));Serial.print(i);Serial.print(F("="));Serial.println(Par[i]);
|
Serial.print(i);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.println(Par[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
}
|
} else { //Double ON - apply special preset - clean white full power
|
||||||
else
|
switch (itemType) {
|
||||||
{ //Double ON - apply special preset - clean white full power
|
|
||||||
switch (itemType)
|
|
||||||
{
|
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
Serial.println(F("Force White"));
|
Serial.println(F("Force White"));
|
||||||
itemType = CH_WHITE;
|
itemType = CH_WHITE;
|
||||||
@@ -358,7 +355,9 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
if (getCmd() != CMD_HALT) //if channels are halted - OFF to be ignored (restore issue)
|
if (getCmd() != CMD_HALT) //if channels are halted - OFF to be ignored (restore issue)
|
||||||
{
|
{
|
||||||
Par[0]=0;Par[1]=0;Par[2]=0;
|
Par[0] = 0;
|
||||||
|
Par[1] = 0;
|
||||||
|
Par[2] = 0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
SendCmd(cmd);
|
SendCmd(cmd);
|
||||||
}
|
}
|
||||||
@@ -366,9 +365,10 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
|
|
||||||
if (isActive()>0)
|
if (isActive() > 0) {
|
||||||
{
|
Par[0] = 0;
|
||||||
Par[0]=0;Par[1]=0;Par[2]=0;
|
Par[1] = 0;
|
||||||
|
Par[2] = 0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
SendCmd(CMD_OFF);
|
SendCmd(CMD_OFF);
|
||||||
Serial.println(F(" Halted"));
|
Serial.println(F(" Halted"));
|
||||||
@@ -380,8 +380,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType) {
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
case CH_DIMMER: //Dimmed light
|
case CH_DIMMER: //Dimmed light
|
||||||
@@ -395,7 +394,8 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
DmxWrite(iaddr + 3, k = map((100 - Par[1]) * Par[2], 0, 10000, 0, 255));
|
DmxWrite(iaddr + 3, k = map((100 - Par[1]) * Par[2], 0, 10000, 0, 255));
|
||||||
Serial.print(F("W:"));Serial.println(k);
|
Serial.print(F("W:"));
|
||||||
|
Serial.println(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -411,7 +411,8 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
DmxWrite(iaddr + 2, rgb.b);
|
DmxWrite(iaddr + 2, rgb.b);
|
||||||
|
|
||||||
|
|
||||||
break; }
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case CH_WHITE:
|
case CH_WHITE:
|
||||||
@@ -423,28 +424,25 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
case CH_MODBUS:
|
case CH_MODBUS: {
|
||||||
{
|
|
||||||
|
|
||||||
if ((itemArg->type == aJson_Array) && (aJson.getArraySize(itemArg)==3))
|
if ((itemArg->type == aJson_Array) && (aJson.getArraySize(itemArg) == 3)) {
|
||||||
{
|
|
||||||
int _addr = aJson.getArrayItem(itemArg, 0)->valueint;
|
int _addr = aJson.getArrayItem(itemArg, 0)->valueint;
|
||||||
int _reg = aJson.getArrayItem(itemArg, 1)->valueint;
|
int _reg = aJson.getArrayItem(itemArg, 1)->valueint;
|
||||||
int _mask = aJson.getArrayItem(itemArg, 2)->valueint;
|
int _mask = aJson.getArrayItem(itemArg, 2)->valueint;
|
||||||
|
|
||||||
modbusSet(_addr, _reg, _mask, map(Par[0], 0, 100, 0, 0x3f));
|
modbusSet(_addr, _reg, _mask, map(Par[0], 0, 100, 0, 0x3f));
|
||||||
}
|
}
|
||||||
break;}
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case CH_GROUP://Group
|
case CH_GROUP://Group
|
||||||
{
|
{
|
||||||
//aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
//aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
||||||
if (itemArg->type==aJson_Array)
|
if (itemArg->type == aJson_Array) {
|
||||||
{
|
|
||||||
aJsonObject *i = itemArg->child;
|
aJsonObject *i = itemArg->child;
|
||||||
while (i)
|
while (i) {
|
||||||
{
|
|
||||||
Item it(i->valuestring);
|
Item it(i->valuestring);
|
||||||
// it.copyPar(itemVal);
|
// it.copyPar(itemVal);
|
||||||
it.Ctrl(cmd, n, Par, send); //// was true
|
it.Ctrl(cmd, n, Par, send); //// was true
|
||||||
@@ -453,20 +451,26 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
} //if
|
} //if
|
||||||
} //case
|
} //case
|
||||||
break;
|
break;
|
||||||
case CH_RELAY:
|
case CH_RELAY: {
|
||||||
{int k;
|
int k;
|
||||||
pinMode(iaddr, OUTPUT);
|
pinMode(iaddr, OUTPUT);
|
||||||
digitalWrite(iaddr, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
digitalWrite(iaddr, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||||
Serial.print(F("Pin:"));Serial.print(iaddr);Serial.print(F("="));Serial.println(k);
|
Serial.print(F("Pin:"));
|
||||||
|
Serial.print(iaddr);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.println(k);
|
||||||
break;
|
break;
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
///thermoSet(name,cmd,Par1); all cativities done - update temp & cmd
|
///thermoSet(name,cmd,Par1); all cativities done - update temp & cmd
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CH_PWM:
|
case CH_PWM: {
|
||||||
{int k;
|
int k;
|
||||||
short inverse = 0;
|
short inverse = 0;
|
||||||
if (iaddr<0) {iaddr=-iaddr;inverse=1;}
|
if (iaddr < 0) {
|
||||||
|
iaddr = -iaddr;
|
||||||
|
inverse = 1;
|
||||||
|
}
|
||||||
pinMode(iaddr, OUTPUT);
|
pinMode(iaddr, OUTPUT);
|
||||||
//timer 0 for pin 13 and 4
|
//timer 0 for pin 13 and 4
|
||||||
//timer 1 for pin 12 and 11
|
//timer 1 for pin 12 and 11
|
||||||
@@ -490,7 +494,10 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
if (inverse) k = map(Par[0], 100, 0, 0, 255);
|
if (inverse) k = map(Par[0], 100, 0, 0, 255);
|
||||||
else k = map(Par[0], 0, 100, 0, 255);
|
else k = map(Par[0], 0, 100, 0, 255);
|
||||||
analogWrite(iaddr, k);
|
analogWrite(iaddr, k);
|
||||||
Serial.print(F("Pin:"));Serial.print(iaddr);Serial.print(F("="));Serial.println(k);
|
Serial.print(F("Pin:"));
|
||||||
|
Serial.print(iaddr);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.println(k);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -500,8 +507,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP: {
|
||||||
{
|
|
||||||
Item it(itemArg->valuestring);
|
Item it(itemArg->valuestring);
|
||||||
if (it.isValid() && it.itemType == CH_VC)
|
if (it.isValid() && it.itemType == CH_VC)
|
||||||
VacomSetHeat(it.getArg(), Par[0], cmd);
|
VacomSetHeat(it.getArg(), Par[0], cmd);
|
||||||
@@ -516,8 +522,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::isActive()
|
int Item::isActive() {
|
||||||
{
|
|
||||||
HSVstore st;
|
HSVstore st;
|
||||||
int val = 0;
|
int val = 0;
|
||||||
|
|
||||||
@@ -529,8 +534,7 @@ int cmd=getCmd();
|
|||||||
|
|
||||||
if (itemType != CH_GROUP)
|
if (itemType != CH_GROUP)
|
||||||
// Simple check last command first
|
// Simple check last command first
|
||||||
switch (cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
//Serial.println(" active");
|
//Serial.println(" active");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -544,18 +548,18 @@ switch (cmd)
|
|||||||
// Last time was not a command but parameters set. Looking inside
|
// Last time was not a command but parameters set. Looking inside
|
||||||
st.aslong = getVal();
|
st.aslong = getVal();
|
||||||
|
|
||||||
switch (itemType)
|
switch (itemType) {
|
||||||
{
|
|
||||||
case CH_GROUP: //make recursive calculation - is it some active in group
|
case CH_GROUP: //make recursive calculation - is it some active in group
|
||||||
if (itemArg->type==aJson_Array)
|
if (itemArg->type == aJson_Array) {
|
||||||
{
|
|
||||||
Serial.println(F("Grp check: "));
|
Serial.println(F("Grp check: "));
|
||||||
aJsonObject *i = itemArg->child;
|
aJsonObject *i = itemArg->child;
|
||||||
while (i)
|
while (i) {
|
||||||
{
|
|
||||||
Item it(i->valuestring);
|
Item it(i->valuestring);
|
||||||
|
|
||||||
if (it.isValid() && it.isActive()) {Serial.println(F("Active")); return 1;}
|
if (it.isValid() && it.isActive()) {
|
||||||
|
Serial.println(F("Active"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
i = i->next;
|
i = i->next;
|
||||||
} //while
|
} //while
|
||||||
return 0;
|
return 0;
|
||||||
@@ -577,7 +581,8 @@ switch (itemType)
|
|||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
val = st.aslong;
|
val = st.aslong;
|
||||||
} //switch
|
} //switch
|
||||||
Serial.print(F(":="));Serial.println(val);
|
Serial.print(F(":="));
|
||||||
|
Serial.println(val);
|
||||||
if (val) return 1; else return 0;
|
if (val) return 1; else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,21 +653,25 @@ POOL 2101x10
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void mb_fail(short addr, short op, int val, int cmd)
|
void mb_fail(short addr, short op, int val, int cmd) {
|
||||||
{
|
|
||||||
Serial.println(F("Modbus op failed"));
|
Serial.println(F("Modbus op failed"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern ModbusMaster node;
|
extern ModbusMaster node;
|
||||||
|
|
||||||
int Item::VacomSetFan (int8_t val, int8_t cmd)
|
int Item::VacomSetFan(int8_t val, int8_t cmd) {
|
||||||
{
|
|
||||||
int addr = getArg();
|
int addr = getArg();
|
||||||
Serial.print(F("VC#"));Serial.print(addr);Serial.print(F("="));Serial.println(val);
|
Serial.print(F("VC#"));
|
||||||
|
Serial.print(addr);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.println(val);
|
||||||
|
|
||||||
|
|
||||||
if (modbusBusy) {mb_fail(1,addr,val,cmd);return -1;}
|
if (modbusBusy) {
|
||||||
|
mb_fail(1, addr, val, cmd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
|
|
||||||
uint8_t j, result;
|
uint8_t j, result;
|
||||||
@@ -674,8 +683,7 @@ node.begin(addr,modbusSerial);
|
|||||||
if (val) {
|
if (val) {
|
||||||
node.writeSingleRegister(2001 - 1, 4 + 1);//delay(500);
|
node.writeSingleRegister(2001 - 1, 4 + 1);//delay(500);
|
||||||
//node.writeSingleRegister(2001-1,1);
|
//node.writeSingleRegister(2001-1,1);
|
||||||
}
|
} else node.writeSingleRegister(2001 - 1, 0);
|
||||||
else node.writeSingleRegister(2001-1,0);
|
|
||||||
delay(50);
|
delay(50);
|
||||||
node.writeSingleRegister(2003 - 1, val * 100);
|
node.writeSingleRegister(2003 - 1, val * 100);
|
||||||
|
|
||||||
@@ -686,11 +694,18 @@ node.begin(addr,modbusSerial);
|
|||||||
#define a 0.1842
|
#define a 0.1842
|
||||||
#define b -36.68
|
#define b -36.68
|
||||||
|
|
||||||
int Item::VacomSetHeat(int addr,int8_t val, int8_t cmd)
|
int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) {
|
||||||
{
|
|
||||||
|
|
||||||
Serial.print(F("VC_heat#"));Serial.print(addr);Serial.print(F("="));Serial.print(val);Serial.print(F(" cmd="));Serial.println(cmd);
|
Serial.print(F("VC_heat#"));
|
||||||
if (modbusBusy) {mb_fail(2,addr,val,cmd);return -1;}
|
Serial.print(addr);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.print(val);
|
||||||
|
Serial.print(F(" cmd="));
|
||||||
|
Serial.println(cmd);
|
||||||
|
if (modbusBusy) {
|
||||||
|
mb_fail(2, addr, val, cmd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
|
|
||||||
modbusSerial.begin(9600, fmPar);
|
modbusSerial.begin(9600, fmPar);
|
||||||
@@ -698,8 +713,7 @@ node.begin(addr,modbusSerial);
|
|||||||
|
|
||||||
uint16_t regval;
|
uint16_t regval;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case CMD_OFF:
|
case CMD_OFF:
|
||||||
case CMD_HALT:
|
case CMD_HALT:
|
||||||
regval = 0;
|
regval = 0;
|
||||||
@@ -715,8 +729,7 @@ node.begin(addr,modbusSerial);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Item::SendCmd(short cmd,short n, int * Par)
|
int Item::SendCmd(short cmd, short n, int *Par) {
|
||||||
{
|
|
||||||
|
|
||||||
/// ToDo: relative patches, configuration
|
/// ToDo: relative patches, configuration
|
||||||
|
|
||||||
@@ -728,8 +741,7 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
strncat(addrstr, itemArr->name, sizeof(addrstr)); ////
|
strncat(addrstr, itemArr->name, sizeof(addrstr)); ////
|
||||||
|
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
strcpy(valstr, "ON");
|
strcpy(valstr, "ON");
|
||||||
break;
|
break;
|
||||||
@@ -741,13 +753,11 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
case 0:
|
case 0:
|
||||||
case CMD_SET:
|
case CMD_SET:
|
||||||
if (Par)
|
if (Par)
|
||||||
for (short i=0;i<n;i++)
|
for (short i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
char num[4];
|
char num[4];
|
||||||
snprintf(num, sizeof(num), "%d", Par[i]);
|
snprintf(num, sizeof(num), "%d", Par[i]);
|
||||||
strncat(valstr, num, sizeof(valstr));
|
strncat(valstr, num, sizeof(valstr));
|
||||||
if (i!=n-1)
|
if (i != n - 1) {
|
||||||
{
|
|
||||||
strcpy(num, ",");
|
strcpy(num, ",");
|
||||||
strncat(valstr, num, sizeof(valstr));
|
strncat(valstr, num, sizeof(valstr));
|
||||||
}
|
}
|
||||||
@@ -757,39 +767,46 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(addrstr);Serial.print(F("->"));Serial.println(valstr);
|
Serial.print(addrstr);
|
||||||
client.publish(addrstr, valstr);
|
Serial.print(F("->"));
|
||||||
|
Serial.println(valstr);
|
||||||
|
mqttClient.publish(addrstr, valstr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value) {
|
||||||
|
|
||||||
|
if (modbusBusy) {
|
||||||
|
mb_fail(3, addr, value, 0);
|
||||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value)
|
return -1;
|
||||||
{
|
};
|
||||||
|
|
||||||
if (modbusBusy) {mb_fail(3,addr,value,0);return -1;};
|
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
|
|
||||||
modbusSerial.begin(9600, dimPar);
|
modbusSerial.begin(9600, dimPar);
|
||||||
node.begin(addr, modbusSerial);
|
node.begin(addr, modbusSerial);
|
||||||
|
|
||||||
|
|
||||||
if (_mask)
|
if (_mask) {
|
||||||
{value <<= 8; value |= (0xff);}
|
value <<= 8;
|
||||||
else {value &= 0xff; value |= (0xff00);}
|
value |= (0xff);
|
||||||
|
} else {
|
||||||
|
value &= 0xff;
|
||||||
|
value |= (0xff00);
|
||||||
|
}
|
||||||
|
|
||||||
Serial.print(addr);Serial.print(F("=>"));Serial.print(_reg,HEX);Serial.print(F(":"));Serial.println(value,HEX);
|
Serial.print(addr);
|
||||||
|
Serial.print(F("=>"));
|
||||||
|
Serial.print(_reg, HEX);
|
||||||
|
Serial.print(F(":"));
|
||||||
|
Serial.println(value, HEX);
|
||||||
|
|
||||||
node.writeSingleRegister(_reg, value);
|
node.writeSingleRegister(_reg, value);
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Item::checkFM() {
|
||||||
int Item::checkFM()
|
|
||||||
{
|
|
||||||
if (modbusBusy) return -1;
|
if (modbusBusy) return -1;
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
|
|
||||||
@@ -815,12 +832,12 @@ node.begin(getArg(),modbusSerial);
|
|||||||
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) {
|
||||||
{ Serial.print(F(" FM Val :"));
|
Serial.print(F(" FM Val :"));
|
||||||
for (j = 0; j < 10; j++)
|
for (j = 0; j < 10; j++) {
|
||||||
{
|
|
||||||
data = node.getResponseBuffer(j);
|
data = node.getResponseBuffer(j);
|
||||||
Serial.print(data,HEX);Serial.print(F("-"));
|
Serial.print(data, HEX);
|
||||||
|
Serial.print(F("-"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,7 +853,10 @@ node.begin(getArg(),modbusSerial);
|
|||||||
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
} else {
|
||||||
|
Serial.print(F("Modbus pooling error="));
|
||||||
|
Serial.println(result, HEX);
|
||||||
|
}
|
||||||
|
|
||||||
if (node.getResponseBuffer(0) & 8) //Active fault
|
if (node.getResponseBuffer(0) & 8) //Active fault
|
||||||
{
|
{
|
||||||
@@ -848,12 +868,12 @@ 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) {
|
||||||
{ Serial.print(F(" PI Val :"));
|
Serial.print(F(" PI Val :"));
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++) {
|
||||||
{
|
|
||||||
data = node.getResponseBuffer(j);
|
data = node.getResponseBuffer(j);
|
||||||
Serial.print(data);Serial.print(F("-"));
|
Serial.print(data);
|
||||||
|
Serial.print(F("-"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -866,11 +886,14 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
|
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
} else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
} else {
|
||||||
|
Serial.print(F("Modbus pooling error="));
|
||||||
|
Serial.println(result, HEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
outch = aJson.print(out);
|
outch = aJson.print(out);
|
||||||
client.publish(addrstr, outch);
|
mqttClient.publish(addrstr, outch);
|
||||||
free(outch);
|
free(outch);
|
||||||
aJson.deleteItem(out);
|
aJson.deleteItem(out);
|
||||||
|
|
||||||
@@ -878,8 +901,7 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Item::checkModbus()
|
int Item::checkModbus() {
|
||||||
{
|
|
||||||
if (modbusBusy) return -1;
|
if (modbusBusy) return -1;
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
|
|
||||||
@@ -899,20 +921,22 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
|
|
||||||
result = node.readHoldingRegisters(reg, 1);
|
result = node.readHoldingRegisters(reg, 1);
|
||||||
|
|
||||||
if (result == node.ku8MBSuccess)
|
if (result == node.ku8MBSuccess) {
|
||||||
{
|
|
||||||
data = node.getResponseBuffer(0);
|
data = node.getResponseBuffer(0);
|
||||||
Serial.print(F("Modbus Val: ")); Serial.println(data,HEX);
|
Serial.print(F("Modbus Val: "));
|
||||||
|
Serial.println(data, HEX);
|
||||||
checkModbus(data);
|
checkModbus(data);
|
||||||
|
} else {
|
||||||
|
Serial.print(F("Modbus pooling error="));
|
||||||
|
Serial.println(result, HEX);
|
||||||
}
|
}
|
||||||
else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); }
|
|
||||||
|
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
|
|
||||||
// Looking 1 step ahead for modbus item, which uses same register
|
// Looking 1 step ahead for modbus item, which uses same register
|
||||||
Item nextItem(modbusitem->next);
|
Item nextItem(modbusitem->next);
|
||||||
if (modbusitem && nextItem.isValid() && nextItem.itemType==CH_MODBUS && nextItem.getArg(0)==addr && nextItem.getArg(1)==reg)
|
if (modbusitem && nextItem.isValid() && nextItem.itemType == CH_MODBUS && nextItem.getArg(0) == addr &&
|
||||||
{
|
nextItem.getArg(1) == reg) {
|
||||||
nextItem.checkModbus(data);
|
nextItem.checkModbus(data);
|
||||||
modbusitem = modbusitem->next;
|
modbusitem = modbusitem->next;
|
||||||
if (!modbusitem) modbusitem = items->child;
|
if (!modbusitem) modbusitem = items->child;
|
||||||
@@ -921,27 +945,23 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Item::checkModbus(int data)
|
int Item::checkModbus(int data) {
|
||||||
{
|
|
||||||
short mask = getArg(2);
|
short mask = getArg(2);
|
||||||
int d = data;
|
int d = data;
|
||||||
if (mask) d>>=8; d&=0xff;
|
if (mask) d >>= 8;
|
||||||
|
d &= 0xff;
|
||||||
d = map(d, 0, 0x3f, 0, 100);
|
d = map(d, 0, 0x3f, 0, 100);
|
||||||
int cmd = getCmd();
|
int cmd = getCmd();
|
||||||
//Serial.println(d);
|
//Serial.println(d);
|
||||||
if (getVal() != d || d && cmd == CMD_OFF || d && cmd == CMD_HALT) //volume changed or turned on manualy
|
if (getVal() != d || d && cmd == CMD_OFF || d && cmd == CMD_HALT) //volume changed or turned on manualy
|
||||||
{
|
{
|
||||||
if (d)
|
if (d) { // Actually turned on
|
||||||
|
|
||||||
{ // Actually turned on
|
|
||||||
if (cmd == CMD_OFF || cmd == CMD_HALT) SendCmd(CMD_ON); //update OH with ON if it was turned off before
|
if (cmd == CMD_OFF || cmd == CMD_HALT) SendCmd(CMD_ON); //update OH with ON if it was turned off before
|
||||||
SendCmd(0, 1, &d); //update OH with value
|
SendCmd(0, 1, &d); //update OH with value
|
||||||
setCmd(CMD_ON); //store command
|
setCmd(CMD_ON); //store command
|
||||||
setVal(d); //store value
|
setVal(d); //store value
|
||||||
}
|
} else {
|
||||||
else {
|
if (cmd != CMD_HALT && cmd != CMD_OFF) {
|
||||||
if (cmd!=CMD_HALT && cmd!=CMD_OFF)
|
|
||||||
{
|
|
||||||
setCmd(CMD_OFF); // store command (not value)
|
setCmd(CMD_OFF); // store command (not value)
|
||||||
SendCmd(CMD_OFF);// update OH
|
SendCmd(CMD_OFF);// update OH
|
||||||
}
|
}
|
||||||
@@ -949,10 +969,8 @@ int Item::checkModbus(int data)
|
|||||||
} //if data changed
|
} //if data changed
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::Pool()
|
int Item::Pool() {
|
||||||
{
|
switch (itemType) {
|
||||||
switch (itemType)
|
|
||||||
{
|
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
checkModbus();
|
checkModbus();
|
||||||
break;
|
break;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -25,14 +25,14 @@ void Changed (int i, DeviceAddress addr, int val);
|
|||||||
void modbusIdle(void);
|
void modbusIdle(void);
|
||||||
void _handleHelp(int arg_cnt, char **args);
|
void _handleHelp(int arg_cnt, char **args);
|
||||||
void _kill(int arg_cnt, char **args);
|
void _kill(int arg_cnt, char **args);
|
||||||
void parseConfig();
|
void parseConfigFromParsedJSON();
|
||||||
void _loadConfig (int arg_cnt, char **args);
|
void _loadConfig (int arg_cnt, char **args);
|
||||||
int loadConfig (int arg_cnt, char **args);
|
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
||||||
void _mqttConfigReq (int arg_cnt, char **args);
|
void _mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigReq (int arg_cnt, char **args);
|
int mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigResp (char * as);
|
int mqttConfigResp (char * as);
|
||||||
void _saveConfig(int arg_cnt, char **args);
|
void _saveConfigToEEPROM(int arg_cnt, char **args);
|
||||||
void _setConfig(int arg_cnt, char **args);
|
void _setMacAddress(int arg_cnt, char **args);
|
||||||
void _getConfig(int arg_cnt, char **args);
|
void _getConfig(int arg_cnt, char **args);
|
||||||
void printBool (bool arg);
|
void printBool (bool arg);
|
||||||
void saveFlash(short n, char* str);
|
void saveFlash(short n, char* str);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "owTerm.h"
|
#include "owTerm.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
OneWire *net = NULL;
|
OneWire *net = NULL;
|
||||||
@@ -39,8 +40,7 @@ unsigned long owTimer=0;
|
|||||||
|
|
||||||
owChangedType owChanged;
|
owChangedType owChanged;
|
||||||
|
|
||||||
int owUpdate()
|
int owUpdate() {
|
||||||
{
|
|
||||||
unsigned long finish = millis() + 5000;
|
unsigned long finish = millis() + 5000;
|
||||||
short sr;
|
short sr;
|
||||||
|
|
||||||
@@ -49,25 +49,32 @@ int owUpdate()
|
|||||||
if (net) net->reset_search();
|
if (net) net->reset_search();
|
||||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||||
|
|
||||||
while (net && net->wireSearch(term[t_count])>0 && (t_count<t_max) && finish > millis ())
|
while (net && net->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||||
{ short ifind=-1;
|
short ifind = -1;
|
||||||
if (net->crc8(term[t_count], 7) == term[t_count][7])
|
if (net->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||||
{
|
for (short i = 0; i < t_count; i++)
|
||||||
for (short i=0;i<t_count;i++) if (!memcmp(term[i],term[t_count],8)) {ifind=i;wstat[i]|=SW_FIND;
|
if (!memcmp(term[i], term[t_count], 8)) {
|
||||||
Serial.print(F(" Node:"));PrintBytes(term[t_count],8);Serial.println(F(" alive"));
|
ifind = i;
|
||||||
break;}; //alive
|
wstat[i] |= SW_FIND;
|
||||||
if (ifind<0 && sensors)
|
Serial.print(F(" Node:"));
|
||||||
{
|
PrintBytes(term[t_count], 8);
|
||||||
|
Serial.println(F(" alive"));
|
||||||
|
break;
|
||||||
|
}; //alive
|
||||||
|
if (ifind < 0 && sensors) {
|
||||||
wstat[t_count] = SW_FIND; //Newly detected
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
Serial.print(F("dev#"));
|
||||||
|
Serial.print(t_count);
|
||||||
|
Serial.print(F(" Addr:"));
|
||||||
|
PrintBytes(term[t_count], 8);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if (term[t_count][0]==0x28)
|
if (term[t_count][0] == 0x28) {
|
||||||
{
|
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
net->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;}
|
t_count++;
|
||||||
|
}
|
||||||
}//if
|
}//if
|
||||||
} //while
|
} //while
|
||||||
|
|
||||||
@@ -99,11 +106,9 @@ term = new DeviceAddress[t_max];
|
|||||||
wstat = new uint16_t[t_max];
|
wstat = new uint16_t[t_max];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
if (net->checkPresence())
|
if (net->checkPresence()) {
|
||||||
{
|
|
||||||
Serial.println(F("DS2482-100 present"));
|
Serial.println(F("DS2482-100 present"));
|
||||||
net->deviceReset();
|
net->deviceReset();
|
||||||
#ifdef APU_OFF
|
#ifdef APU_OFF
|
||||||
@@ -136,11 +141,9 @@ wstat = new uint16_t [t_max];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sensors_loop(void)
|
int sensors_loop(void) {
|
||||||
{
|
|
||||||
if (!sensors) return -1;
|
if (!sensors) return -1;
|
||||||
if (si>=t_count)
|
if (si >= t_count) {
|
||||||
{
|
|
||||||
owUpdate(); //every check circle - scan for new devices
|
owUpdate(); //every check circle - scan for new devices
|
||||||
si = 0;
|
si = 0;
|
||||||
return 8000;
|
return 8000;
|
||||||
@@ -168,29 +171,27 @@ int sensors_loop(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void owLoop()
|
void owLoop() {
|
||||||
|
|
||||||
{
|
|
||||||
if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owFind(DeviceAddress addr)
|
int owFind(DeviceAddress addr) {
|
||||||
{
|
|
||||||
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void owAdd (DeviceAddress addr)
|
void owAdd(DeviceAddress addr) {
|
||||||
{
|
|
||||||
wstat[t_count] = SW_FIND; //Newly detected
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
memcpy(term[t_count], addr, 8);
|
memcpy(term[t_count], addr, 8);
|
||||||
//term[t_count]=addr;
|
//term[t_count]=addr;
|
||||||
|
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
Serial.print(F("dev#"));
|
||||||
|
Serial.print(t_count);
|
||||||
|
Serial.print(F(" Addr:"));
|
||||||
|
PrintBytes(term[t_count], 8);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if (term[t_count][0]==0x28)
|
if (term[t_count][0] == 0x28) {
|
||||||
{
|
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
net->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
; megaatmega2560
|
megaatmega2560
|
||||||
due
|
; due
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
|
|||||||
Reference in New Issue
Block a user