REFACTORING st2 (still untested & uncomplete)

This commit is contained in:
2020-11-15 20:26:24 +03:00
parent 118fd25186
commit d81308ad4d
16 changed files with 308 additions and 266 deletions

View File

@@ -263,8 +263,9 @@ return INTERVAL_POLLING;
};
//int out_AC::Ctrl(short cmd, short n, int * Parameters, int suffixCode, char* subItem)
int out_AC::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
int out_AC::Ctrl(itemCmd cmd, char* subItem)
{char s_mode[10];
int suffixCode = cmd.getSuffix();
// Some additional Subitems
if (strcmp_P(subItem, LOCK_P) == 0) suffixCode = S_LOCK;
else if (strcmp_P(subItem, SWING_P) == 0) suffixCode = S_SWING;

View File

@@ -30,7 +30,7 @@ public:
int Status() override;
int isActive() override;
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
protected:
void InsertData(byte data[], size_t size);

View File

@@ -1,5 +1,5 @@
//#ifndef DMX_DISABLE
#ifdef XXXX
#ifndef DMX_DISABLE
#include "modules/out_dmx.h"
#include "Arduino.h"
#include "options.h"
@@ -7,128 +7,79 @@
#include "item.h"
#include "main.h"
#include "dmx.h"
static int driverStatus = CST_UNKNOWN;
int out_dmx::Setup()
{
debugSerial<<F("DMX-Out Init")<<endl;
driverStatus = CST_INITIALIZED;
return 1;
}
int out_SPILed::Stop()
int out_dmx::Stop()
{
debugSerial<<F("DMX-Out stop")<<endl;
driverStatus = CST_UNKNOWN;
return 1;
}
int out_SPILed::Status()
int out_dmx::Status()
{
return driverStatus;
}
int out_SPILed::isActive()
int out_dmx::isActive()
{
itemStore st;
itemArgStore st;
st.aslong = item->getVal(); //Restore old params
debugSerial<< F(" val:")<<st.v<<endl;
return st.v;
}
int out_SPILed::Poll(short cause)
int out_dmx::Poll(short cause)
{
return 0;
};
int out_SPILed::getChanType()
int out_dmx::getChanType()
{
if ((ledsType>>4) == (ledsType>>6))
return CH_RGB;
else
return CH_RGBW;
if (item) return item->itemType;
return 0;
}
int out_SPILed::PixelCtrl(itemCmd cmd, int from, int to, bool show)
int out_dmx::PixelCtrl(itemCmd cmd)
{
if (!item) return 0;
int iaddr = item->getArg(0);
itemCmd st(ST_RGB);
st.assignFrom(cmd);
#ifdef ADAFRUIT_LED
uint32_t pixel;
#else
CRGB pixel;
#endif
if (to>numLeds-1) to=numLeds-1;
if (from<0) from=0;
for (int i=from;i<=to;i++)
{
switch (cmd.getCmd()) {
case CMD_ON:
#ifdef ADAFRUIT_LED
if (!leds->getPixelColor(i)) leds->setPixelColor(i, leds->Color(255, 255, 255));
#else
if (!leds[i].r && !leds[i].g &&!leds[i].b) leds[i] = CRGB::White;
#endif
switch (getChanType())
{
case CH_RGBW:
DmxWrite(iaddr + 3, st.param.w);
case CH_RGB:
DmxWrite(iaddr, st.param.r);
DmxWrite(iaddr + 1, st.param.g);
DmxWrite(iaddr + 2, st.param.b);
break;
case CMD_OFF:
#ifdef ADAFRUIT_LED
leds->setPixelColor(i, leds->Color(0, 0, 0));
#else
leds[i] = CRGB::Black;
#endif
break;
default:
st.assignFrom(cmd);
#ifdef ADAFRUIT_LED
leds->setPixelColor(i, leds->Color(st.param.r,st.param.g,st.param.b));
#else
leds[i] = CRGB(st.param.r,st.param.g,st.param.b);
#endif
}
} //for
if (show)
{
#ifdef ADAFRUIT_LED
leds->show();
#else
FastLED.show();
#endif
debugSerial<<F("Show")<<endl;
}
default: ;
}
return 1;
}
int out_SPILed::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
int out_dmx::Ctrl(itemCmd cmd, char* subItem)
{
int chActive = item->isActive();
bool toExecute = (chActive>0);
bool toExecute = (chActive>0); // execute if channel is active now
int suffixCode = cmd.getSuffix();
itemCmd st(ST_HSV);
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
int from=0, to=numLeds-1; //All LEDs on the strip by default
// retrive LEDs range from suffix
if (subItem)
{ //Just single LED to control todo - range
// debugSerial<<F("Range:")<<subItem<<endl;
if (sscanf(subItem,"%d-%d",&from,&to) == 1) to=from;
}
debugSerial<<from<<F("-")<<to<<F(" cmd=")<<cmd.getCmd()<<endl;
if (!suffixCode) toExecute=true; //forced execute if no suffix
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command recognized , but w/o correct cmd suffix - threat it as command
switch(suffixCode)
{
@@ -137,17 +88,11 @@ case S_NOTFOUND:
toExecute = true;
case S_SET:
case S_HSV:
//st.Int(item->getVal()); //Restore old params
st.loadItem(item);
st.assignFrom(cmd);
PixelCtrl(st,from,to,toExecute);
if (!subItem) //Whole strip
{
//item->setVal(st.getInt()); //Store
if (toExecute) PixelCtrl(st);
st.saveItem(item);
if (!suffixCode)
{
if (chActive>0 && !st.getPercents()) item->setCmd(CMD_OFF);
@@ -155,9 +100,8 @@ case S_HSV:
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED);
}
else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
}
return 1;
//break;
/*
case S_HUE:
st.setH(uint16_t);
break;
@@ -165,62 +109,45 @@ case S_HUE:
case S_SAT:
st.setS(uint8_t);
break;
*/
case S_CMD:
item->setCmd(cmd.getCmd());
switch (cmd.getCmd())
{
case CMD_ON:
//retrive stored values
st.loadItem(item);
if (subItem) // LED range, not whole strip
PixelCtrl(st.Cmd(CMD_ON),from,to);
else //whole strip
if (st.loadItem(item))
{
if (st.param.aslong && (st.param.v<MIN_VOLUME) /* && send */) st.Percents(INIT_VOLUME);
//item->setVal(st.getInt());
st.saveItem(item);
if (st.param.aslong && (st.param.v<MIN_VOLUME)) {
st.Percents(INIT_VOLUME);
}
if (st.getInt() ) //Stored smthng
{
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS);
debugSerial<<F("Restored: ")<<st.param.h<<F(",")<<st.param.s<<F(",")<<st.param.v<<endl;
}
else
}
else // Not restored
{
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
st.setDefault();
//st.param.hsv_flag=1; ///tyta
// Store
//item->setVal(st.getInt());
st.saveItem(item);
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
}
PixelCtrl(st,from,to);
debugSerial<<st.param.aslong<<F(": No stored values - default\n");
}
st.saveItem(item);
PixelCtrl(st);
item->SendStatus(SEND_COMMAND | SEND_PARAMETERS );
return 1;
case CMD_OFF:
if (subItem) // LED range, not whole strip
PixelCtrl(st.Cmd(CMD_OFF));
else
{
st.Percents(0);
PixelCtrl(st,from,to);
PixelCtrl(st);
item->SendStatus(SEND_COMMAND);
// if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd");
}
return 1;
} //switch cmd
break;
} //switch cmd
} //switch suffix
debugSerial<<F("Unknown cmd")<<endl;
return 0;
}
#endif

