mirror of
https://github.com/anklimov/lighthub
synced 2025-12-07 20:29:50 +03:00
scmd,rcmd in inputs may contain not only cmd but values, minimal dimmers volume treshhold for ON command, remote command execute on MQTT command (new Cmd.h required), bat-files to flash DUE and start CLI added
This commit is contained in:
@@ -27,11 +27,11 @@ extern PubSubClient mqttClient;
|
||||
|
||||
Input::Input(char * name) //Constructor
|
||||
{
|
||||
if (name)
|
||||
if (name)
|
||||
inputObj= aJson.getObjectItem(inputs, name);
|
||||
else inputObj=NULL;
|
||||
|
||||
Parse();
|
||||
|
||||
Parse();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,34 +42,34 @@ Input::Input(int pin) //Constructor
|
||||
|
||||
|
||||
Input::Input(aJsonObject * obj) //Constructor
|
||||
{
|
||||
inputObj= obj;
|
||||
{
|
||||
inputObj= obj;
|
||||
Parse();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
boolean Input::isValid ()
|
||||
{
|
||||
return (pin && store);
|
||||
return (pin && store);
|
||||
}
|
||||
|
||||
void Input::Parse()
|
||||
{
|
||||
{
|
||||
store = NULL;
|
||||
inType = 0;
|
||||
pin = 0;
|
||||
|
||||
pin = 0;
|
||||
|
||||
if (inputObj && (inputObj->type==aJson_Object))
|
||||
{
|
||||
aJsonObject * s;
|
||||
|
||||
s = aJson.getObjectItem(inputObj,"T");
|
||||
|
||||
s = aJson.getObjectItem(inputObj,"T");
|
||||
if (s) inType = s->valueint;
|
||||
|
||||
|
||||
pin = atoi(inputObj->name);
|
||||
|
||||
|
||||
|
||||
s = aJson.getObjectItem(inputObj,"S");
|
||||
if (!s) { Serial.print(F("In: "));Serial.print(pin);Serial.print(F("/"));Serial.println(inType);
|
||||
aJson.addNumberToObject(inputObj,"S", 0);
|
||||
@@ -81,40 +81,40 @@ void Input::Parse()
|
||||
}
|
||||
|
||||
int Input::Poll()
|
||||
{
|
||||
{
|
||||
boolean v;
|
||||
if (!isValid()) return -1;
|
||||
|
||||
|
||||
if (inType & IN_ACTIVE_HIGH)
|
||||
{ pinMode(pin, INPUT);
|
||||
v = (digitalRead(pin)==HIGH);
|
||||
}
|
||||
else
|
||||
{ pinMode(pin, INPUT_PULLUP);
|
||||
|
||||
if (inType & IN_ACTIVE_HIGH)
|
||||
{ pinMode(pin, INPUT);
|
||||
v = (digitalRead(pin)==HIGH);
|
||||
}
|
||||
else
|
||||
{ pinMode(pin, INPUT_PULLUP);
|
||||
v = (digitalRead(pin)==LOW);
|
||||
}
|
||||
if (v!=store->cur) // value changed
|
||||
}
|
||||
if (v!=store->cur) // value changed
|
||||
{
|
||||
if (store->bounce) store->bounce--;
|
||||
if (store->bounce) store->bounce--;
|
||||
else //confirmed change
|
||||
{
|
||||
Changed(v);
|
||||
store->cur=v;
|
||||
}
|
||||
}
|
||||
else // no change
|
||||
store->bounce=3;
|
||||
return 0;
|
||||
else // no change
|
||||
store->bounce=3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Input::Changed (int val)
|
||||
{
|
||||
Serial.print(pin);Serial.print(F("="));Serial.println(val);
|
||||
aJsonObject * item = aJson.getObjectItem(inputObj,"item");
|
||||
Serial.print(F("IN:")); Serial.print(pin);Serial.print(F("="));Serial.println(val);
|
||||
aJsonObject * item = aJson.getObjectItem(inputObj,"item");
|
||||
aJsonObject * scmd = aJson.getObjectItem(inputObj,"scmd");
|
||||
aJsonObject * rcmd = aJson.getObjectItem(inputObj,"rcmd");
|
||||
aJsonObject * emit = aJson.getObjectItem(inputObj,"emit");
|
||||
aJsonObject * rcmd = aJson.getObjectItem(inputObj,"rcmd");
|
||||
aJsonObject * emit = aJson.getObjectItem(inputObj,"emit");
|
||||
|
||||
if (emit)
|
||||
{
|
||||
@@ -126,7 +126,7 @@ void Input::Changed (int val)
|
||||
else
|
||||
{ //send reset command
|
||||
if (!rcmd) mqttClient.publish(emit->valuestring,"OFF",true); else if (strlen(rcmd->valuestring)) mqttClient.publish(emit->valuestring,rcmd->valuestring,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item)
|
||||
@@ -136,11 +136,11 @@ void Input::Changed (int val)
|
||||
{
|
||||
if (val)
|
||||
{ //send set command
|
||||
if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(txt2cmd(scmd->valuestring),0,NULL,true);
|
||||
if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(scmd->valuestring,true);
|
||||
}
|
||||
else
|
||||
{ //send reset command
|
||||
if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(txt2cmd(rcmd->valuestring),0,NULL,true);
|
||||
if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(rcmd->valuestring,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user