mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Multi-ventilation - alpha
This commit is contained in:
@@ -648,6 +648,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
|||||||
bool chActive = (isActive()>0);
|
bool chActive = (isActive()>0);
|
||||||
bool toExecute = chActive; // execute if channel is active now
|
bool toExecute = chActive; // execute if channel is active now
|
||||||
bool scale100 = false;
|
bool scale100 = false;
|
||||||
|
|
||||||
debugSerial<<endl;
|
debugSerial<<endl;
|
||||||
|
|
||||||
if (itemType != CH_GROUP )
|
if (itemType != CH_GROUP )
|
||||||
@@ -655,15 +656,30 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
|
|||||||
//Check if subitem is some sort of command
|
//Check if subitem is some sort of command
|
||||||
int subitemCmd = subitem2cmd(subItem);
|
int subitemCmd = subitem2cmd(subItem);
|
||||||
short prevCmd = getCmd();
|
short prevCmd = getCmd();
|
||||||
if (!prevCmd && chActive>0) prevCmd=CMD_ON;
|
if (!prevCmd && chActive) prevCmd=CMD_ON;
|
||||||
|
|
||||||
if (subitemCmd && subitemCmd != prevCmd)
|
if (subitemCmd) //Find some COMMAND in subitem
|
||||||
|
{
|
||||||
|
if (subitemCmd != prevCmd)
|
||||||
{
|
{
|
||||||
debugSerial<<F("Ignored, channel cmd=")<<prevCmd<<endl;
|
debugSerial<<F("Ignored, channel cmd=")<<prevCmd<<endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
subItem=NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subItem) // Fast track for commands to subitems
|
||||||
|
{
|
||||||
|
if (itemType==CH_GROUP)
|
||||||
|
{
|
||||||
|
if (allowRecursion && itemArg->type == aJson_Array && operation) digGroup(itemArg,&cmd,subItem);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (driver) return driver->Ctrl(cmd,subItem,toExecute);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
itemCmd st(ST_VOID,CMD_VOID);
|
itemCmd st(ST_VOID,CMD_VOID);
|
||||||
|
|
||||||
//Restore previous channel state to "st"
|
//Restore previous channel state to "st"
|
||||||
@@ -1130,16 +1146,17 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
debugSerial<<F("Status deffered\n");
|
debugSerial<<F("Status deffered\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else return SendStatusImmediate(sendFlags);
|
else
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
|
sendFlags |= getFlag(SEND_COMMAND | SEND_PARAMETERS); //if some delayed status is pending
|
||||||
sendFlags |= getFlag(SEND_COMMAND | SEND_PARAMETERS); //if some delayed status is pending
|
return SendStatusImmediate(st,sendFlags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Item::SendStatusImmediate(itemCmd st, int sendFlags, char * subItem) {
|
||||||
|
{
|
||||||
char addrstr[48];
|
char addrstr[48];
|
||||||
char valstr[20] = "";
|
char valstr[20] = "";
|
||||||
char cmdstr[8] = "";
|
char cmdstr[8] = "";
|
||||||
|
|||||||
@@ -129,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, char * subItem=NULL);
|
int SendStatusImmediate(itemCmd st, 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));};
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ static int driverStatus = CST_UNKNOWN;
|
|||||||
void out_Multivent::getConfig()
|
void out_Multivent::getConfig()
|
||||||
{
|
{
|
||||||
gatesObj = NULL;
|
gatesObj = NULL;
|
||||||
if (!item || !item->itemArg || !item->itemArg->type != aJson_Array) return;
|
if (!item || !item->itemArg || item->itemArg->type != aJson_Object) return;
|
||||||
gatesObj = aJson.getArrayItem(item->itemArg,1);
|
gatesObj = item->itemArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Multivent::Setup()
|
int out_Multivent::Setup()
|
||||||
@@ -23,31 +23,36 @@ abstractOut::Setup();
|
|||||||
//getConfig();
|
//getConfig();
|
||||||
|
|
||||||
//Expand Argument storage to 2
|
//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));
|
||||||
|
|
||||||
//Allocate objects to store persistent data in config tree
|
//Allocate objects to store persistent data in config tree
|
||||||
if (gatesObj)
|
if (gatesObj /*&& aJson.getArraySize(item->itemArg)>=2*/)
|
||||||
{
|
{
|
||||||
aJsonObject * i = gatesObj->child;
|
aJsonObject * i = gatesObj->child;
|
||||||
while (i)
|
while (i)
|
||||||
{
|
{
|
||||||
|
if (i->name && *i->name)
|
||||||
|
{
|
||||||
aJsonObject * setObj = aJson.getObjectItem(i, "set");
|
aJsonObject * setObj = aJson.getObjectItem(i, "set");
|
||||||
if (!setObj) aJson.addNumberToObject(i, "set", (long int) -1);
|
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) -1);
|
if (!cmdObj) 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) -1);
|
if (!outObj) aJson.addNumberToObject(i, "out", (long int) -1);
|
||||||
|
}
|
||||||
i=i->next;
|
i=i->next;
|
||||||
}
|
}
|
||||||
|
debugSerial << F ("MultiVent init")<< endl;
|
||||||
|
driverStatus = CST_INITIALIZED;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSerial << F ("MultiVent init")<< endl;
|
debugSerial << F ("MultiVent config failed")<< endl;
|
||||||
driverStatus = CST_INITIALIZED;
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int out_Multivent::Stop()
|
int out_Multivent::Stop()
|
||||||
@@ -96,91 +101,97 @@ 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
|
||||||
|
|
||||||
aJsonObject * i = NULL;
|
aJsonObject * i = NULL;
|
||||||
aJsonObject * currentGateObj = NULL;
|
|
||||||
|
|
||||||
if (gatesObj) i = gatesObj->child; // Pass 1 - calculate summ air value, max value etc
|
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;
|
|
||||||
//char * gateEmit = NULL;
|
|
||||||
int gateCmd = 0;
|
|
||||||
int maxV=0;
|
int maxV=0;
|
||||||
|
int maxRequestedV=0;
|
||||||
|
int maxPercent=0;
|
||||||
|
|
||||||
|
|
||||||
while (i)
|
while (i)
|
||||||
{
|
{
|
||||||
|
|
||||||
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;
|
if (setObj && cmdObj && setObj->type==aJson_Int && cmdObj->type==aJson_Int)
|
||||||
|
{
|
||||||
|
|
||||||
int V =aJson.getObjectItem(i,"V")->valueint;
|
int V =aJson.getObjectItem(i,"V")->valueint;
|
||||||
int requestedV=0;
|
int requestedV=0;
|
||||||
|
|
||||||
if (subItem && !strcmp (i->name,subItem))
|
if (subItem && !strcmp (i->name,subItem))
|
||||||
{
|
{
|
||||||
currentGateObj=i;
|
if (cmdObj && cmd.isCommand())
|
||||||
gateV=V;
|
{
|
||||||
// gateEmit=aJson.getObjectItem(i,"emit")->valuestring;
|
cmdObj->valueint = cmd.getCmd();
|
||||||
|
//publishTopic(i->name,cmdObj->valueint,"/set");
|
||||||
|
if (isNotRetainingStatus()) item->SendStatusImmediate(cmd,SEND_COMMAND,i->name);
|
||||||
|
}
|
||||||
|
if (setObj && cmd.isValue())
|
||||||
|
{
|
||||||
|
setObj->valueint = cmd.getPercents255();
|
||||||
|
//publishTopic(i->name,setObj->valueint,"/set");
|
||||||
|
if (isNotRetainingStatus()) item->SendStatusImmediate(cmd,SEND_PARAMETERS,i->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gateCmd=cmdObj->valueint;
|
if (cmdObj->valueint != CMD_OFF)
|
||||||
if (cmdObj && cmd.isCommand())
|
{
|
||||||
{
|
requestedV=V*setObj->valueint;
|
||||||
cmdObj->valueint = cmd.getCmd();
|
activeV+=requestedV;
|
||||||
//publishTopic(i->name,cmdObj->valueint,"/set");
|
}
|
||||||
item->SendStatusImmediate(SEND_COMMAND,i->name);
|
totalV+=V;
|
||||||
}
|
|
||||||
if (setObj && cmd.isValue())
|
|
||||||
{
|
|
||||||
setObj->valueint = cmd.getPercents255();
|
|
||||||
//publishTopic(i->name,setObj->valueint,"/set");
|
|
||||||
item->SendStatusImmediate(SEND_PARAMETERS,i->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmdObj->valueint != CMD_OFF)
|
|
||||||
{
|
|
||||||
requestedV=V*setObj->valueint;
|
|
||||||
activeV+=requestedV;
|
|
||||||
}
|
|
||||||
totalV+=V;
|
|
||||||
// numberGates++;
|
|
||||||
|
|
||||||
if(requestedV>maxV) maxV=requestedV;
|
|
||||||
|
|
||||||
|
//if(requestedV>maxRequestedV)
|
||||||
|
if (setObj->valueint>maxPercent)
|
||||||
|
{
|
||||||
|
maxRequestedV=requestedV;
|
||||||
|
maxV=V;
|
||||||
|
maxPercent=setObj->valueint;
|
||||||
|
}
|
||||||
|
}
|
||||||
i=i->next;
|
i=i->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fanV=activeV/totalV;
|
if (!totalV) return 0;
|
||||||
debugSerial << F("Total V:")<<totalV<<F(" active V:")<<activeV<< F(" %:")<<fanV<< endl;
|
|
||||||
|
int fanV=activeV/totalV;
|
||||||
|
debugSerial << F("Total V:")<<totalV<<F(" active V:")<<activeV/255<< F(" fan%:")<<fanV<< F(" Max request:")<<maxRequestedV/255 <<F(" from ")<<maxV<<F(" m3")<< endl;
|
||||||
|
|
||||||
|
executeCommand(aJson.getObjectItem(gatesObj, ""),-1,itemCmd().Percents255(fanV));
|
||||||
|
|
||||||
//uint8_t nGate=0;
|
|
||||||
i=NULL;
|
i=NULL;
|
||||||
if (gatesObj) i = gatesObj->child; //Pass 2: re-distribute airflow
|
if (gatesObj) i = gatesObj->child; //Pass 2: re-distribute airflow
|
||||||
|
|
||||||
while (i)
|
while (i)
|
||||||
{
|
{
|
||||||
// nGate++;
|
|
||||||
int V =aJson.getObjectItem(i,"V")->valueint;
|
int V =aJson.getObjectItem(i,"V")->valueint;
|
||||||
|
|
||||||
aJsonObject * outObj=aJson.getObjectItem(i, "out");
|
aJsonObject * outObj=aJson.getObjectItem(i, "out");
|
||||||
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 (!outObj || !setObj || !cmdObj || outObj->type!=aJson_Int || setObj->type!=aJson_Int || cmdObj->type!=aJson_Int) continue;
|
if (outObj && setObj && cmdObj && outObj->type==aJson_Int && setObj->type==aJson_Int && cmdObj->type==aJson_Int && V)
|
||||||
int out = 0;
|
{
|
||||||
if (cmdObj->valueint != CMD_OFF)
|
long int out = 0;
|
||||||
{
|
if (cmdObj->valueint != CMD_OFF && maxRequestedV)
|
||||||
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
|
int requestedV=V*setObj->valueint;
|
||||||
executeCommand(i,-1,itemCmd().Percents255(out));
|
out = (( long)requestedV*255L)/(( long)V)*( long)maxV/( long)maxRequestedV;
|
||||||
outObj->valueint=out;
|
debugSerial<<i->name<<(" Req:")<<requestedV/255<<F(" Out:")<<out<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// executeCommand(i,-1,itemCmd().Percents255(out));
|
||||||
|
if (out != outObj->valueint)
|
||||||
|
{
|
||||||
|
//report out
|
||||||
|
executeCommand(i,-1,itemCmd().Percents255(out));
|
||||||
|
outObj->valueint=out;
|
||||||
|
}
|
||||||
|
}
|
||||||
i=i->next;
|
i=i->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "itemCmd.h"
|
#include "itemCmd.h"
|
||||||
|
|
||||||
|
|
||||||
static int8_t motorQuote = 0;
|
//static int8_t motorQuote = 0;
|
||||||
|
|
||||||
class out_Multivent : public abstractOut {
|
class out_Multivent : public abstractOut {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user