LightHub  v4.0.0
Smarthome controller firmware
item.h
Go to the documentation of this file.
1 /* Copyright © 2017-2020 Andrey Klimov. All rights reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 
15 Homepage: http://lazyhome.ru
16 GIT: https://github.com/anklimov/lighthub
17 e-mail anklimov@gmail.com
18 
19 */
20 #pragma once
21 #include "options.h"
22 #include "abstractout.h"
23 #include "itemCmd.h"
24 
25 #define S_NOTFOUND 0
26 //#define S_SETnCMD 0
27 #define S_CMD 1
28 #define S_SET 2
29 //#define S_ESET 4
30 #define S_HSV 5
31 #define S_RGB 6
32 #define S_FAN 7
33 #define S_MODE 8
34 #define S_HUE 9
35 #define S_SAT 10
36 #define S_TEMP 11
37 #define S_VAL 12
38 #define S_DELAYED 13
39 #define S_RAW 14
40 #define S_ADDITIONAL 14
41 
42 #define CH_DIMMER 0 //DMX 1-4 ch
43 #define CH_RGBW 1 //DMX 4 ch
44 #define CH_RGB 2 //DMX 3 ch
45 #define CH_PWM 3 //PWM output directly to PIN 1-4 CH
46 #define CH_MODBUS 4 //Modbus AC Dimmer
47 #define CH_THERMO 5 //Simple ON/OFF thermostat
48 #define CH_RELAY 6 //ON_OFF relay output
49 #define CH_GROUP 7 //Group pseudochannel
50 #define CH_VCTEMP 8 //Vacom PID regulator
51 #define CH_VC 9 //Vacom modbus motor regulator
52 #define CH_AC 10 //AC Haier
53 #define CH_SPILED 11
54 #define CH_MOTOR 12
55 #define CH_PID 13
56 #define CH_MBUS 14
57 #define CH_UARTBRIDGE 15
58 #define CH_RELAYX 16
59 #define CH_RGBWW 17
60 #define CH_MULTIVENT 18
61 #define CH_ELEVATOR 19
62 
63 //#define CHANNEL_TYPES 13
64 
65 //static uint32_t pollInterval[CHANNEL_TYPES] = {0,0,0,0,MODB};
66 //static uint32_t nextPollTime[CHANNEL_TYPES] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
67 
68 #define CH_WHITE 127//
69 
70 
71 
72 
73 #define POLLING_SLOW 1
74 #define POLLING_FAST 2
75 #define POLLING_INT 3
76 
77 
78 #define I_TYPE 0 //Type of item
79 #define I_ARG 1 //Chanel-type depended argument or array of arguments (pin, address etc)
80 #define I_VAL 2 //Latest preset (int or array of presets)
81 #define I_CMD 3 //Latest CMD received
82 #define I_EXT 4 //Chanell-depended extension - array
83 #define I_TIMESTAMP 5
84 
85 #define MODBUS_CMD_ARG_ADDR 0
86 #define MODBUS_CMD_ARG_REG 1
87 #define MODBUS_CMD_ARG_MASK 2
88 #define MODBUS_CMD_ARG_MAX_SCALE 3
89 #define MODBUS_CMD_ARG_REG_TYPE 4
90 
91 #define MODBUS_COIL_REG_TYPE 0
92 #define MODBUS_DISCRETE_REG_TYPE 1
93 #define MODBUS_HOLDING_REG_TYPE 2
94 #define MODBUS_INPUT_REG_TYPE 3
95 
96 #include "aJSON.h"
97 
98 extern aJsonObject *items;
99 extern short thermoSetCurTemp(char *name, float t);
100 
101 int txt2cmd (char * payload);
102 bool digGroup (aJsonObject *itemArr, itemCmd *cmd = NULL, char* subItem = NULL);
103 class Item
104 {
105  public:
106  aJsonObject *itemArr, *itemArg,*itemVal,*itemExt;
107  uint8_t itemType;
109 
110  Item(char * name);
111  Item(aJsonObject * obj);
112  ~Item();
113 
114  boolean isValid ();
115  boolean Setup();
116  void Stop();
117  //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL);
118  int Ctrl(itemCmd cmd, char* subItem=NULL, bool allowRecursion = true);
119  int Ctrl(char * payload, char * subItem=NULL);
120 
121  int getArg(short n=0);
122  float getFloatArg(short n=0);
123  short getArgCount();
124  //int getVal(short n); //From VAL array. Negative if no array
125  long int getVal(); //From int val OR array
126  uint8_t getSubtype();
127  uint8_t getCmd();
128  long int getExt(); //From int val OR array
129  void setExt(long int par);
132  void setCmd(uint8_t cmdValue);
133  short getFlag (short flag=FLAG_MASK);
134  void setFlag (short flag);
135  void clearFlag (short flag);
136  void setVal(long int par);
137  void setFloatVal(float par);
138  void setSubtype(uint8_t par);
139  int Poll(int cause);
140  int SendStatus(int sendFlags);
141  int SendStatusImmediate(itemCmd st, int sendFlags, char * subItem=NULL);
142  int isActive();
143  int getChanType();
144  inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));};
145  inline int Off(){return Ctrl(itemCmd(ST_VOID,CMD_OFF));};
146  inline int Toggle(){return Ctrl(itemCmd(ST_VOID,CMD_TOGGLE));};
147 
148  protected:
149 
150  int VacomSetFan (itemCmd st);
151  int VacomSetHeat(itemCmd st);
152  int modbusDimmerSet(itemCmd st);
153 
154  int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value);
155  void mb_fail(int result=0);
156  void Parse();
157  int checkModbusDimmer();
158  int checkModbusDimmer(int data);
159 
160  int checkModbusRetry();
161  //boolean checkVCRetry();
162  //boolean checkHeatRetry();
163  void sendDelayedStatus();
164  bool resumeModbus();
165 
166 
167  int checkFM();
168  char defaultSubItem[10];
170 
171 };
172 
173 typedef union
174 {
175 struct
176  {
177  int16_t tempX100;
178  uint16_t timestamp16;
179  };
180 int32_t asint;
Item::setCmd
void setCmd(uint8_t cmdValue)
Definition: item.cpp:286
Item::isValid
boolean isValid()
Definition: item.cpp:491
Item::getSubtype
uint8_t getSubtype()
Definition: item.cpp:392
Item::isActive
int isActive()
Definition: item.cpp:1192
Item::Toggle
int Toggle()
Definition: item.h:146
itemCmd.h
itemCmd
Definition: itemCmd.h:153
Item::Ctrl
int Ctrl(itemCmd cmd, char *subItem=NULL, bool allowRecursion=true)
Definition: item.cpp:693
Item::getArg
int getArg(short n=0)
Definition: item.cpp:329
ST_VOID
#define ST_VOID
Definition of all possible types of argument, contained in class.
Definition: itemCmd.h:82
thermostatStore::timestamp16
uint16_t timestamp16
Definition: item.h:178
Item::setPersistent
chPersistent * setPersistent(chPersistent *par)
Definition: item.cpp:471
chPersistent
Definition: abstractout.h:7
Item::~Item
~Item()
Definition: item.cpp:240
Item::setExt
void setExt(long int par)
Definition: item.cpp:448
Item::Parse
void Parse()
Definition: item.cpp:127
Item::getVal
long int getVal()
Definition: item.cpp:381
Item::Off
int Off()
Definition: item.h:145
FLAG_MASK
#define FLAG_MASK
Definition: itemCmd.h:61
options.h
abstractOut
Definition: abstractout.h:8
Item::SendStatus
int SendStatus(int sendFlags)
Definition: item.cpp:1346
items
aJsonObject * items
Definition: main.cpp:92
Item::getChanType
int getChanType()
Definition: item.cpp:1526
Item::clearFlag
void clearFlag(short flag)
Definition: item.cpp:318
thermostatStore
Definition: item.h:174
Item::defaultSubItem
char defaultSubItem[10]
Definition: item.h:168
CMD_OFF
#define CMD_OFF
Definition: itemCmd.h:36
Item::Setup
boolean Setup()
Definition: item.cpp:215
Item::modbusDimmerSet
int modbusDimmerSet(itemCmd st)
Definition: item.cpp:1659
Item::setSubtype
void setSubtype(uint8_t par)
Definition: item.cpp:430
thermostatStore::asint
int32_t asint
Definition: item.h:180
CMD_TOGGLE
#define CMD_TOGGLE
Definition: itemCmd.h:38
Item::defaultSuffixCode
int defaultSuffixCode
Definition: item.h:169
Item::getCmd
uint8_t getCmd()
Definition: item.cpp:278
Item::Stop
void Stop()
Definition: item.cpp:231
Item::checkModbusDimmer
int checkModbusDimmer()
Definition: item.cpp:1954
Item::itemType
uint8_t itemType
Definition: item.h:107
txt2cmd
int txt2cmd(char *payload)
Definition: itemCmd.cpp:18
Item::getPersistent
chPersistent * getPersistent()
Definition: item.cpp:464
CMD_ON
#define CMD_ON
Definition of Commands.
Definition: itemCmd.h:35
thermostatStore::tempX100
int16_t tempX100
Definition: item.h:177
Item::checkModbusRetry
int checkModbusRetry()
Definition: item.cpp:1552
Item::mb_fail
void mb_fail(int result=0)
Definition: item.cpp:1534
Item::itemVal
aJsonObject * itemVal
Definition: item.h:106
Item::checkFM
int checkFM()
Definition: item.cpp:1843
Item::itemExt
aJsonObject * itemExt
Definition: item.h:106
Item::sendDelayedStatus
void sendDelayedStatus()
Definition: item.cpp:1335
thermoSetCurTemp
short thermoSetCurTemp(char *name, float t)
Item::setFloatVal
void setFloatVal(float par)
Definition: item.cpp:422
Item
Definition: item.h:104
Item::itemArg
aJsonObject * itemArg
Definition: item.h:106
Item::getFlag
short getFlag(short flag=FLAG_MASK)
Definition: item.cpp:296
digGroup
bool digGroup(aJsonObject *itemArr, itemCmd *cmd=NULL, char *subItem=NULL)
Definition: item.cpp:653
Item::resumeModbus
bool resumeModbus()
Definition: item.cpp:1591
Item::SendStatusImmediate
int SendStatusImmediate(itemCmd st, int sendFlags, char *subItem=NULL)
Definition: item.cpp:1363
abstractout.h
Item::On
int On()
Definition: item.h:144
Item::VacomSetHeat
int VacomSetHeat(itemCmd st)
move to float todo
Definition: item.cpp:1738
Item::getFloatArg
float getFloatArg(short n=0)
Definition: item.cpp:340
Item::VacomSetFan
int VacomSetFan(itemCmd st)
Definition: item.cpp:1690
data
byte data[37]
Definition: out_ac.cpp:31
Item::setFlag
void setFlag(short flag)
Definition: item.cpp:306
Item::driver
abstractOut * driver
Definition: item.h:108
Item::Poll
int Poll(int cause)
Definition: item.cpp:1262
Item::setVal
void setVal(long int par)
Definition: item.cpp:414
Item::getExt
long int getExt()
Definition: item.cpp:437
Item::Item
Item(char *name)
Definition: item.cpp:248
Item::getArgCount
short getArgCount()
Definition: item.cpp:361
Item::itemArr
aJsonObject * itemArr
Definition: item.h:106