driver status, setup, stop

This commit is contained in:
2019-07-19 13:52:52 +03:00
parent a24e56e941
commit fb64394571
6 changed files with 60 additions and 8 deletions

View File

@@ -1,13 +1,19 @@
#pragma once
#include "Arduino.h"
#define CST_UNKNOWN 0
#define CST_INITIALIZED 1
class abstractCh {
public:
abstractCh(){};
virtual ~abstractCh(){};
virtual int Poll() = 0;
virtual int Setup() =0;
virtual int Setup() =0; //Should initialize hardware and reserve resources
virtual int Anounce () {};
virtual int Stop() {}; //Should free resources
virtual int Status() {return CST_UNKNOWN;}
protected:
virtual int publishTopic(char* topic, long value, char* subtopic = NULL);

View File

@@ -135,15 +135,33 @@ void Item::Parse() {
{
case CH_SPILED:
driver = new out_SPILed (this);
debugSerial<<F("SPILED driver created")<<endl;
break;
}
// debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl;
}
}
boolean Item::Setup()
{
if (driver)
{
if (driver->Status()) driver->Stop();
driver->Setup();
return true;
}
else return false;
}
Item::~Item()
{
if (driver) delete driver;
if (driver)
{
delete driver;
debugSerial<<F("Driver destroyed")<<endl;
}
}
Item::Item(char *name) //Constructor
@@ -1222,6 +1240,13 @@ int Item::checkModbusDimmer(int data) {
}
int Item::Poll() {
if (driver && driver->Status())
{
driver->Poll();
return INTERVAL_POLLING; //TODO refactoring
}
// Legacy polling
switch (itemType) {
case CH_MODBUS:
checkModbusDimmer();

View File

@@ -129,6 +129,7 @@ class Item
~Item();
boolean isValid ();
boolean Setup();
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL);
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);

View File

@@ -907,7 +907,8 @@ void applyConfig() {
while (items && item)
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
Item it(item);
if (it.isValid()) {
if (it.isValid() && !it.Setup()) {
//Legacy Setup
short inverse = 0;
int pin=it.getArg();
if (pin<0) {pin=-pin; inverse = 1;}

View File

@@ -7,16 +7,33 @@
#include "FastLED.h"
#define NUM_LEDS 60
#define DATA_PIN 11
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
static int driverStatus = CST_UNKNOWN;
int out_SPILed::Setup()
{
Serial.println("SPI-LED Init");
FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
driverStatus = CST_INITIALIZED;
return 1;
}
int out_SPILed::Stop()
{
Serial.println("SPI-LED De-Init");
FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
driverStatus = CST_UNKNOWN;
return 1;
}
int out_SPILed::Status()
{
return driverStatus;
}
int out_SPILed::Poll()
{
FastLED.show();
@@ -32,7 +49,7 @@ if (subItem)
from=atoi(subItem);
to=from;
}
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd<<endl;
for (n=from;n<=to;n++)
{

View File

@@ -9,7 +9,9 @@ public:
out_SPILed(Item * _item):abstractOut(_item){};
int Setup() override;
int Poll() override;
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL) override;
int Stop() override;
int Status() override;
int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL) override;
protected:
};