# LightHub: itemCmd.h Source File

itemCmd.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 "Arduino.h"
typedef char cmdstr[9];
const cmdstr commands_P[] PROGMEM =
{
"","ON","OFF","REST","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
"HEAT","COOL","AUTO","FAN_ONLY","DRY","STOP","HIGH","MEDIUM","LOW",
"TRUE","FALSE","ENABLED","DISABLED","RGB","HSV"
};
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
#define CMD_ON 1
#define CMD_OFF 2
#define CMD_RESTORE 3
#define CMD_TOGGLE 4
#define CMD_HALT 5
#define CMD_XON 6
#define CMD_XOFF 7
#define CMD_UP 8
#define CMD_DN 9
#define CMD_HEAT 0xa
#define CMD_COOL 0xb
#define CMD_AUTO 0xc
#define CMD_FAN 0xd
#define CMD_DRY 0xe
#define CMD_STOP 0xf
#define CMD_HIGH 0x10
#define CMD_MED 0x11
#define CMD_LOW 0x12
#define CMD_ENABLED 0x13
#define CMD_DISABLED 0x14
#define CMD_TRUE 0x15
#define CMD_FALSE 0x16
#define CMD_RGB 0x17
#define CMD_HSV 0x18
#define CMD_MASK 0xff
#define FLAG_MASK 0xff00
#define CMD_VOID 0
#define CMD_UNKNOWN -1
#define CMD_JSON -2
#define SEND_COMMAND 0x100
#define SEND_PARAMETERS 0x200
#define SEND_RETRY 0x400
#define SEND_DEFFERED 0x800
#define ACTION_NEEDED 0x1000
#define ACTION_IN_PROCESS 0x2000
int txt2cmd (char * payload);
/*
enum itemStoreType {
ST_VOID = 0,
ST_PERCENTS = 1,
ST_TENS = 2,
ST_HSV = 3,
ST_FLOAT_CELSIUS= 4,
ST_FLOAT_FARENHEIT= 5,
ST_RGB = 6,
ST_RGBW = 7,
ST_PERCENTS255 = 8,
ST_HSV255 = 9,
ST_INT32 = 10,
ST_UINT32 = 11,
ST_STRING = 12,
ST_FLOAT = 13//,
//ST_COMMAND = 15
};
*/
#define ST_VOID 0
#define ST_PERCENTS 1
#define ST_TENS 2
#define ST_HSV 3
#define ST_HS 4
#define ST_FLOAT_CELSIUS 5
#define ST_FLOAT_FARENHEIT 6
#define ST_RGB 7
#define ST_RGBW 8
#define ST_PERCENTS255 9
#define ST_HSV255 10
#define ST_INT32 11
#define ST_UINT32 12
#define ST_STRING 13
#define ST_FLOAT 14
#pragma pack(push, 1)
typedef union
{
long int aslong;
int32_t asInt32;
uint32_t asUint32;
struct
{
uint8_t cmdCode;
union {
uint8_t cmdFlag;
/*
struct
{ uint8_t suffixCode:4;
uint8_t itemArgType:4;
};
*/
};
struct
{ uint8_t suffixCode:4;
uint8_t itemArgType:4;
};
// uint8_t cmdEffect;
uint8_t cmdParam;
};
} itemCmdStore;
typedef union
{
long int aslong;
int32_t asInt32;
uint32_t asUint32;
char* asString;
float asfloat;
struct
{ uint8_t v;
uint8_t s;
uint16_t h:9;
uint16_t colorTemp:7;
};
struct
{ int8_t signed_v;
int8_t signed_s;
int16_t signed_h:9;
int16_t signed_colorTemp:7;
};
struct //Should be NeoPixel packed Color compatible
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t w;
};
} itemArgStore;
class Item;
class itemCmd
{
public:
itemCmdStore cmd;
itemArgStore param;
itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID);
itemCmd(float val);
itemCmd assignFrom(itemCmd from);
bool loadItem(Item * item, bool includeCommand=false );
bool saveItem(Item * item, bool includeCommand=false);
itemCmd Int(int32_t i);
itemCmd Int(uint32_t i);
itemCmd Cmd(uint8_t i);
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
itemCmd HSV255(uint16_t h, uint8_t s, uint8_t v);
itemCmd HS(uint16_t h, uint8_t s);
itemCmd RGB(uint8_t r, uint8_t g, uint8_t b);
itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
bool setH(uint16_t);
bool setS(uint8_t);
bool setColorTemp(uint8_t);
int8_t getColorTemp();
uint16_t getH();
uint16_t getS();
itemCmd setArgType(uint8_t);
itemCmd Percents(int i);
itemCmd Percents255(int i);
uint8_t getSuffix();
itemCmd setSuffix(uint8_t suffix);
bool incrementPercents(int16_t);
bool incrementH(int16_t);
bool incrementS(int16_t);
long int getInt();
short getPercents(bool inverse=false);
short getPercents255(bool inverse=false);
uint8_t getCmd();
uint8_t getArgType();
uint8_t getCmdParam();
char * toString(char * Buffer, int bufLen, int sendFlags = SEND_COMMAND | SEND_PARAMETERS );
bool isCommand();
bool isValue();
bool isColor();
itemCmd setDefault();
itemCmd setChanType(short chanType);
void debugOut();
};
#pragma pack(pop)
itemArgStore::asfloat
float asfloat
Definition: itemCmd.h:148
itemCmd::assignFrom
itemCmd assignFrom(itemCmd from)
Definition: itemCmd.cpp:272
itemCmd::incrementPercents
bool incrementPercents(int16_t)
Definition: itemCmd.cpp:207
itemArgStore::s
uint8_t s
Definition: itemCmd.h:152
itemCmd::Percents255
itemCmd Percents255(int i)
Definition: itemCmd.cpp:608
itemCmd::toString
char * toString(char *Buffer, int bufLen, int sendFlags=SEND_COMMAND|SEND_PARAMETERS)
Definition: itemCmd.cpp:753
itemArgStore
Definition: itemCmd.h:143
itemCmd
Definition: itemCmd.h:173
itemCmdStore::suffixCode
uint8_t suffixCode
Definition: itemCmd.h:134
itemCmdStore::aslong
long int aslong
Definition: itemCmd.h:118
ST_VOID
#define ST_VOID
Definition of all possible types of argument, contained in class.
Definition: itemCmd.h:97
itemCmd::RGBW
itemCmd RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Definition: itemCmd.cpp:681
itemCmd::itemCmd
itemCmd(uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID)
Constructor with definition of type and command.
Definition: itemCmd.cpp:42
itemCmd::param
itemArgStore param
Definition: itemCmd.h:176
itemArgStore::asString
char * asString
Definition: itemCmd.h:147
itemCmd::Cmd
itemCmd Cmd(uint8_t i)
Definition: itemCmd.cpp:700
itemCmd::HSV255
itemCmd HSV255(uint16_t h, uint8_t s, uint8_t v)
Definition: itemCmd.cpp:650
CMD_VOID
#define CMD_VOID
Definition: itemCmd.h:62
itemCmdStore::itemArgType
uint8_t itemArgType
Definition: itemCmd.h:135
itemCmd::getColorTemp
int8_t getColorTemp()
Definition: itemCmd.cpp:191
itemArgStore::aslong
long int aslong
Definition: itemCmd.h:144
itemCmd::setDefault
itemCmd setDefault()
Definition: itemCmd.cpp:92
itemArgStore::signed_colorTemp
int16_t signed_colorTemp
Definition: itemCmd.h:160
itemCmd::setS
bool setS(uint8_t)
Definition: itemCmd.cpp:136
itemArgStore::signed_h
int16_t signed_h
Definition: itemCmd.h:159
itemCmd::getS
uint16_t getS()
Definition: itemCmd.cpp:202
itemArgStore::h
uint16_t h
Definition: itemCmd.h:153
itemCmd::setChanType
itemCmd setChanType(short chanType)
Definition: itemCmd.cpp:66
itemCmdStore::asUint32
uint32_t asUint32
Definition: itemCmd.h:120
itemArgStore::asUint32
uint32_t asUint32
Definition: itemCmd.h:146
itemCmd::Percents
itemCmd Percents(int i)
Definition: itemCmd.cpp:585
b
#define b
Definition: item.cpp:1131
itemCmd::isValue
bool isValue()
Definition: itemCmd.cpp:488
itemCmd::saveItem
bool saveItem(Item *item, bool includeCommand=false)
Definition: itemCmd.cpp:737
itemCmd::isColor
bool isColor()
Definition: itemCmd.cpp:493
itemCmd::setH
bool setH(uint16_t)
Definition: itemCmd.cpp:115
itemCmd::loadItem
bool loadItem(Item *item, bool includeCommand=false)
Definition: itemCmd.cpp:719
itemCmd::getCmdParam
uint8_t getCmdParam()
Definition: itemCmd.cpp:579
itemCmd::debugOut
void debugOut()
Definition: itemCmd.cpp:820
itemArgStore::signed_s
int8_t signed_s
Definition: itemCmd.h:158
itemCmd::setArgType
itemCmd setArgType(uint8_t)
Definition: itemCmd.cpp:573
itemCmd::setSuffix
itemCmd setSuffix(uint8_t suffix)
Definition: itemCmd.cpp:713
itemCmd::getPercents255
short getPercents255(bool inverse=false)
Definition: itemCmd.cpp:545
cmdstr
char cmdstr[9]
Definition: itemCmd.h:23
itemArgStore::signed_v
int8_t signed_v
Definition: itemCmd.h:157
itemArgStore::w
uint8_t w
Definition: itemCmd.h:167
itemCmd::cmd
itemCmdStore cmd
Definition: itemCmd.h:175
itemArgStore::asInt32
int32_t asInt32
Definition: itemCmd.h:145
itemCmd::getCmd
uint8_t getCmd()
Definition: itemCmd.cpp:563
itemArgStore::r
uint8_t r
Definition: itemCmd.h:166
itemCmd::getInt
long int getInt()
Definition: itemCmd.cpp:499
itemCmd::isCommand
bool isCommand()
Definition: itemCmd.cpp:483
itemArgStore::colorTemp
uint16_t colorTemp
Definition: itemCmd.h:154
itemArgStore::v
uint8_t v
Definition: itemCmd.h:151
itemArgStore::g
uint8_t g
Definition: itemCmd.h:165
SEND_COMMAND
#define SEND_COMMAND
Definition: itemCmd.h:66
txt2cmd
int txt2cmd(char *payload)
Definition: itemCmd.cpp:14
SEND_PARAMETERS
#define SEND_PARAMETERS
Definition: itemCmd.h:67
Item
Definition: item.h:93
itemCmd::RGB
itemCmd RGB(uint8_t r, uint8_t g, uint8_t b)
Definition: itemCmd.cpp:671
itemCmd::getH
uint16_t getH()
Definition: itemCmd.cpp:197
PROGMEM
const cmdstr commands_P[] PROGMEM
Definition: itemCmd.h:25
itemCmdStore::cmdCode
uint8_t cmdCode
Definition: itemCmd.h:123
itemCmdStore::cmdParam
uint8_t cmdParam
Definition: itemCmd.h:138
itemCmd::Int
itemCmd Int(int32_t i)
Definition: itemCmd.cpp:631
itemCmd::getSuffix
uint8_t getSuffix()
Definition: itemCmd.cpp:708
itemCmd::getArgType
uint8_t getArgType()
Definition: itemCmd.cpp:568
itemCmd::getPercents
short getPercents(bool inverse=false)
Definition: itemCmd.cpp:527
itemCmd::incrementS
bool incrementS(int16_t)
Definition: itemCmd.cpp:246
itemCmdStore
Definition: itemCmd.h:117
itemCmdStore::cmdFlag
uint8_t cmdFlag
Definition: itemCmd.h:125
itemCmd::setColorTemp
bool setColorTemp(uint8_t)
Definition: itemCmd.cpp:165
itemCmdStore::asInt32
int32_t asInt32
Definition: itemCmd.h:119
itemCmd::HS
itemCmd HS(uint16_t h, uint8_t s)
Definition: itemCmd.cpp:661
itemCmd::incrementH
bool incrementH(int16_t)
Definition: itemCmd.cpp:229
itemCmd::HSV
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v)
Definition: itemCmd.cpp:640
itemArgStore::b
uint8_t b
Definition: itemCmd.h:164