multivent interim 2

This commit is contained in:
2021-04-30 11:51:29 +03:00
parent a0f99d96bc
commit ecff141f6a
3 changed files with 96 additions and 27 deletions

View File

@@ -48,6 +48,7 @@ e-mail anklimov@gmail.com
#include "modules/out_dmx.h" #include "modules/out_dmx.h"
#include "modules/out_pwm.h" #include "modules/out_pwm.h"
#include "modules/out_pid.h" #include "modules/out_pid.h"
#include "modules/out_multivent.h"
short modbusBusy = 0; short modbusBusy = 0;
extern aJsonObject *pollingItem; extern aJsonObject *pollingItem;
@@ -172,6 +173,13 @@ void Item::Parse() {
// debugSerial<<F("AC driver created")<<endl; // debugSerial<<F("AC driver created")<<endl;
break; break;
#endif #endif
#ifndef MULTIVENT_DISABLE
case CH_MULTIVENT:
driver = new out_Multivent (this);
// debugSerial<<F("AC driver created")<<endl;
break;
#endif
default: ; default: ;
} }
// debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl; // debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl;
@@ -1125,7 +1133,7 @@ int Item::SendStatus(int sendFlags) {
else return SendStatusImmediate(sendFlags); else return SendStatusImmediate(sendFlags);
} }
int Item::SendStatusImmediate(int sendFlags) { int Item::SendStatusImmediate(int sendFlags, char * subItem) {
{ {
itemCmd st(ST_VOID,CMD_VOID); itemCmd st(ST_VOID,CMD_VOID);
st.loadItem(this, true); st.loadItem(this, true);
@@ -1171,7 +1179,7 @@ int Item::SendStatus(int sendFlags) {
case ST_HSV255: case ST_HSV255:
case ST_FLOAT_CELSIUS: case ST_FLOAT_CELSIUS:
if (mqttClient.connected() && !ethernetIdleCount) if (mqttClient.connected() && !ethernetIdleCount && !subItem)
{ {
setTopic(addrstr,sizeof(addrstr),T_OUT); setTopic(addrstr,sizeof(addrstr),T_OUT);
@@ -1206,6 +1214,12 @@ int Item::SendStatus(int sendFlags) {
{ {
setTopic(addrstr,sizeof(addrstr),T_OUT); setTopic(addrstr,sizeof(addrstr),T_OUT);
strncat(addrstr, itemArr->name, sizeof(addrstr)-1); strncat(addrstr, itemArr->name, sizeof(addrstr)-1);
if (subItem)
{
strncat(addrstr, "/", sizeof(addrstr));
strncat(addrstr, subItem, sizeof(addrstr)-1);
}
strncat(addrstr, "/", sizeof(addrstr)); strncat(addrstr, "/", sizeof(addrstr));
// Preparing parameters payload ////////// // Preparing parameters payload //////////
@@ -1263,6 +1277,11 @@ int Item::SendStatus(int sendFlags) {
setTopic(addrstr,sizeof(addrstr),T_OUT); setTopic(addrstr,sizeof(addrstr),T_OUT);
strncat(addrstr, itemArr->name, sizeof(addrstr)-1); strncat(addrstr, itemArr->name, sizeof(addrstr)-1);
if (subItem)
{
strncat(addrstr, "/", sizeof(addrstr));
strncat(addrstr, subItem, sizeof(addrstr)-1);
}
strncat(addrstr, "/", sizeof(addrstr)); strncat(addrstr, "/", sizeof(addrstr));
strncat_P(addrstr, CMD_P, sizeof(addrstr)); strncat_P(addrstr, CMD_P, sizeof(addrstr));

View File

@@ -52,6 +52,7 @@ e-mail anklimov@gmail.com
#define CH_MOTOR 12 #define CH_MOTOR 12
#define CH_PID 13 #define CH_PID 13
#define CH_MBUS 14 #define CH_MBUS 14
#define CH_MULTIVENT 18
//#define CHANNEL_TYPES 13 //#define CHANNEL_TYPES 13
@@ -128,7 +129,7 @@ class Item
void setSubtype(uint8_t par); void setSubtype(uint8_t par);
int Poll(int cause); int Poll(int cause);
int SendStatus(int sendFlags); int SendStatus(int sendFlags);
int SendStatusImmediate(int sendFlags); int SendStatusImmediate(int sendFlags, char * subItem=NULL);
int isActive(); int isActive();
int getChanType(); int getChanType();
inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));}; inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));};

View File

@@ -22,7 +22,7 @@ int out_Multivent::Setup()
abstractOut::Setup(); abstractOut::Setup();
//getConfig(); //getConfig();
//Expand Argument storage to 3 //Expand Argument storage to 2
for (int i = aJson.getArraySize(item->itemArg); i < 2; i++) for (int i = aJson.getArraySize(item->itemArg); i < 2; i++)
aJson.addItemToArray(item->itemArg, aJson.createItem( (long int) 0)); aJson.addItemToArray(item->itemArg, aJson.createItem( (long int) 0));
@@ -33,13 +33,13 @@ if (gatesObj)
while (i) while (i)
{ {
aJsonObject * setObj = aJson.getObjectItem(i, "set"); aJsonObject * setObj = aJson.getObjectItem(i, "set");
if (!setObj) aJson.addNumberToObject(i, "set", (long int) 0); if (!setObj) aJson.addNumberToObject(i, "set", (long int) -1);
aJsonObject * cmdObj = aJson.getObjectItem(i, "cmd"); aJsonObject * cmdObj = aJson.getObjectItem(i, "cmd");
if (!setObj) aJson.addNumberToObject(i, "cmd", (long int) 0); if (!setObj) aJson.addNumberToObject(i, "cmd", (long int) -1);
aJsonObject * outObj = aJson.getObjectItem(i, "out"); aJsonObject * outObj = aJson.getObjectItem(i, "out");
if (!setObj) aJson.addNumberToObject(i, "out", (long int) 0); if (!setObj) aJson.addNumberToObject(i, "out", (long int) -1);
i=i->next; i=i->next;
} }
@@ -91,51 +91,100 @@ int out_Multivent::getChanType()
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute) int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
{ {
aJsonObject * gateObj = NULL;
int suffixCode = cmd.getSuffix(); int suffixCode = cmd.getSuffix();
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
//if (subItem && gatesObj)
//{
//gateObj = aJson.getObjectItem(gatesObj,subItem);
//}
aJsonObject * i = NULL; aJsonObject * i = NULL;
if (gatesObj) i = gatesObj->child; aJsonObject * currentGateObj = NULL;
if (gatesObj) i = gatesObj->child; // Pass 1 - calculate summ air value, max value etc
int activeV = 0; int activeV = 0;
int totalV = 0; int totalV = 0;
int gateV = 0; int gateV = 0;
char * gateEmit = NULL; //char * gateEmit = NULL;
int gateCmd = 0; int gateCmd = 0;
int maxV=0;
while (i) while (i)
{ {
int V =aJson.getObjectItem(i,"V")->valueint;
aJsonObject * setObj=aJson.getObjectItem(i, "set"); aJsonObject * setObj=aJson.getObjectItem(i, "set");
aJsonObject * cmdObj=aJson.getObjectItem(i, "cmd"); aJsonObject * cmdObj=aJson.getObjectItem(i, "cmd");
if (!setObj || !cmdObj || setObj->type!=aJson_Int || cmdObj->type!=aJson_Int) continue;
int V =aJson.getObjectItem(i,"V")->valueint;
int requestedV=0;
if (subItem && !strcmp (i->name,subItem)) if (subItem && !strcmp (i->name,subItem))
{ {
gateObj=i; currentGateObj=i;
gateV=V; gateV=V;
gateEmit=aJson.getObjectItem(i,"emit")->valuestring; // gateEmit=aJson.getObjectItem(i,"emit")->valuestring;
gateCmd=cmdObj->valueint; gateCmd=cmdObj->valueint;
if (cmdObj && cmd.isCommand()) cmdObj->valueint = cmd.getCmd(); if (cmdObj && cmd.isCommand())
if (setObj && cmd.isValue()) setObj->valueint = cmd.getPercents255(); {
cmdObj->valueint = cmd.getCmd();
//publishTopic(i->name,cmdObj->valueint,"/set");
item->SendStatusImmediate(SEND_COMMAND,i->name);
}
if (setObj && cmd.isValue())
{
setObj->valueint = cmd.getPercents255();
//publishTopic(i->name,setObj->valueint,"/set");
item->SendStatusImmediate(SEND_PARAMETERS,i->name);
}
} }
if (cmdObj && cmdObj->valueint != CMD_OFF) activeV+=setObj->valueint*V; if (cmdObj->valueint != CMD_OFF)
{
requestedV=V*setObj->valueint;
activeV+=requestedV;
}
totalV+=V; totalV+=V;
// numberGates++;
if(requestedV>maxV) maxV=requestedV;
i=i->next; i=i->next;
} }
int fanV=activeV*255/totalV; int fanV=activeV/totalV;
debugSerial << F("Total V:")<<totalV<<F(" active V:")<<activeV<< F(" %:")<<fanV<< endl;
//RECALC gates //uint8_t nGate=0;
//APPLY every gate i=NULL;
//SUB current gate if (gatesObj) i = gatesObj->child; //Pass 2: re-distribute airflow
while (i)
{
// nGate++;
int V =aJson.getObjectItem(i,"V")->valueint;
aJsonObject * outObj=aJson.getObjectItem(i, "out");
aJsonObject * setObj=aJson.getObjectItem(i, "set");
aJsonObject * cmdObj=aJson.getObjectItem(i, "cmd");
if (!outObj || !setObj || !cmdObj || outObj->type!=aJson_Int || setObj->type!=aJson_Int || cmdObj->type!=aJson_Int) continue;
int out = 0;
if (cmdObj->valueint != CMD_OFF)
{
int requestedV=V*setObj->valueint;
int out = requestedV*255/maxV;
debugSerial<<i->name,(" Req:")<<requestedV<<F( Out:)<<out<<endl;
}
if (out != outObj->valueint)
{
//report out
executeCommand(i,-1,itemCmd().Percents255(out));
outObj->valueint=out;
}
i=i->next;
}
return 1;
switch(suffixCode) switch(suffixCode)
{ {