mirror of
https://github.com/anklimov/lighthub
synced 2025-12-07 20:29:50 +03:00
driver status, setup, stop
This commit is contained in:
@@ -1,13 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#define CST_UNKNOWN 0
|
||||||
|
#define CST_INITIALIZED 1
|
||||||
|
|
||||||
class abstractCh {
|
class abstractCh {
|
||||||
public:
|
public:
|
||||||
abstractCh(){};
|
abstractCh(){};
|
||||||
virtual ~abstractCh(){};
|
virtual ~abstractCh(){};
|
||||||
virtual int Poll() = 0;
|
virtual int Poll() = 0;
|
||||||
virtual int Setup() =0;
|
virtual int Setup() =0; //Should initialize hardware and reserve resources
|
||||||
virtual int Anounce () {};
|
virtual int Anounce () {};
|
||||||
|
virtual int Stop() {}; //Should free resources
|
||||||
|
virtual int Status() {return CST_UNKNOWN;}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int publishTopic(char* topic, long value, char* subtopic = NULL);
|
virtual int publishTopic(char* topic, long value, char* subtopic = NULL);
|
||||||
|
|||||||
@@ -135,15 +135,33 @@ void Item::Parse() {
|
|||||||
{
|
{
|
||||||
case CH_SPILED:
|
case CH_SPILED:
|
||||||
driver = new out_SPILed (this);
|
driver = new out_SPILed (this);
|
||||||
|
debugSerial<<F("SPILED driver created")<<endl;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << endl;
|
// 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()
|
Item::~Item()
|
||||||
{
|
{
|
||||||
if (driver) delete driver;
|
if (driver)
|
||||||
|
{
|
||||||
|
delete driver;
|
||||||
|
debugSerial<<F("Driver destroyed")<<endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Item(char *name) //Constructor
|
Item::Item(char *name) //Constructor
|
||||||
@@ -1222,6 +1240,13 @@ int Item::checkModbusDimmer(int data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Item::Poll() {
|
int Item::Poll() {
|
||||||
|
|
||||||
|
if (driver && driver->Status())
|
||||||
|
{
|
||||||
|
driver->Poll();
|
||||||
|
return INTERVAL_POLLING; //TODO refactoring
|
||||||
|
}
|
||||||
|
// Legacy polling
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
checkModbusDimmer();
|
checkModbusDimmer();
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ class Item
|
|||||||
~Item();
|
~Item();
|
||||||
|
|
||||||
boolean isValid ();
|
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(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);
|
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -907,7 +907,8 @@ void applyConfig() {
|
|||||||
while (items && item)
|
while (items && item)
|
||||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
||||||
Item it(item);
|
Item it(item);
|
||||||
if (it.isValid()) {
|
if (it.isValid() && !it.Setup()) {
|
||||||
|
//Legacy Setup
|
||||||
short inverse = 0;
|
short inverse = 0;
|
||||||
int pin=it.getArg();
|
int pin=it.getArg();
|
||||||
if (pin<0) {pin=-pin; inverse = 1;}
|
if (pin<0) {pin=-pin; inverse = 1;}
|
||||||
|
|||||||
@@ -7,16 +7,33 @@
|
|||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
|
||||||
#define NUM_LEDS 60
|
#define NUM_LEDS 60
|
||||||
#define DATA_PIN 11
|
#define DATA_PIN 4
|
||||||
|
|
||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
|
static int driverStatus = CST_UNKNOWN;
|
||||||
|
|
||||||
int out_SPILed::Setup()
|
int out_SPILed::Setup()
|
||||||
{
|
{
|
||||||
Serial.println("SPI-LED Init");
|
Serial.println("SPI-LED Init");
|
||||||
FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
|
FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
|
||||||
|
driverStatus = CST_INITIALIZED;
|
||||||
return 1;
|
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()
|
int out_SPILed::Poll()
|
||||||
{
|
{
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
@@ -32,7 +49,7 @@ if (subItem)
|
|||||||
from=atoi(subItem);
|
from=atoi(subItem);
|
||||||
to=from;
|
to=from;
|
||||||
}
|
}
|
||||||
|
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd<<endl;
|
||||||
for (n=from;n<=to;n++)
|
for (n=from;n<=to;n++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ public:
|
|||||||
out_SPILed(Item * _item):abstractOut(_item){};
|
out_SPILed(Item * _item):abstractOut(_item){};
|
||||||
int Setup() override;
|
int Setup() override;
|
||||||
int Poll() 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:
|
protected:
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user