Motor driver with feedback input (Airflow regulator Dospel)

items pulling reworked
This commit is contained in:
2019-11-03 03:31:32 +03:00
parent 23167b4f1c
commit c947c8bb4c
14 changed files with 383 additions and 49 deletions

View File

@@ -40,6 +40,7 @@ e-mail anklimov@gmail.com
#include <PubSubClient.h>
#include "modules/out_spiled.h"
#include "modules/out_ac.h"
#include "modules/out_motor.h"
short modbusBusy = 0;
extern aJsonObject *pollingItem;
@@ -122,7 +123,7 @@ void Item::Parse() {
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
itemArg = aJson.getArrayItem(itemArr, I_ARG);
itemVal = aJson.getArrayItem(itemArr, I_VAL);
itemExt = aJson.getArrayItem(itemArr, I_EXT);
switch (itemType)
{
#ifndef SPILED_DISABLE
@@ -138,6 +139,13 @@ void Item::Parse() {
// debugSerial<<F("AC driver created")<<endl;
break;
#endif
#ifndef MOTOR_DISABLE
case CH_MOTOR:
driver = new out_Motor (this);
// debugSerial<<F("AC driver created")<<endl;
break;
#endif
default: ;
}
// debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl;
@@ -297,6 +305,32 @@ void Item::setVal(long int par) // Only store if VAL is int (autogenerated or c
}
long int Item::getExt() //Return Val if val is int or first elem of Value array
{
if (!itemExt) return 0;//-1;
if (itemExt->type == aJson_Int) return itemExt->valueint;
else if (itemExt->type == aJson_Array) {
aJsonObject *t = aJson.getArrayItem(itemExt, 0);
if (t) return t->valueint;
else return 0;//-3;
} else return 0;//-2;
}
void Item::setExt(long int par) // Only store if VAL is int (autogenerated or config-defined)
{
if (!itemExt)
{
for (int i = aJson.getArraySize(itemArr); i <= 4; i++)
aJson.addItemToArray(itemArr, aJson.createItem(0));
itemExt = aJson.getArrayItem(itemArr, I_EXT);
};
if(itemExt->type != aJson_Int) return;
itemExt->valueint = par;
debugSerial<<F("Stored EXT:")<<par<<endl;
}
boolean Item::isValid() {
return (itemArr && (itemArr->type == aJson_Array));
}
@@ -561,7 +595,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
*/
default:
res = driver->Ctrl(cmd, n, Parameters, send, suffixCode, subItem);
setCmd(cmd);
if (cmd) setCmd(cmd);
}
return res;
}
@@ -1475,13 +1509,11 @@ int Item::checkModbusDimmer(int data) {
} //if data changed
}
int Item::Poll() {
int Item::Poll(short cause) {
if (driver && driver->Status())
{
driver->Poll();
return INTERVAL_POLLING; //TODO refactoring
}
switch (cause)
{
case POLLING_SLOW:
// Legacy polling
switch (itemType) {
case CH_MODBUS:
@@ -1504,12 +1536,20 @@ int Item::Poll() {
default:
sendDelayedStatus();
}
}
if (driver && driver->Status())
{
return driver->Poll(cause);
}
return INTERVAL_POLLING;
}
void Item::sendDelayedStatus()
{
if (getFlag(SEND_COMMAND | SEND_PARAMETERS))
{ long int flags = getFlag(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<flags<<F(" Delayed Status ")<<itemArr->name<<endl;
if (flags)
{
SendStatus(SEND_COMMAND | SEND_PARAMETERS);
clearFlag(SEND_COMMAND | SEND_PARAMETERS);