| LightHub v4.0.0 Smarthome controller firmware

itemCmd.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 "Arduino.h"
22 #include "aJSON.h"
23
24 typedef char cmdstr[9];
25
26 const cmdstr commands_P[] PROGMEM =
27 {
28 "","ON","OFF","REST","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
29 "HEAT","COOL","AUTO","FAN_ONLY","DRY","STOP","HIGH","MEDIUM","LOW",
30 "TRUE","FALSE","ENABLED","DISABLED","RGB","HSV"
31 };
32 #define commandsNum sizeof(commands_P)/sizeof(cmdstr)
33
35 #define CMD_ON 1
36 #define CMD_OFF 2
37 #define CMD_RESTORE 3
38 #define CMD_TOGGLE 4
39 #define CMD_HALT 5
40 #define CMD_XON 6
41 #define CMD_XOFF 7
42 #define CMD_UP 8
43 #define CMD_DN 9
44 #define CMD_HEAT 0xa
45 #define CMD_COOL 0xb
46 #define CMD_AUTO 0xc
47 #define CMD_FAN 0xd
48 #define CMD_DRY 0xe
49 #define CMD_STOP 0xf
50 #define CMD_HIGH 0x10
51 #define CMD_MED 0x11
52 #define CMD_LOW 0x12
53 #define CMD_ENABLED 0x13
54 #define CMD_DISABLED 0x14
55 #define CMD_TRUE 0x15
56 #define CMD_FALSE 0x16
57 #define CMD_RGB 0x17
58 #define CMD_HSV 0x18
59
60 #define CMD_MASK 0xff
61 #define FLAG_MASK 0xff00
62
63 #define CMD_VOID 0
64 #define CMD_UNKNOWN -1
65 #define CMD_JSON -2
66
67 #define SEND_IMMEDIATE 0x1
68 #define SEND_COMMAND 0x100
69 #define SEND_PARAMETERS 0x200
70 #define SEND_RETRY 0x400
71 #define SEND_DEFFERED 0x800
72 #define SEND_DELAYED 0x1000
73 #define ACTION_NEEDED 0x2000
74 #define ACTION_IN_PROCESS 0x4000
75
76
77
78 int txt2cmd (char * payload);
79
80
82 #define ST_VOID 0
83 #define ST_PERCENTS255 1
84
85 #define ST_HSV255 2
86 #define ST_HS 3
87
88 #define ST_RGB 4
89 #define ST_RGBW 5
90
91 #define ST_TENS 6
92 #define ST_FLOAT 7
93 #define ST_FLOAT_CELSIUS 8
94 #define ST_FLOAT_FARENHEIT 9
95
96 #define ST_INT32 10
97 #define ST_UINT32 11
98 #define ST_STRING 12
99 //#define ST_TIMESTAMP 13
100
101 #define MAP_SCALE 1
102 #define MAP_VAL_CMD 2
103
104 #pragma pack(push, 1)
105
106 typedef union
107 {
108 long int aslong;
109 int32_t asInt32;
110 uint32_t asUint32;
111 struct
112 {
113 uint8_t cmdCode;
114 uint8_t suffixCode:4;
115 uint8_t itemArgType:4;
116
117 uint8_t cmdEffect; //Reserve
118 uint8_t cmdParam; //Reserve
119 };
120 } itemCmdStore;
121
122 typedef union
123 {
124 long int aslong;
125 int32_t asInt32;
126 uint32_t asUint32;
127 char* asString;
128 float asfloat;
129
130 struct
131 { uint8_t v;
132 uint8_t s;
133 uint16_t h:9;
134 uint16_t colorTemp:7;
135 };
136 struct
137 { int8_t signed_v;
138 int8_t signed_s;
139 int16_t signed_h:9;
140 int16_t signed_colorTemp:7;
141 };
142 struct //Should be NeoPixel packed Color compatible
143 {
144 uint8_t b;
145 uint8_t g;
146 uint8_t r;
147 uint8_t w;
148 };
149 } itemArgStore;
150
151 class Item;
152 class itemCmd
153 {
154 public:
155 itemCmdStore cmd;
156 itemArgStore param;
157
158 itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID);
159 itemCmd(float val);
160 itemCmd(Item *item);
161
162 itemCmd assignFrom(itemCmd from, short chanType=-1);
163
164 bool loadItem(Item * item, uint16_t optionsFlag=SEND_PARAMETERS);
165 bool loadItemDef(Item * item, uint16_t optionsFlag=SEND_PARAMETERS );
166 bool saveItem(Item * item, uint16_t optionsFlag=SEND_PARAMETERS);
167
168 itemCmd Int(int32_t i);
169 itemCmd Int(uint32_t i);
170 itemCmd Float(float f);
171 itemCmd Tens(int32_t i);
172 itemCmd Cmd(uint8_t i);
173 itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
174 itemCmd HSV255(uint16_t h, uint8_t s, uint8_t v);
175 itemCmd HS(uint16_t h, uint8_t s);
176 itemCmd RGB(uint8_t r, uint8_t g, uint8_t b);
177 itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
178 itemCmd Str(char * str);
179 bool setH(uint16_t);
180 bool setS(uint8_t);
181 bool setColorTemp(int);
182 int getColorTemp();
183 uint16_t getH();
184 uint16_t getS();
185 itemCmd setArgType(uint8_t);
186 itemCmd convertTo(uint8_t);
187 uint8_t getStoragetypeByChanType(short chanType);
188
189 itemCmd Percents(int i);
190 itemCmd Percents255(int i);
191
192 uint8_t getSuffix();
193 itemCmd setSuffix(uint8_t suffix);
194
195 bool incrementPercents(int16_t);
196 bool incrementH(int16_t);
197 bool incrementS(int16_t);
198
199 long int getInt();
200 float getFloat();
201 char * getString();
202 long int getSingleInt();
203 short getPercents(bool inverse=false);
204 short getPercents255(bool inverse=false);
205 bool setPercents(int percents);
206 uint8_t getCmd();
207 uint8_t getArgType();
208 uint8_t getCmdParam();
209 char * toString(char * Buffer, int bufLen, int sendFlags = SEND_COMMAND | SEND_PARAMETERS, bool scale100 = false);
210
211 bool isCommand();
212 bool isValue();
213 bool isColor();
214
215 itemCmd setDefault();
216 itemCmd setChanType(short chanType);
217 void debugOut();
218
219 int doMapping(aJsonObject *mappingData);
220 int doReverseMapping (aJsonObject *mappingData);
221 int doMappingCmd(aJsonObject *mappingData);
222 int doReverseMappingCmd (aJsonObject *mappingData);
223 bool scale100();
224
225 };
226
227 #pragma pack(pop)
itemArgStore::asfloat
float asfloat
Definition: itemCmd.h:128
itemCmd::incrementPercents
bool incrementPercents(int16_t)
Definition: itemCmd.cpp:238
itemArgStore::s
uint8_t s
Definition: itemCmd.h:132
itemCmd::Percents255
itemCmd Percents255(int i)
Definition: itemCmd.cpp:835
itemArgStore
Definition: itemCmd.h:123
itemCmd
Definition: itemCmd.h:153
itemCmdStore::suffixCode
uint8_t suffixCode
Definition: itemCmd.h:114
itemCmdStore::cmdEffect
uint8_t cmdEffect
Definition: itemCmd.h:117
itemCmdStore::aslong
long int aslong
Definition: itemCmd.h:108
ST_VOID
#define ST_VOID
Definition of all possible types of argument, contained in class.
Definition: itemCmd.h:82
itemCmd::RGBW
itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Definition: itemCmd.cpp:922
itemCmd::itemCmd
itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID)
Constructor with definition of type and command.
Definition: itemCmd.cpp:46
itemCmd::param
itemArgStore param
Definition: itemCmd.h:156
itemArgStore::asString
char * asString
Definition: itemCmd.h:127
itemCmd::Str
itemCmd Str(char *str)
Definition: itemCmd.cpp:933
itemCmd::Cmd
itemCmd Cmd(uint8_t i)
Definition: itemCmd.cpp:941
itemCmd::doReverseMappingCmd
int doReverseMappingCmd(aJsonObject *mappingData)
Definition: itemCmd.cpp:1063
itemCmd::HSV255
itemCmd HSV255(uint16_t h, uint8_t s, uint8_t v)
Definition: itemCmd.cpp:891
itemCmd::getFloat
float getFloat()
Definition: itemCmd.cpp:672
CMD_VOID
#define CMD_VOID
Definition: itemCmd.h:63
itemCmdStore::itemArgType
uint8_t itemArgType
Definition: itemCmd.h:115
itemCmd::Float
itemCmd Float(float f)
Definition: itemCmd.cpp:867
itemArgStore::aslong
long int aslong
Definition: itemCmd.h:124
itemCmd::setDefault
itemCmd setDefault()
Definition: itemCmd.cpp:122
itemCmd::doMappingCmd
int doMappingCmd(aJsonObject *mappingData)
Definition: itemCmd.cpp:1058
itemArgStore::signed_colorTemp
int16_t signed_colorTemp
Definition: itemCmd.h:140
itemCmd::setS
bool setS(uint8_t)
Definition: itemCmd.cpp:161
itemArgStore::signed_h
int16_t signed_h
Definition: itemCmd.h:139
itemCmd::getS
uint16_t getS()
Definition: itemCmd.cpp:233
itemArgStore::h
uint16_t h
Definition: itemCmd.h:133
itemCmd::toString
char * toString(char *Buffer, int bufLen, int sendFlags=SEND_COMMAND|SEND_PARAMETERS, bool scale100=false)
Definition: itemCmd.cpp:1069
itemCmd::setChanType
itemCmd setChanType(short chanType)
Definition: itemCmd.cpp:83
itemCmdStore::asUint32
uint32_t asUint32
Definition: itemCmd.h:110
itemArgStore::asUint32
uint32_t asUint32
Definition: itemCmd.h:126
itemCmd::Percents
itemCmd Percents(int i)
Definition: itemCmd.cpp:818
b
#define b
Definition: item.cpp:1735
itemCmd::isValue
bool isValue()
Definition: itemCmd.cpp:619
itemCmd::isColor
bool isColor()
Definition: itemCmd.cpp:624
itemCmd::setH
bool setH(uint16_t)
Definition: itemCmd.cpp:141
itemCmd::getCmdParam
uint8_t getCmdParam()
Definition: itemCmd.cpp:812
itemCmd::convertTo
itemCmd convertTo(uint8_t)
Definition: itemCmd.cpp:802
itemCmd::debugOut
void debugOut()
Definition: itemCmd.cpp:1148
itemArgStore::signed_s
int8_t signed_s
Definition: itemCmd.h:138
itemCmd::setArgType
itemCmd setArgType(uint8_t)
Definition: itemCmd.cpp:795
itemCmd::loadItemDef
bool loadItemDef(Item *item, uint16_t optionsFlag=SEND_PARAMETERS)
Definition: itemCmd.cpp:999
itemCmd::setSuffix
itemCmd setSuffix(uint8_t suffix)
Definition: itemCmd.cpp:953
itemCmd::getPercents255
short getPercents255(bool inverse=false)
Definition: itemCmd.cpp:760
itemCmd::getString
char * getString()
Definition: itemCmd.cpp:660
cmdstr
char cmdstr[9]
Definition: itemCmd.h:24
itemCmd::doMapping
int doMapping(aJsonObject *mappingData)
Definition: itemCmd.cpp:1047
itemArgStore::signed_v
int8_t signed_v
Definition: itemCmd.h:137
itemArgStore::w
uint8_t w
Definition: itemCmd.h:147
itemCmd::cmd
itemCmdStore cmd
Definition: itemCmd.h:155
itemCmd::setPercents
bool setPercents(int percents)
Definition: itemCmd.cpp:737
itemArgStore::asInt32
int32_t asInt32
Definition: itemCmd.h:125
itemCmd::getCmd
uint8_t getCmd()
Definition: itemCmd.cpp:785
itemArgStore::r
uint8_t r
Definition: itemCmd.h:146
itemCmd::getStoragetypeByChanType
uint8_t getStoragetypeByChanType(short chanType)
Definition: itemCmd.cpp:91
itemCmd::getInt
long int getInt()
Definition: itemCmd.cpp:632
itemCmd::isCommand
bool isCommand()
Definition: itemCmd.cpp:614
itemCmd::saveItem
bool saveItem(Item *item, uint16_t optionsFlag=SEND_PARAMETERS)
Definition: itemCmd.cpp:1016
itemArgStore::colorTemp
uint16_t colorTemp
Definition: itemCmd.h:134
itemArgStore::v
uint8_t v
Definition: itemCmd.h:131
itemCmd::scale100
bool scale100()
Definition: itemCmd.cpp:1155
itemArgStore::g
uint8_t g
Definition: itemCmd.h:145
itemCmd::setColorTemp
bool setColorTemp(int)
Definition: itemCmd.cpp:183
SEND_COMMAND
#define SEND_COMMAND
Definition: itemCmd.h:68
itemCmd::getColorTemp
int getColorTemp()
Definition: itemCmd.cpp:212
txt2cmd
int txt2cmd(char *payload)
Definition: itemCmd.cpp:18
SEND_PARAMETERS
#define SEND_PARAMETERS
Definition: itemCmd.h:69
Item
Definition: item.h:104
itemCmd::assignFrom
itemCmd assignFrom(itemCmd from, short chanType=-1)
Definition: itemCmd.cpp:319
itemCmd::RGB
itemCmd RGB(uint8_t r, uint8_t g, uint8_t b)
Definition: itemCmd.cpp:912
itemCmd::getH
uint16_t getH()
Definition: itemCmd.cpp:228
PROGMEM
const cmdstr commands_P[] PROGMEM
Definition: itemCmd.h:26
itemCmdStore::cmdCode
uint8_t cmdCode
Definition: itemCmd.h:113
itemCmdStore::cmdParam
uint8_t cmdParam
Definition: itemCmd.h:118
itemCmd::Int
itemCmd Int(int32_t i)
Definition: itemCmd.cpp:853
itemCmd::Tens
itemCmd Tens(int32_t i)
Definition: itemCmd.cpp:874
itemCmd::getSuffix
uint8_t getSuffix()
Definition: itemCmd.cpp:948
itemCmd::getSingleInt
long int getSingleInt()
Definition: itemCmd.cpp:702
itemCmd::getArgType
uint8_t getArgType()
Definition: itemCmd.cpp:790
itemCmd::getPercents
short getPercents(bool inverse=false)
Definition: itemCmd.cpp:708
itemCmd::incrementS
bool incrementS(int16_t)
Definition: itemCmd.cpp:301
itemCmd::loadItem
bool loadItem(Item *item, uint16_t optionsFlag=SEND_PARAMETERS)
Definition: itemCmd.cpp:959
itemCmdStore
Definition: itemCmd.h:107
itemCmdStore::asInt32
int32_t asInt32
Definition: itemCmd.h:109
itemCmd::HS
itemCmd HS(uint16_t h, uint8_t s)
Definition: itemCmd.cpp:902
itemCmd::incrementH
bool incrementH(int16_t)
Definition: itemCmd.cpp:284
itemCmd::HSV
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v)
Definition: itemCmd.cpp:881
itemCmd::doReverseMapping
int doReverseMapping(aJsonObject *mappingData)
Definition: itemCmd.cpp:1052
itemArgStore::b
uint8_t b
Definition: itemCmd.h:144