mirror of
https://github.com/anklimov/lighthub
synced 2025-12-08 12:49:50 +03:00
root
applyConfig And *Pool* to *Poll* of course
This commit is contained in:
@@ -80,7 +80,7 @@ void Input::Parse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Input::Pool ()
|
int Input::Poll()
|
||||||
{
|
{
|
||||||
boolean v;
|
boolean v;
|
||||||
if (!isValid()) return -1;
|
if (!isValid()) return -1;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Input
|
|||||||
boolean isValid ();
|
boolean isValid ();
|
||||||
void Changed (int val);
|
void Changed (int val);
|
||||||
|
|
||||||
int Pool ();
|
int Poll();
|
||||||
protected:
|
protected:
|
||||||
void Parse();
|
void Parse();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -647,7 +647,7 @@ OFF
|
|||||||
[22:25:34] => Poll: 0A 06 07 D0 00 00 88 3C
|
[22:25:34] => Poll: 0A 06 07 D0 00 00 88 3C
|
||||||
|
|
||||||
|
|
||||||
POOL 2101x10
|
POLL 2101x10
|
||||||
[22:27:29] <= Response: 0A 03 14 00 23 00 00 27 10 13 88 0B 9C 00 32 00 F8 00 F2 06 FA 01 3F AD D0
|
[22:27:29] <= Response: 0A 03 14 00 23 00 00 27 10 13 88 0B 9C 00 32 00 F8 00 F2 06 FA 01 3F AD D0
|
||||||
[22:27:29] => Poll: 0A 03 08 34 00 0A 87 18
|
[22:27:29] => Poll: 0A 03 08 34 00 0A 87 18
|
||||||
|
|
||||||
@@ -854,7 +854,7 @@ int Item::checkFM() {
|
|||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("Modbus pooling error="));
|
Serial.print(F("Modbus polling error="));
|
||||||
Serial.println(result, HEX);
|
Serial.println(result, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,7 +887,7 @@ int Item::checkFM() {
|
|||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("Modbus pooling error="));
|
Serial.print(F("Modbus polling error="));
|
||||||
Serial.println(result, HEX);
|
Serial.println(result, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -927,7 +927,7 @@ int Item::checkModbus() {
|
|||||||
Serial.println(data, HEX);
|
Serial.println(data, HEX);
|
||||||
checkModbus(data);
|
checkModbus(data);
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("Modbus pooling error="));
|
Serial.print(F("Modbus polling error="));
|
||||||
Serial.println(result, HEX);
|
Serial.println(result, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,7 +969,7 @@ int Item::checkModbus(int data) {
|
|||||||
} //if data changed
|
} //if data changed
|
||||||
}
|
}
|
||||||
|
|
||||||
int Item::Pool() {
|
int Item::Poll() {
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
checkModbus();
|
checkModbus();
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Item
|
|||||||
inline int On (){Ctrl(CMD_ON);};
|
inline int On (){Ctrl(CMD_ON);};
|
||||||
inline int Off(){Ctrl(CMD_OFF);};
|
inline int Off(){Ctrl(CMD_OFF);};
|
||||||
inline int Toggle(){Ctrl(CMD_TOGGLE);};
|
inline int Toggle(){Ctrl(CMD_TOGGLE);};
|
||||||
int Pool ();
|
int Poll();
|
||||||
int SendCmd(short cmd,short n=0, int * Par=NULL);
|
int SendCmd(short cmd,short n=0, int * Par=NULL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ extern Artnet *artnet;
|
|||||||
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
||||||
#define subprefix "/myhome/in/#"
|
#define subprefix "/myhome/in/#"
|
||||||
|
|
||||||
aJsonObject *aJsonObjectRoot = NULL;
|
aJsonObject *root = NULL;
|
||||||
aJsonObject *items = NULL;
|
aJsonObject *items = NULL;
|
||||||
aJsonObject *inputs = NULL;
|
aJsonObject *inputs = NULL;
|
||||||
|
|
||||||
@@ -597,10 +597,10 @@ void _kill(int arg_cnt, char **args) {
|
|||||||
|
|
||||||
#define EEPROM_offset 32+6
|
#define EEPROM_offset 32+6
|
||||||
|
|
||||||
void parseConfigFromParsedJSON() {
|
void applyConfig() {
|
||||||
int arrayItemValue, itemsCount;
|
int arrayItemValue, itemsCount;
|
||||||
//DMX out is configured
|
//DMX out is configured
|
||||||
aJsonObject *dmxoutArr = aJson.getObjectItem(aJsonObjectRoot, "dmx");
|
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
if (dmxoutArr && aJson.getArraySize(dmxoutArr) == 2) {
|
if (dmxoutArr && aJson.getArraySize(dmxoutArr) == 2) {
|
||||||
DMXoutSetup(arrayItemValue = aJson.getArrayItem(dmxoutArr, 1)->valueint,
|
DMXoutSetup(arrayItemValue = aJson.getArrayItem(dmxoutArr, 1)->valueint,
|
||||||
@@ -611,7 +611,7 @@ void parseConfigFromParsedJSON() {
|
|||||||
#endif
|
#endif
|
||||||
//DMX in is configured
|
//DMX in is configured
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
dmxArr = aJson.getObjectItem(aJsonObjectRoot, "dmxin");
|
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||||
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
||||||
DMXinSetup(itemsCount * 4);
|
DMXinSetup(itemsCount * 4);
|
||||||
Serial.print(F("DMX in started. Channels:"));
|
Serial.print(F("DMX in started. Channels:"));
|
||||||
@@ -619,18 +619,18 @@ void parseConfigFromParsedJSON() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
items = aJson.getObjectItem(aJsonObjectRoot, "items");
|
items = aJson.getObjectItem(root, "items");
|
||||||
modbusitem = items->child;
|
modbusitem = items->child;
|
||||||
inputs = aJson.getObjectItem(aJsonObjectRoot, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
modbusArr = aJson.getObjectItem(aJsonObjectRoot, "modbus");
|
modbusArr = aJson.getObjectItem(root, "modbus");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mqttArr = aJson.getObjectItem(aJsonObjectRoot, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
owArr = aJson.getObjectItem(aJsonObjectRoot, "ow");
|
owArr = aJson.getObjectItem(root, "ow");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Serial.println(F("Configured:"));
|
Serial.println(F("Configured:"));
|
||||||
@@ -679,15 +679,15 @@ int loadConfigFromEEPROM(int arg_cnt, char **args)
|
|||||||
ch = EEPROM.read(EEPROM_offset);
|
ch = EEPROM.read(EEPROM_offset);
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset);
|
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset);
|
||||||
aJson.deleteItem(aJsonObjectRoot);
|
aJson.deleteItem(root);
|
||||||
aJsonObjectRoot = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if (!aJsonObjectRoot) {
|
if (!root) {
|
||||||
Serial.println(F("load failed"));
|
Serial.println(F("load failed"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
Serial.println(F("Loaded"));
|
||||||
parseConfigFromParsedJSON();
|
applyConfig();
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("No stored config"));
|
Serial.println(F("No stored config"));
|
||||||
@@ -726,14 +726,14 @@ int mqttConfigResp(char *as) {
|
|||||||
//aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
//aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
||||||
|
|
||||||
//aJson.deleteItem(root);
|
//aJson.deleteItem(root);
|
||||||
aJsonObjectRoot = aJson.parse(as);
|
root = aJson.parse(as);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if (!aJsonObjectRoot) {
|
if (!root) {
|
||||||
Serial.println(F("load failed"));
|
Serial.println(F("load failed"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
Serial.println(F("Loaded"));
|
||||||
parseConfigFromParsedJSON();
|
applyConfig();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +742,7 @@ void _saveConfigToEEPROM(int arg_cnt, char **args)
|
|||||||
{
|
{
|
||||||
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset);
|
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset);
|
||||||
Serial.println(F("Saving config to EEPROM.."));
|
Serial.println(F("Saving config to EEPROM.."));
|
||||||
aJson.print(aJsonObjectRoot, &jsonEEPROMStream);
|
aJson.print(root, &jsonEEPROMStream);
|
||||||
jsonEEPROMStream.putEOF();
|
jsonEEPROMStream.putEOF();
|
||||||
Serial.println(F("Saved to EEPROM"));
|
Serial.println(F("Saved to EEPROM"));
|
||||||
}
|
}
|
||||||
@@ -822,20 +822,20 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
|
|
||||||
Serial.println(F("got Config"));
|
Serial.println(F("got Config"));
|
||||||
aJsonFileStream as = aJsonFileStream(result);
|
aJsonFileStream as = aJsonFileStream(result);
|
||||||
aJson.deleteItem(aJsonObjectRoot);
|
aJson.deleteItem(root);
|
||||||
aJsonObjectRoot = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
||||||
|
|
||||||
if (!aJsonObjectRoot) {
|
if (!root) {
|
||||||
Serial.println(F("Config parsing failed"));
|
Serial.println(F("Config parsing failed"));
|
||||||
lanCheck = millis() + 15000;
|
lanCheck = millis() + 15000;
|
||||||
return -11;
|
return -11;
|
||||||
} else {
|
} else {
|
||||||
char *outstr = aJson.print(aJsonObjectRoot);
|
char *outstr = aJson.print(root);
|
||||||
Serial.println(outstr);
|
Serial.println(outstr);
|
||||||
free(outstr);
|
free(outstr);
|
||||||
|
|
||||||
parseConfigFromParsedJSON();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -877,10 +877,10 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
//Serial.print("GET Response: ");
|
//Serial.print("GET Response: ");
|
||||||
|
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
aJson.deleteItem(aJsonObjectRoot);
|
aJson.deleteItem(root);
|
||||||
aJsonObjectRoot = aJson.parse((char *) response.c_str());
|
root = aJson.parse((char *) response.c_str());
|
||||||
|
|
||||||
if (!aJsonObjectRoot) {
|
if (!root) {
|
||||||
Serial.println(F("Config parsing failed"));
|
Serial.println(F("Config parsing failed"));
|
||||||
// lanCheck=millis()+15000;
|
// lanCheck=millis()+15000;
|
||||||
return -11; //Load from NVRAM
|
return -11; //Load from NVRAM
|
||||||
@@ -891,7 +891,7 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
free (outstr);
|
free (outstr);
|
||||||
*/
|
*/
|
||||||
Serial.println(response);
|
Serial.println(response);
|
||||||
parseConfigFromParsedJSON();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1095,7 +1095,7 @@ void inputLoop(void) {
|
|||||||
while (input) {
|
while (input) {
|
||||||
if ((input->type == aJson_Object)) {
|
if ((input->type == aJson_Object)) {
|
||||||
Input in(input);
|
Input in(input);
|
||||||
in.Pool();
|
in.Poll();
|
||||||
}
|
}
|
||||||
input = input->next;
|
input = input->next;
|
||||||
}
|
}
|
||||||
@@ -1117,7 +1117,7 @@ void modbusLoop(void) {
|
|||||||
//case CH_VCTEMP:
|
//case CH_VCTEMP:
|
||||||
case CH_VC: {
|
case CH_VC: {
|
||||||
Item it(modbusitem);
|
Item it(modbusitem);
|
||||||
it.Pool();
|
it.Poll();
|
||||||
modbuscheck = millis() + 2000;
|
modbuscheck = millis() + 2000;
|
||||||
done = true;
|
done = true;
|
||||||
break; //case;
|
break; //case;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ 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 parseConfigFromParsedJSON();
|
void applyConfig();
|
||||||
void _loadConfig (int arg_cnt, char **args);
|
void _loadConfig (int arg_cnt, char **args);
|
||||||
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
||||||
void _mqttConfigRequest(int arg_cnt, char **args);
|
void _mqttConfigRequest(int arg_cnt, char **args);
|
||||||
|
|||||||
@@ -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