mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
text chan types, comp options, counter fixed
This commit is contained in:
@@ -15,4 +15,5 @@
|
|||||||
-DTIMER_INT
|
-DTIMER_INT
|
||||||
|
|
||||||
-DRESTART_LAN_ON_MQTT_ERRORS
|
-DRESTART_LAN_ON_MQTT_ERRORS
|
||||||
-DOTA_PORT=80
|
-DOTA_PORT=80
|
||||||
|
-DMERCURY_ENABLE
|
||||||
@@ -56,4 +56,5 @@
|
|||||||
-DMQTT_KEEPALIVE=10
|
-DMQTT_KEEPALIVE=10
|
||||||
-DMQTT_SOCKET_TIMEOUT=20
|
-DMQTT_SOCKET_TIMEOUT=20
|
||||||
-D CORS=\"*\"
|
-D CORS=\"*\"
|
||||||
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
||||||
|
-DMERCURY_ENABLE
|
||||||
@@ -38,5 +38,5 @@
|
|||||||
-DOTA_PORT=80
|
-DOTA_PORT=80
|
||||||
-D CORS=\"*\"
|
-D CORS=\"*\"
|
||||||
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
||||||
#-D MERCURY_ENABLE
|
-D MERCURY_ENABLE
|
||||||
#-D IPMODBUS
|
#-D IPMODBUS
|
||||||
@@ -6,6 +6,12 @@
|
|||||||
-DARDUINO_OTA_MDNS_DISABLE
|
-DARDUINO_OTA_MDNS_DISABLE
|
||||||
-DMDNS_ENABLE
|
-DMDNS_ENABLE
|
||||||
|
|
||||||
|
-DNO_HOMIE
|
||||||
|
-DCSSHDC_DISABLE
|
||||||
|
-DSPILED_DISABLE
|
||||||
|
-DAC_DISABLE
|
||||||
|
|
||||||
|
|
||||||
-DRESTART_LAN_ON_MQTT_ERRORS
|
-DRESTART_LAN_ON_MQTT_ERRORS
|
||||||
-D CORS=\"*\"
|
-D CORS=\"*\"
|
||||||
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
||||||
|
|||||||
@@ -27,3 +27,4 @@
|
|||||||
# Example of UARTBRIDGE configuration
|
# Example of UARTBRIDGE configuration
|
||||||
#-DUARTBRIDGE_ENABLE
|
#-DUARTBRIDGE_ENABLE
|
||||||
-DOTA_PORT=80
|
-DOTA_PORT=80
|
||||||
|
-DMERCURY_ENABLE
|
||||||
|
|||||||
@@ -15,4 +15,5 @@
|
|||||||
#-DMCP23017
|
#-DMCP23017
|
||||||
|
|
||||||
-D CORS=\"*\"
|
-D CORS=\"*\"
|
||||||
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
|
||||||
|
-DMERCURY_ENABLE
|
||||||
@@ -36,4 +36,5 @@
|
|||||||
-D HAL_CAN_MODULE_ENABLED
|
-D HAL_CAN_MODULE_ENABLED
|
||||||
#HAL_ETH_MODULE_DISABLED
|
#HAL_ETH_MODULE_DISABLED
|
||||||
#HAL_SD_MODULE_DISABLED
|
#HAL_SD_MODULE_DISABLED
|
||||||
#HAL_DAC_MODULE_DISABLED
|
#HAL_DAC_MODULE_DISABLED
|
||||||
|
-DMERCURY_ENABLE
|
||||||
@@ -140,7 +140,8 @@ void Item::Parse() {
|
|||||||
for (int i = aJson.getArraySize(itemArr); i < 4; i++)
|
for (int i = aJson.getArraySize(itemArr); i < 4; i++)
|
||||||
aJson.addItemToArray(itemArr, aJson.createNull());//( (long int) 0));
|
aJson.addItemToArray(itemArr, aJson.createNull());//( (long int) 0));
|
||||||
// int(defval[i]) )); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
// 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;
|
||||||
|
itemType = replaceTypeToInt (aJson.getArrayItem(itemArr, I_TYPE));
|
||||||
itemArg = aJson.getArrayItem(itemArr, I_ARG);
|
itemArg = aJson.getArrayItem(itemArr, I_ARG);
|
||||||
itemVal = aJson.getArrayItem(itemArr, I_VAL);
|
itemVal = aJson.getArrayItem(itemArr, I_VAL);
|
||||||
itemExt = aJson.getArrayItem(itemArr, I_EXT);
|
itemExt = aJson.getArrayItem(itemArr, I_EXT);
|
||||||
@@ -794,6 +795,8 @@ int Item::scheduleOppositeCommand(itemCmd cmd,bool authorized)
|
|||||||
break;
|
break;
|
||||||
case CMD_RESTORE: nextCmd.Cmd(CMD_HALT);
|
case CMD_RESTORE: nextCmd.Cmd(CMD_HALT);
|
||||||
break;
|
break;
|
||||||
|
case CMD_TOGGLE: nextCmd.Cmd(CMD_TOGGLE);
|
||||||
|
break;
|
||||||
|
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
@@ -1341,12 +1344,12 @@ if (invalidArgument) return -4;
|
|||||||
|
|
||||||
if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
||||||
{
|
{
|
||||||
// UPDATE internal variables
|
|
||||||
if (status2Send) cmd.saveItem(this,status2Send);
|
|
||||||
//debugSerial<<F("sts:")<<status2Send<<endl;
|
|
||||||
|
|
||||||
if (driver) //New style modular code
|
if (driver) //New style modular code
|
||||||
{
|
{
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
|
|
||||||
res = driver->Ctrl(cmd, subItem, toExecute,authorized);
|
res = driver->Ctrl(cmd, subItem, toExecute,authorized);
|
||||||
if (driver->getChanType() == CH_THERMO) status2Send |= FLAG_SEND_IMMEDIATE;
|
if (driver->getChanType() == CH_THERMO) status2Send |= FLAG_SEND_IMMEDIATE;
|
||||||
//if (res==-1) status2Send=0; ///////not working
|
//if (res==-1) status2Send=0; ///////not working
|
||||||
@@ -1365,6 +1368,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
short icmd =cmd.getCmd();
|
short icmd =cmd.getCmd();
|
||||||
if (!authorized && isProtectedPin(iaddr)) {errorSerial<<F("Unauthorized")<<endl; return -5;}
|
if (!authorized && isProtectedPin(iaddr)) {errorSerial<<F("Unauthorized")<<endl; return -5;}
|
||||||
|
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
|
|
||||||
if (iaddr)
|
if (iaddr)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
@@ -1409,6 +1415,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
}
|
}
|
||||||
|
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
|
|
||||||
switch (suffixCode)
|
switch (suffixCode)
|
||||||
{
|
{
|
||||||
case S_VAL:
|
case S_VAL:
|
||||||
@@ -1438,6 +1447,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
|
|
||||||
#ifndef MODBUS_DISABLE
|
#ifndef MODBUS_DISABLE
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
|
|
||||||
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue()))
|
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue()))
|
||||||
{
|
{
|
||||||
int vol;
|
int vol;
|
||||||
@@ -1451,9 +1463,13 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetFan(cmd);
|
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetFan(cmd);
|
||||||
break;
|
break;
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
|
// UPDATE internal variables
|
||||||
|
if (status2Send) cmd.saveItem(this,status2Send);
|
||||||
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetHeat(cmd);
|
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetHeat(cmd);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,6 +39,20 @@ int txt2cmd(char *payload) {
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int type2num(char *payload) {
|
||||||
|
if (!payload || !payload[0]) return -1;
|
||||||
|
|
||||||
|
for(uint8_t i=0; i<ch_typeNum ;i++)
|
||||||
|
if (strncmp_P(payload, ch_type_P[i], strlen_P(ch_type_P[i])) == 0)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Constructor with definition of type and command
|
\brief Constructor with definition of type and command
|
||||||
\param type - type of value (ST_???, ST_VOID by default)
|
\param type - type of value (ST_???, ST_VOID by default)
|
||||||
@@ -1180,6 +1194,22 @@ return false;
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int replaceTypeToInt(aJsonObject* verb)
|
||||||
|
{
|
||||||
|
if (verb && verb->type == aJson_String)
|
||||||
|
{
|
||||||
|
int type = type2num(verb->valuestring);
|
||||||
|
if (type>=0)
|
||||||
|
{
|
||||||
|
freeString(verb->valuestring);
|
||||||
|
verb->valueint=type;
|
||||||
|
verb->type=aJson_Int;
|
||||||
|
return verb->valueint;
|
||||||
|
}
|
||||||
|
} else if (verb && verb->type == aJson_Int) return verb->valueint;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Mapping from unified itemCmd object to some specific device-depended value
|
// Mapping from unified itemCmd object to some specific device-depended value
|
||||||
itemCmd itemCmd::doMapping(aJsonObject *mappingData)
|
itemCmd itemCmd::doMapping(aJsonObject *mappingData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,8 +31,39 @@ const cmdstr commands_P[] PROGMEM =
|
|||||||
"HIGH","MEDIUM","LOW",
|
"HIGH","MEDIUM","LOW",
|
||||||
"HEAT","COOL","DRY","STOP","RGB","HSV"
|
"HEAT","COOL","DRY","STOP","RGB","HSV"
|
||||||
};
|
};
|
||||||
|
|
||||||
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
|
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
|
||||||
|
|
||||||
|
typedef char ch_type[9];
|
||||||
|
const ch_type ch_type_P[] PROGMEM =
|
||||||
|
{
|
||||||
|
"DMX", // 0 //DMX 1-4 ch
|
||||||
|
"DMXRGBW",// 1 //DMX 4 ch
|
||||||
|
"DMXRGB", // 2 //DMX 3 ch
|
||||||
|
"PWM", // 3 //PWM output directly to PIN 1-4 CH
|
||||||
|
"MBUSDIM",// 4 //Modbus AC Dimmer
|
||||||
|
"THERMO", // 5 //Simple ON/OFF thermostat
|
||||||
|
"RELAY", // 6 //ON_OFF relay output
|
||||||
|
"GROUP", // 7 //Group pseudochannel
|
||||||
|
"VCTEMP", // 8 //Vacom PID regulator
|
||||||
|
"MBUSVC", // 9 //Vacom modbus motor regulator
|
||||||
|
"ACHAIER",// 10 //AC Haier
|
||||||
|
"SPILED", // 11 //SPI led strip
|
||||||
|
"MOTOR", // 12 //Motorized gate with feedback resistor
|
||||||
|
"PID", // 13 //PID regulator
|
||||||
|
"MBUS", // 14 //Universal Modbus Master channel
|
||||||
|
"UARTBRDG", // 15 //Bridge between 2 UARTS with reporting PDUs to Wireshark via UDP
|
||||||
|
"RELAYPWM", // 16 //Slow PWM relay to control objects with inertia
|
||||||
|
"DMXRGBWW", // 17 //DMX RGBWW channel (warm&cold white)
|
||||||
|
"VENTS", // 18 //Multichannel ventilation
|
||||||
|
"ELEVATOR", // 19 //
|
||||||
|
"COUNTER", // 20 //Generic counter
|
||||||
|
"HUM", // 21 //Humidifier
|
||||||
|
"MERCURY" // 22 //Mercury energy meter/RS485 interface
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ch_typeNum sizeof(ch_type_P)/sizeof(ch_type)
|
||||||
|
|
||||||
/// Definition of Commands
|
/// Definition of Commands
|
||||||
#define CMD_ON 1 /// Turn channel ON
|
#define CMD_ON 1 /// Turn channel ON
|
||||||
#define CMD_OFF 2 /// Turn channel OFF
|
#define CMD_OFF 2 /// Turn channel OFF
|
||||||
@@ -241,4 +272,5 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int replaceTypeToInt(aJsonObject* verb);
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@@ -6,19 +6,10 @@
|
|||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
//#include "dmx.h"
|
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
static int driverStatus = CST_UNKNOWN;
|
||||||
|
|
||||||
void out_counter::getConfig()
|
|
||||||
{
|
|
||||||
if (!item) return;
|
|
||||||
impulse = item->getFloatArg(0)*TENS_BASE;
|
|
||||||
|
|
||||||
period = item->getFloatArg(1)*1000.0;
|
|
||||||
//debugSerial<<"CTR: imp:"<<impulse<<" period:"<<period<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int out_counter::Setup()
|
int out_counter::Setup()
|
||||||
{
|
{
|
||||||
abstractOut::Setup();
|
abstractOut::Setup();
|
||||||
@@ -43,22 +34,18 @@ int out_counter::Poll(short cause)
|
|||||||
if (cause==POLLING_SLOW || cause==POLLING_INT) return 0;
|
if (cause==POLLING_SLOW || cause==POLLING_INT) return 0;
|
||||||
if (!item) return 0;
|
if (!item) return 0;
|
||||||
|
|
||||||
|
uint32_t timer = item->getExt();
|
||||||
uint32_t timer = item->getExt();
|
uint32_t period = item->getFloatArg(1)*1000.0;
|
||||||
|
|
||||||
if (timer && period && isTimeOver(timer,millis(),period))
|
if (timer && period && isTimeOver(timer,millis(),period))
|
||||||
{
|
{
|
||||||
|
uint32_t impulse = item->getFloatArg(0)*TENS_BASE;
|
||||||
item->setExt(millisNZ());
|
item->setExt(millisNZ());
|
||||||
|
|
||||||
itemCmd st;
|
itemCmd st;
|
||||||
st.loadItem(item,FLAG_PARAMETERS|FLAG_COMMAND);
|
st.loadItem(item,FLAG_PARAMETERS|FLAG_COMMAND);
|
||||||
//float val = st.getFloat();
|
|
||||||
uint32_t val = st.getTens_raw();
|
uint32_t val = st.getTens_raw();
|
||||||
//short cmd = st.getCmd();
|
|
||||||
debugSerial<<"CTR: tick val:"<<val<< " + "<< impulse << endl;
|
debugSerial<<"CTR: tick val:"<<val<< " + "<< impulse << endl;
|
||||||
|
|
||||||
val+=impulse;
|
val+=impulse;
|
||||||
//st.Float(val);
|
|
||||||
st.Tens_raw(val);
|
st.Tens_raw(val);
|
||||||
st.saveItem(item);
|
st.saveItem(item);
|
||||||
debugSerial<<"CTR: tick saved val:"<<val<<endl;
|
debugSerial<<"CTR: tick saved val:"<<val<<endl;
|
||||||
|
|||||||
@@ -9,19 +9,12 @@
|
|||||||
class out_counter : public abstractOut {
|
class out_counter : public abstractOut {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
out_counter(Item * _item):abstractOut(_item){ getConfig();};
|
out_counter(Item * _item):abstractOut(_item){};
|
||||||
void getConfig();
|
|
||||||
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 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;
|
||||||
|
|
||||||
protected:
|
|
||||||
//float impulse;
|
|
||||||
uint32_t impulse;
|
|
||||||
uint32_t period;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user