View File

@@ -1,34 +1,24 @@
#pragma once
#include "options.h"
//#ifndef DMX_DISABLE
#ifdef XXXX
#ifndef DMX_DISABLE
#include <abstractout.h>
#include <item.h>
#ifdef ADAFRUIT_LED
#include <Adafruit_NeoPixel.h>
#else
#include "FastLED.h"
#endif
class out_dmx : public abstractOut {
public:
out_dmx(Item * _item):abstractOut(_item){getConfig();};
out_dmx(Item * _item):abstractOut(_item){};
int Setup() override;
int Poll(short cause) override;
int Stop() override;
int Status() override;
int isActive() override;
int getChanType() override;
int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override;
int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1);
int numLeds;
int8_t pin;
int ledsType;
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
int PixelCtrl(itemCmd cmd);
protected:
void getConfig();
};
#endif

View File

@@ -338,11 +338,13 @@ int out_Modbus::getChanType()
int out_Modbus::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
int out_Modbus::Ctrl(itemCmd cmd, char* subItem)
{
int chActive = item->isActive();
bool toExecute = (chActive>0);
itemCmd st(ST_UINT32);
int suffixCode = cmd.getSuffix();
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
switch(suffixCode)

View File

@@ -31,7 +31,7 @@ public:
int Status() override;
int isActive() override;
int getChanType() override;
int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
protected:

View File

@@ -211,10 +211,11 @@ int out_Motor::getChanType()
int out_Motor::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
int out_Motor::Ctrl(itemCmd cmd, char* subItem)
{
int chActive = item->isActive();
bool toExecute = (chActive>0);
int suffixCode = cmd.getSuffix();
itemCmd st(ST_PERCENTS);
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it

View File

@@ -26,7 +26,7 @@ public:
int isActive() override;
int getChanType() override;
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
int8_t pinUp;
int8_t pinDown;

View File

@@ -89,7 +89,7 @@ return driverStatus;
int out_SPILed::isActive()
{
itemStore st;
itemArgStore st;
st.aslong = item->getVal(); //Restore old params
debugSerial<< F(" val:")<<st.v<<endl;
return st.v;
@@ -102,6 +102,7 @@ return 0;
int out_SPILed::getChanType()
{
if ((ledsType>>4) == (ledsType>>6))
return CH_RGB;
else
@@ -167,10 +168,11 @@ CRGB pixel;
return 1;
}
int out_SPILed::Ctrl(itemCmd cmd, int suffixCode, char* subItem)
int out_SPILed::Ctrl(itemCmd cmd, char* subItem)
{
int chActive = item->isActive();
bool toExecute = (chActive>0);
int suffixCode = cmd.getSuffix();
itemCmd st(ST_HSV);
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it

View File

@@ -22,7 +22,7 @@ public:
int isActive() override;
int getChanType() override;
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, char* subItem=NULL) override;
int PixelCtrl(itemCmd cmd, int from =0 , int to = 1024, bool show = 1);
int numLeds;
int8_t pin;