From 65ca7dff97130e1eaca7bee618284887c95117a9 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Wed, 4 Oct 2017 03:08:09 +0300 Subject: [PATCH] Code review, many bugfixes. Synchronization items with Openhab improved. Modbus pulling developed --- item.cpp | 372 +++++++++++++++++++++++++++++++++++++++++---------- item.h | 10 +- lighthub.ino | 308 ++++++++++++++---------------------------- utils.cpp | 11 ++ utils.h | 1 + 5 files changed, 423 insertions(+), 279 deletions(-) diff --git a/item.cpp b/item.cpp index 4aef93b..59a6c20 100644 --- a/item.cpp +++ b/item.cpp @@ -25,7 +25,7 @@ e-mail anklimov@gmail.com #include #include - +short modbusBusy=0; extern int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value); extern PubSubClient client; @@ -48,16 +48,20 @@ int txt2cmd (char * payload) return cmd; } -Item::Item(char * name) //Constructor +const short defval[4] = {0,0,0,0}; //Type,Arg,Val,Cmd + +Item::Item(aJsonObject * obj)//Constructor +{ + itemArr= obj; + Parse(); +} + +void Item::Parse() { - if (name) - itemArr= aJson.getObjectItem(items, name); - else itemArr=NULL; - if (isValid()) { // Todo - avoid static enlarge for every types - for (int i=aJson.getArraySize(itemArr);i<4;i++) aJson.addItemToArray(itemArr,aJson.createItem(int(0))); //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; @@ -66,11 +70,20 @@ Item::Item(char * name) //Constructor Serial.print(F(" Item:")); - Serial.println(name); - Serial.print(itemType);Serial.print(":");Serial.println(getArg()); + Serial.print(itemArr->name);Serial.print(F(" T:")); + Serial.print(itemType);Serial.print(" =");Serial.println(getArg()); } } +Item::Item(char * name) //Constructor +{ + if (name) + itemArr= aJson.getObjectItem(items, name); + else itemArr=NULL; + +Parse(); +} + uint8_t Item::getCmd() { aJsonObject *t = aJson.getArrayItem(itemArr,I_CMD); @@ -87,10 +100,10 @@ void Item::setCmd(uint8_t cmd) t->valueint=cmd; } -int Item::getArg() //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->type==aJson_Int) return itemArg->valueint; - else if (itemArg->type==aJson_Array) return aJson.getArrayItem(itemArg,0)->valueint; + else if (itemArg->type==aJson_Array) return aJson.getArrayItem(itemArg,n)->valueint; else return -2; } /* @@ -168,17 +181,15 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) int iaddr=getArg(); HSVstore st; - - - //Store Parameter(s) into json VAL + //Store Parameter(s) into json VAL switch (cmd) { - + int t; case CMD_TOGGLE: - switch (getCmd()) + switch (t=getCmd()) { case CMD_ON: case CMD_SET: @@ -186,19 +197,24 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) break; case CMD_OFF: case CMD_HALT: + case 0: + case -1: //No stored command yet cmd=CMD_ON; break; }//switch old cmd - + //Serial.print("Tog/oldcmd:");Serial.print(t);Serial.print(" new ");Serial.println(cmd); break; case CMD_RESTORE: - if (itemType!=CH_GROUP) //individual threating of channels - switch (getCmd()) - { case CMD_HALT: - // Serial.print("LastCmd:");Serial.println(t); - cmd=CMD_ON; + if (itemType!=CH_GROUP) //individual threating of channels. Ignore restore command for groups + switch (t=getCmd()) + { + case CMD_HALT: //previous command was HALT ? + Serial.print("Restored from:");Serial.println(t); + cmd=CMD_ON; //turning on break; + default: + return -3; }//switch old cmd } //switch cmd @@ -210,8 +226,11 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) switch (itemType) { - case CH_GROUP: + case CH_RGBW: //only if configured VAL array + if (!Par[1]) itemType=CH_WHITE; + case CH_GROUP: //Save for groups as well + case CH_RGB: st.h=Par[0]; st.s=Par[1]; st.v=Par[2]; @@ -232,18 +251,54 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) break; - case CMD_ON: //retrive stored values + case CMD_ON: if (getCmd()!=CMD_ON) - { - st.aslong=getVal();//Serial.print("Returned getVal: ");Serial.println(st.aslong); - if (st.aslong>=0) - { - Par[0]=st.h; - Par[1]=st.s; - Par[2]=st.v; - } + + { + short params=0; + //retrive stored values + st.aslong=getVal(); + if (st.aslong>0) //Stored smthng + + switch (itemType) + { + //case CH_GROUP: + case CH_RGBW: + case CH_RGB: + Par[0]=st.h; + Par[1]=st.s; + Par[2]=st.v; + params=3; + SendCmd(0,params,Par); // Send restored triplet + break; + + case CH_DIMMER: //Everywhere, in flat VAL + case CH_MODBUS: + case CH_VC: + case CH_VCTEMP: + Par[0]=st.aslong; + params=1; + SendCmd(0,params,Par); // Send restored parameter + break; + case CH_THERMO: + Par[0]=st.aslong; + params=0; + SendCmd(CMD_ON); // Just ON (switch) + break; + default: + SendCmd(cmd); // Just send ON + }//itemtype + else + {// Default settings + Serial.print(st.aslong); + Serial.println(F(": No stored values - default")); + Par[0]=100; + Par[1]=0; + Par[2]=100; + } - for (short i=0;i<3 ;i++) + + for (short i=0;i0) + { + Par[0]=0;Par[1]=0;Par[2]=0; setCmd(cmd); - Serial.print(itemType);Serial.println(" Halted"); - } - - + SendCmd(CMD_OFF); + Serial.println(" Halted"); + } + }//switch cmd -/* - Serial.print("go: "); - for (short i=0;i<3 ;i++) - { - Serial.print(i);Serial.print("=");Serial.println(Par[i]); - } - */ + - if (send) SendCmd(cmd,n,Par); switch (itemType) { @@ -339,7 +401,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) int _reg = aJson.getArrayItem(itemArg,1)->valueint; int _mask= aJson.getArrayItem(itemArg,2)->valueint; - modbusSet(_addr,_reg,_mask,map(Par[0],0,100,0,0x1f)); + modbusSet(_addr,_reg,_mask,map(Par[0],0,100,0,0x3f)); } break;} @@ -353,7 +415,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) { Item it (i->valuestring); // it.copyPar(itemVal); - it.Ctrl(cmd,n,Par,true); + it.Ctrl(cmd,n,Par,send); //// was true i=i->next; } //while } //if @@ -434,7 +496,7 @@ if (items) } } -*/ + void PooledItem::Idle() { if (PoolingInterval) @@ -448,7 +510,7 @@ if (PoolingInterval) - /* + addr 10d Снять аварию 42001 (2001=7d1) =>4 @@ -481,12 +543,7 @@ POOL 2101x10 */ -int Item::Pool() -{ - - } -extern short modbusBusy; extern ModbusMaster node; int Item::VacomSetFan (int addr, int8_t val) @@ -541,8 +598,8 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) int Item::SendCmd(short cmd,short n, int * Par) { char addrstr[32]; - char addrbuf[17]; - char valstr[16]; + //char addrbuf[17]; + char valstr[16]=""; strcpy_P (addrstr,outprefix); strncat (addrstr,itemArr->name,sizeof(addrstr)); //// @@ -558,16 +615,185 @@ int Item::SendCmd(short cmd,short n, int * Par) strcpy(valstr,"OFF"); break; // TODO send Par - //case 0: - //case CMD_SET: - ///////////sprintf(valstr,"%d",Par[0]); - default: - return -1; + case 0: + case CMD_SET: + if (Par) + for (short i=0;i");Serial.println(valstr); client.publish(addrstr, valstr); return 0; } - + + int Item::isActive() +{ + HSVstore st; + int val=0; + +if (!isValid()) return -1; +//Serial.print(itemArr->name); +int cmd=getCmd(); +switch (cmd) +{ + case CMD_ON: + //Serial.println(" active"); + return 1; + case CMD_OFF: + case CMD_HALT: + //Serial.println(" inactive"); + return 0; +} + + st.aslong=getVal(); + +switch (itemType) +{ + //case CH_GROUP: + case CH_RGBW: + case CH_RGB: + + val=st.v; + break; + + case CH_DIMMER: //Everywhere, in flat VAL + case CH_MODBUS: + case CH_THERMO: + case CH_VC: + case CH_VCTEMP: + val=st.aslong; +} //switch +Serial.print(":=");Serial.println(val); + if (val) return 1; else return 0; +} + + + + int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value) + { + + if (modbusBusy) return -1; + modbusBusy=1; + node.begin(9600,SERIAL_8E1,13); + node.setSlave(addr); + +if (_mask) + {value <<= 8; value |= (0xff);} + else {value &= 0xff; value |= (0xff00);} + + Serial.print(addr);Serial.print("=>");Serial.print(_reg,HEX);Serial.print(":");Serial.println(value,HEX); + + node.writeSingleRegister(_reg,value); + modbusBusy=0; + } + + +int Item::checkFM() + { + if (modbusBusy) return -1; + modbusBusy=1; + + uint8_t j, result; + uint16_t data[1]; + node.begin(9600,SERIAL_8N1,13); + + node.setSlave(getArg()); + + result = node.readHoldingRegisters(2101-1, 10); + + // do something with data if read is successful + if (result == node.ku8MBSuccess) + { Serial.print(F(" FM Val :")); + for (j = 0; j < 10; j++) + { + data[j] = node.getResponseBuffer(j); + Serial.print(data[j],HEX);Serial.print("-"); + + } + Serial.println(); + } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } + +result = node.readHoldingRegisters(20-1, 4); + + // do something with data if read is successful + if (result == node.ku8MBSuccess) + { Serial.print(F(" PI Val :")); + for (j = 0; j < 4; j++) + { + data[j] = node.getResponseBuffer(j); + Serial.print(data[j]);Serial.print("-"); + + } + Serial.println(); + } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } + + + + modbusBusy=0; + } + + + int Item::checkModbus() + { + if (modbusBusy) return -1; + modbusBusy=1; + node.begin(9600,SERIAL_8E1,13); + + uint8_t result; + int data; + + node.setSlave(getArg()); + result = node.readHoldingRegisters(0, 1); + + // do something with data if read is successful + if (result == node.ku8MBSuccess) + { + + data=node.getResponseBuffer(0); + Serial.print(F("Modbus Val: ")); Serial.println(data,HEX); + if (getArg(2)) data>>=8; data&=0xff; + data=map(data,0,0x3f,0,100); + + if (getVal()!=data) + { + SendCmd(0,1,&data); //update OH + + switch (getCmd()) //Save value if not turned off + {case CMD_OFF: + case CMD_HALT: + break; + default: + setVal(data); + } //switch + } //if data changed + + } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } + + modbusBusy=0; + } + +int Item::Pool() +{ + switch (itemType) + { + case CH_MODBUS: + checkModbus(); + break; + case CH_VC: + checkFM(); + } + } diff --git a/item.h b/item.h index 4da3546..2db8b9a 100644 --- a/item.h +++ b/item.h @@ -69,9 +69,10 @@ class Item Item(char * name); + Item(aJsonObject * obj); boolean isValid (); virtual int Ctrl(short cmd, short n=0, int * Par=NULL, boolean send=false); - int getArg(); + int getArg(short n=0); boolean getEnableCMD(int delta); //int getVal(short n); //From VAL array. Negative if no array long int getVal(); //From int val OR array @@ -89,10 +90,15 @@ class Item protected: int VacomSetFan (int addr, int8_t val); int VacomSetHeat(int addr, int8_t val, int8_t cmd=0); + int isActive(); + void Parse(); + int checkModbus(); + int checkFM(); }; +/* class PooledItem : public Item { @@ -108,7 +114,7 @@ class PooledItem : public Item -/* + class Vacon : public Item { diff --git a/lighthub.ino b/lighthub.ino index 6754d79..9a001a0 100644 --- a/lighthub.ino +++ b/lighthub.ino @@ -36,31 +36,20 @@ e-mail anklimov@gmail.com Todo === -A/C control +A/C control/Dimmer ? rotary encoder local ctrl analog in local ctrl -Light sensor analog in Smooth regulation/fading -Phase dimmer board PID Termostat out dmx relay out --IRDA in --MCS 350 out ? --HDMI sw out? -Simple bridging (1w <-> dmx,modbus etc) ? - */ //define NOETHER - -//#include #include #include #include - -//#include "owSwitch.h" #include "utils.h" #include "owTerm.h" @@ -68,22 +57,30 @@ Simple bridging (1w <-> dmx,modbus etc) ? //#include "pixeltypes.h" //#include "hsv2rgb.h" #include -//#include #include #include "aJSON.h" #include "HTTPClient.h" -//#include "CommandLine.h" #include #include "stdarg.h" #include -//#include #include #include "dmx.h" #include "item.h" #include "inputs.h" #include +// Hardcoded definitions +#define GIST 2 +#define serverip "192.168.88.2" +IPAddress server(192, 168, 88, 2); //TODO - configure it +//char* inprefix=("/myhome/in/"); +//char* outprefix=("/myhome/s_out/"); +//char* subprefix=("/myhome/in/#"); +#define inprefix "/myhome/in/" +const char outprefix[] PROGMEM = "/myhome/s_out/"; +#define subprefix "/myhome/in/#" +// aJsonObject *root = NULL; aJsonObject *items = NULL; @@ -93,6 +90,13 @@ aJsonObject *mqttArr = NULL; aJsonObject *modbusArr = NULL; aJsonObject *owArr = NULL; +unsigned long modbuscheck=0; +unsigned long incheck =0; +unsigned long lanCheck =0; +unsigned long thermocheck=0; + +aJsonObject * modbusitem= NULL; + // CommandLine instance. //CommandLine commandLine(Serial, "> "); @@ -104,39 +108,16 @@ int lanStatus = 0; ModbusMaster node(2,0x60); //TODO dynamic alloc -IPAddress server(192, 168, 88, 2); byte mac[6]; EthernetClient ethClient; PubSubClient client(ethClient); -//char* inprefix=("/myhome/in/"); -//char* outprefix=("/myhome/s_out/"); -//char* subprefix=("/myhome/in/#"); - -#define inprefix "/myhome/in/" -const char outprefix[] PROGMEM = "/myhome/s_out/"; -#define subprefix "/myhome/in/#" -//#define subprefix "#" - int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value); int freeRam (void) ; -int getInt(char ** chan) -{ - int ch = atoi(*chan); - *chan=strchr(*chan,','); - - if (*chan) *chan+=1; - //Serial.print(F("Par:")); Serial.println(ch); - return ch; - -} - - -//// int itemCtrl2(char* name,int r,int g, int b, int w) { aJsonObject *itemArr= aJson.getObjectItem(items, name); @@ -199,16 +180,8 @@ void callback(char* topic, byte* payload, unsigned int length) { // short outtopic = strncmp(topic,F(outprefix),strlen(outprefix)); cmd= txt2cmd((char*) payload); - /* - // Check for command - if (strcmp((char*)payload,"ON")==0) cmd=CMD_ON; - else if (strcmp((char*)payload,"OFF")==0) cmd=CMD_OFF; - else if (strcmp((char*)payload,"RESTORE")==0) cmd=CMD_RESTORE; - else if (strcmp((char*)payload,"TOGGLE")==0) cmd=CMD_TOGGLE; - //Serial.print("Cmd:");Serial.println(cmd); -*/ - char * t; - if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , 20); + char * t; + if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , 20); @@ -279,10 +252,10 @@ void restoreState() client.publish("/myhome/out/RestoreState","ON"); }; -unsigned long lanCheck=0; + int getConfig (int arg_cnt, char **args); -int lanloop() { +int lanLoop() { static short _once=1; #ifdef NOETHER @@ -489,7 +462,7 @@ void Changed (int i, DeviceAddress addr, int val) if (owItem) { - thermoSetCurTemp(owItem,val); + thermoSetCurTemp(owItem,val); ///TODO: Refactore using Items interface } @@ -540,6 +513,7 @@ void parseConfig() } items = aJson.getObjectItem(root,"items"); + modbusitem = items->child; inputs = aJson.getObjectItem(root,"in"); modbusArr= aJson.getObjectItem(root, "modbus"); @@ -688,7 +662,7 @@ int getConfig (int arg_cnt, char **args) snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); Serial.println(F("Config URI: "));Serial.println(URI); - HTTPClient hclient("192.168.88.2",hserver,80); + HTTPClient hclient(serverip,hserver,80); // FILE is the return STREAM type of the HTTPClient result = hclient.getURI( URI); @@ -746,7 +720,7 @@ void setup() { //Serial.begin(115200); cmdInit(115200); - Serial.println(F("\nLazyhome.ru LightHub controller v0.8")); + Serial.println(F("\nLazyhome.ru LightHub controller v0.9")); for (short i=0;i<6;i++) mac[i]=EEPROM.read(i); @@ -783,117 +757,11 @@ void setup() { -unsigned long modbus_check=0; -short modbusBusy=0; - - int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value) - { - - if (modbusBusy) return -1; - modbusBusy=1; - node.begin(9600,SERIAL_8E1,13); - node.setSlave(addr); - /* - uint8_t res = node.readHoldingRegisters(_reg, 1); - if (res != node.ku8MBSuccess) return -1; - uint16_t b0=node.getResponseBuffer(0); - //uint8_t b1=node.getResponseBuffer(1); - //Serial.print(b0,HEX);Serial.println(b1,HEX); - delay(5); - - - if (_mask) - {value <<= 8; value |= (b0 & 0xff);} - else {value &= 0xff; value |= (b0 & 0xff00);} -*/ - -if (_mask) - {value <<= 8; value |= (0xff);} - else {value &= 0xff; value |= (0xff00);} - - Serial.print(addr);Serial.print("=>");Serial.print(_reg,HEX);Serial.print(":");Serial.println(value,HEX); - - node.writeSingleRegister(_reg,value); - modbusBusy=0; - } - - - -int checkFMDev(int dev) - { - if (modbusBusy) return -1; - modbusBusy=1; - - uint8_t j, result; - uint16_t data[1]; - node.begin(9600,SERIAL_8N1,13); - - node.setSlave(dev); - - result = node.readHoldingRegisters(2101-1, 10); - - // do something with data if read is successful - if (result == node.ku8MBSuccess) - { Serial.print(F(" FM Val :")); - for (j = 0; j < 10; j++) - { - data[j] = node.getResponseBuffer(j); - Serial.print(data[j],HEX);Serial.print("-"); - - } - Serial.println(); - } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } - -result = node.readHoldingRegisters(20-1, 4); - - // do something with data if read is successful - if (result == node.ku8MBSuccess) - { Serial.print(F(" PI Val :")); - for (j = 0; j < 4; j++) - { - data[j] = node.getResponseBuffer(j); - Serial.print(data[j]);Serial.print("-"); - - } - Serial.println(); - } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } - - - - modbusBusy=0; - } - - - int checkDev(int dev) - { - if (modbusBusy) return -1; - modbusBusy=1; - node.begin(9600,SERIAL_8E1,13); - - uint8_t j, result; - uint16_t data[1]; - - node.setSlave(dev); - result = node.readHoldingRegisters(0, 1); - - // do something with data if read is successful - if (result == node.ku8MBSuccess) - { Serial.print(F(" Modbus Val :")); - for (j = 0; j < 1; j++) - { - data[j] = node.getResponseBuffer(j); - Serial.print(data[j],HEX);Serial.print("-"); - - } - Serial.println(); - } else {Serial.print(F("Modbus pooling error=")); Serial.println(result,HEX); } - - modbusBusy=0; - } - +//unsigned long modbus_check=0; +/* void modbusloop() { @@ -910,29 +778,27 @@ void modbusloop() Serial.println(freeRam()); } } - +*/ void loop(){ wdt_reset(); //commandLine.update(); cmdPoll(); -if (lanloop() >1) {client.loop(); if (artnet) artnet->read();} +if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();} if (owReady && owArr) owLoop(); unsigned long lastpacket = DMXSerial.noDataSince(); // if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket); DMXCheck(); - if (modbusArr) modbusloop(); - if (items) thermoIdle(); - if (inputs) inputIdle(); + if (modbusArr && items) modbusLoop(); + if (items) thermoLoop(); + if (inputs) inputLoop(); } -//int imodbus=0; -//unsigned short modbuspoll[]={0x60,0x61}; - +// Idle handlers void owIdle(void) { if (artnet) artnet->read(); wdt_reset(); @@ -940,10 +806,10 @@ void owIdle(void) return;/// Serial.print("o"); -if (lanloop() == 1) client.loop(); +if (lanLoop() == 1) client.loop(); //if (owReady) owLoop(); DMXCheck(); - //modbusloop(); + //modbusLoop(); } @@ -952,17 +818,79 @@ void modbusIdle(void) //Serial.print("m"); wdt_reset(); -if (lanloop() > 1) {client.loop();if (artnet) artnet->read();} +if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();} //if (owReady) owLoop(); DMXCheck(); //modbusloop(); } -#define GIST 2 -unsigned long thermocheck=0; -void thermoIdle(void) +// Loops + + + +void inputLoop(void) +{ + + if (millis()>incheck) + { + + aJsonObject * input= inputs->child; + + while (input) + { + if ((input->type==aJson_Object) ) + { + Input in(input); + in.Pool(); + } + input=input->next; + } + + + incheck=millis()+50; + + } + +} + + + +void modbusLoop(void) +{ + boolean done=false; + if (millis()>modbuscheck) + { + while (modbusitem && !done) + { + if (modbusitem->type==aJson_Array) + { + switch (aJson.getArrayItem(modbusitem, 0)->valueint) + { + case CH_MODBUS: + //case CH_VCTEMP: + case CH_VC: + { + Item it(modbusitem); + it.Pool(); + modbuscheck=millis()+2000; + done=true; + break; //case; + } + } //switch + + }//if + modbusitem=modbusitem->next; + if (!modbusitem) {modbusitem=items->child;return;} //start from 1-st element + } //while + }//if +} + + +// To be refactored + +void thermoLoop(void) { #define T_ATTEMPTS 20 #define IET_TEMP 0 @@ -987,7 +915,7 @@ void thermoIdle(void) if (extArr && (aJson.getArraySize(extArr)>1) ) { int curtemp = aJson.getArrayItem(extArr, IET_TEMP)->valueint; - if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) {Serial.println(F("Expired"));} else aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint--; + if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) {Serial.print(item->name);Serial.println(F(" Expired"));} else aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint--; Serial.print(item->name);Serial.print(F(" Set:"));Serial.print(temp); Serial.print(F(" Curtemp:"));Serial.print(curtemp); Serial.print(F( " cmd:")); Serial.print(cmd), @@ -1012,32 +940,6 @@ void thermoIdle(void) } -long int incheck =0; - -void inputIdle(void) -{ - - if (millis()>incheck) - { - - aJsonObject * input= inputs->child; - - while (input) - { - if ((input->type==aJson_Object) ) - { - Input in(input); - in.Pool(); - } - input=input->next; - } - - - incheck=millis()+50; - - } - -} short thermoSetCurTemp(char * name, short t) @@ -1072,7 +974,6 @@ if (items) } //proc - int freeRam () { extern int __heap_start, *__brkval; @@ -1080,4 +981,3 @@ int freeRam () return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); } - diff --git a/utils.cpp b/utils.cpp index f4ef021..bdf44b7 100644 --- a/utils.cpp +++ b/utils.cpp @@ -59,3 +59,14 @@ void SetAddr(char * out, uint8_t* addr) { } +int getInt(char ** chan) +{ + int ch = atoi(*chan); + *chan=strchr(*chan,','); + + if (*chan) *chan+=1; + //Serial.print(F("Par:")); Serial.println(ch); + return ch; + +} + diff --git a/utils.h b/utils.h index bda9214..42e9c32 100644 --- a/utils.h +++ b/utils.h @@ -23,3 +23,4 @@ void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0); void SetBytes(uint8_t* addr, uint8_t count, char * out); void SetAddr(char * out, uint8_t* addr); uint8_t HEX2DEC(char i); +int getInt(char ** chan);