# LightHub: item.h Source File

item.h
Go to the documentation of this file.
/* Copyright © 2017-2020 Andrey Klimov. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Homepage: http://lazyhome.ru
GIT: https://github.com/anklimov/lighthub
e-mail anklimov@gmail.com
*/
#pragma once
#include "options.h"
#include "abstractout.h"
#include "itemCmd.h"
#define S_NOTFOUND 0
//#define S_SETnCMD 0
#define S_CMD 1
#define S_SET 2
#define S_ESET 4
#define S_HSV 5
#define S_RGB 6
#define S_FAN 7
#define S_MODE 8
#define S_HUE 9
#define S_SAT 10
#define S_TEMP 11
#define S_ADDITIONAL 11
#define CH_DIMMER 0 //DMX 1 ch
#define CH_RGBW 1 //DMX 4 ch
#define CH_RGB 2 //DMX 3 ch
#define CH_PWM 3 //PWM output directly to PIN
#define CH_MODBUS 4 //Modbus AC Dimmer
#define CH_THERMO 5 //Simple ON/OFF thermostat
#define CH_RELAY 6 //ON_OFF relay output
#define CH_GROUP 7 //Group pseudochannel
#define CH_VCTEMP 8 //Vacom PID regulator
#define CH_VC 9 //Vacom modbus motor regulator
#define CH_AC 10 //AC Haier
#define CH_SPILED 11
#define CH_MOTOR 12
#define CH_MBUS 14
//#define CHANNEL_TYPES 13
//static uint32_t pollInterval[CHANNEL_TYPES] = {0,0,0,0,MODB};
//static uint32_t nextPollTime[CHANNEL_TYPES] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
#define CH_WHITE 127//
#define POLLING_SLOW 1
#define POLLING_FAST 2
#define POLLING_INT 3
#define I_TYPE 0 //Type of item
#define I_ARG 1 //Chanel-type depended argument or array of arguments (pin, address etc)
#define I_VAL 2 //Latest preset (int or array of presets)
#define I_CMD 3 //Latest CMD received
#define I_EXT 4 //Chanell-depended extension - array
#define MODBUS_CMD_ARG_ADDR 0
#define MODBUS_CMD_ARG_REG 1
#define MODBUS_CMD_ARG_MASK 2
#define MODBUS_CMD_ARG_MAX_SCALE 3
#define MODBUS_CMD_ARG_REG_TYPE 4
#define MODBUS_COIL_REG_TYPE 0
#define MODBUS_DISCRETE_REG_TYPE 1
#define MODBUS_HOLDING_REG_TYPE 2
#define MODBUS_INPUT_REG_TYPE 3
#include "aJSON.h"
extern aJsonObject *items;
extern short thermoSetCurTemp(char *name, float t);
int txt2cmd (char * payload);
class Item
{
public:
aJsonObject *itemArr, *itemArg,*itemVal,*itemExt;
uint8_t itemType;
abstractOut * driver;
Item(char * name);
Item(aJsonObject * obj);
~Item();
boolean isValid ();
boolean Setup();
void Stop();
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL);
int Ctrl(itemCmd cmd, char* subItem=NULL);
int Ctrl(char * payload, char * subItem=NULL);
int getArg(short n=0);
short getArgCount();
//int getVal(short n); //From VAL array. Negative if no array
long int getVal(); //From int val OR array
uint8_t getSubtype();
uint8_t getCmd();
long int getExt(); //From int val OR array
void setExt(long int par);
chPersistent * getPersistent();
chPersistent * setPersistent(chPersistent * par);
void setCmd(uint8_t cmdValue);
short getFlag (short flag=FLAG_MASK);
void setFlag (short flag);
void clearFlag (short flag);
void setVal(long int par);
void setSubtype(uint8_t par);
int Poll(int cause);
int SendStatus(int sendFlags);
int isActive();
int getChanType();
inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));};
inline int Off(){return Ctrl(itemCmd(ST_VOID,CMD_OFF));};
inline int Toggle(){return Ctrl(itemCmd(ST_VOID,CMD_TOGGLE));};
protected:
//short cmd2changeActivity(int lastActivity, short defaultCmd = CMD_SET);
int VacomSetFan (itemCmd st);
int VacomSetHeat(itemCmd st);
int modbusDimmerSet(itemCmd st);
int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
void mb_fail();
void Parse();
int checkModbusDimmer();
int checkModbusDimmer(int data);
boolean checkModbusRetry();
boolean checkVCRetry();
boolean checkHeatRetry();
void sendDelayedStatus();
int checkFM();
char defaultSubItem[10];
int defaultSuffixCode;
};
Item::setCmd
void setCmd(uint8_t cmdValue)
Definition: item.cpp:243
Item::checkModbusRetry
boolean checkModbusRetry()
Definition: item.cpp:1329
Item::isValid
boolean isValid()
Definition: item.cpp:411
Item::getSubtype
uint8_t getSubtype()
Definition: item.cpp:325
Item::isActive
int isActive()
Definition: item.cpp:899
Item::Toggle
int Toggle()
Definition: item.h:132
itemCmd.h
itemCmd
Definition: itemCmd.h:173
Item::getArg
int getArg(short n=0)
Definition: item.cpp:284
ST_VOID
#define ST_VOID
Definition of all possible types of argument, contained in class.
Definition: itemCmd.h:97
Item::setPersistent
chPersistent * setPersistent(chPersistent *par)
Definition: item.cpp:394
chPersistent
Definition: abstractout.h:7
Item::~Item
~Item()
Definition: item.cpp:196
Item::setExt
void setExt(long int par)
Definition: item.cpp:372
Item::Parse
void Parse()
Definition: item.cpp:118
Item::getVal
long int getVal()
Definition: item.cpp:314
Item::Off
int Off()
Definition: item.h:131
FLAG_MASK
#define FLAG_MASK
Definition: itemCmd.h:60
options.h
abstractOut
Definition: abstractout.h:8
Item::SendStatus
int SendStatus(int sendFlags)
Definition: item.cpp:1533
items
aJsonObject * items
Definition: main.cpp:140
Item::getChanType
int getChanType()
Definition: item.cpp:1681
Item::clearFlag
void clearFlag(short flag)
Definition: item.cpp:273
Item::defaultSubItem
char defaultSubItem[10]
Definition: item.h:151
CMD_OFF
#define CMD_OFF
Definition: itemCmd.h:35
Item::Setup
boolean Setup()
Definition: item.cpp:175
Item::modbusDimmerSet
int modbusDimmerSet(itemCmd st)
Definition: item.cpp:1048
Item::setSubtype
void setSubtype(uint8_t par)
Definition: item.cpp:354
CMD_TOGGLE
#define CMD_TOGGLE
Definition: itemCmd.h:37
Item::defaultSuffixCode
int defaultSuffixCode
Definition: item.h:152
Item::getCmd
uint8_t getCmd()
Definition: item.cpp:235
Item::Stop
void Stop()
Definition: item.cpp:187
Item::checkModbusDimmer
int checkModbusDimmer()
Definition: item.cpp:1371
Item::itemType
uint8_t itemType
Definition: item.h:96
Item::Ctrl
int Ctrl(itemCmd cmd, char *subItem=NULL)
Definition: item.cpp:571
txt2cmd
int txt2cmd(char *payload)
Definition: itemCmd.cpp:14
Item::getPersistent
chPersistent * getPersistent()
Definition: item.cpp:387
CMD_ON
#define CMD_ON
Definition of Commands.
Definition: itemCmd.h:34
Item::itemVal
aJsonObject * itemVal
Definition: item.h:95
Item::checkFM
int checkFM()
Definition: item.cpp:1222
Item::itemExt
aJsonObject * itemExt
Definition: item.h:95
Item::sendDelayedStatus
void sendDelayedStatus()
Definition: item.cpp:1522
thermoSetCurTemp
short thermoSetCurTemp(char *name, float t)
Definition: main.cpp:2151
Item
Definition: item.h:93
Item::itemArg
aJsonObject * itemArg
Definition: item.h:95
Item::getFlag
short getFlag(short flag=FLAG_MASK)
Definition: item.cpp:252
abstractout.h
Item::On
int On()
Definition: item.h:130
Item::VacomSetHeat
int VacomSetHeat(itemCmd st)
move to float todo
Definition: item.cpp:1134
Item::checkHeatRetry
boolean checkHeatRetry()
Definition: item.cpp:1357
Item::VacomSetFan
int VacomSetFan(itemCmd st)
Definition: item.cpp:1089
data
byte data[37]
Definition: out_ac.cpp:31
Item::setFlag
void setFlag(short flag)
Definition: item.cpp:262
Item::driver
abstractOut * driver
Definition: item.h:97
Item::Poll
int Poll(int cause)
Definition: item.cpp:1478
Item::setVal
void setVal(long int par)
Definition: item.cpp:347
Item::checkVCRetry
boolean checkVCRetry()
Definition: item.cpp:1343
Item::getExt
long int getExt()
Definition: item.cpp:361
Item::Item
Item(char *name)
Definition: item.cpp:205
Item::mb_fail
void mb_fail()
Definition: item.cpp:1079
Item::getArgCount
short getArgCount()
Definition: item.cpp:294
Item::itemArr
aJsonObject * itemArr
Definition: item.h:95