LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
itemCmd.h File Reference
#include "Arduino.h"
#include "aJSON.h"

Go to the source code of this file.

Classes

union  itemCmdStore
 Packed 32-bit command word of itemCmd. More...
union  itemArgStore
 32-bit parameter storage of itemCmd. More...
class  itemCmd
 Command + value container passed between items, drivers and MQTT. More...

Macros

#define commandsNum   sizeof(commands_P)/sizeof(cmdstr)
#define ch_typeNum   sizeof(ch_type_P)/sizeof(ch_type)
#define CMD_ON   1
 Definition of Commands.
#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_ENABLE   0xa
#define CMD_DISABLE   0xb
#define CMD_UNFREEZE   0xc
#define CMD_FREEZE   0xd
#define CMD_AUTO   0xe
#define CMD_FAN   0xf
#define CMD_HIGH   0x10
#define CMD_MED   0x11
#define CMD_LOW   0x12
#define CMD_HEATCOOL   0x13
#define CMD_HEAT   0x14
#define CMD_COOL   0x15
#define CMD_DRY   0x16
#define CMD_RGB   0x17
#define CMD_HSV   0x18
#define CMD_RESET   0x19
#define CMD_MASK   0xffUL
 Low byte of the packed I_CMD int - command code.
#define FLAG_MASK   0x00ffff00UL
 High two bytes of the packed I_CMD int - state flags (FLAG_*).
#define CMD_VOID   0
#define CMD_UNKNOWN   -1
#define CMD_JSON   -2
#define FLAG_DISABLED   0x100UL
#define FLAG_LOCKED_CMD   0x200UL
#define FLAG_LOCKED_SET   0x400UL
#define FLAG_FREEZED   0x600UL
#define FLAG_SEND_DEFFERED   0x800UL
#define FLAG_COMMAND   0x1000UL
#define FLAG_PARAMETERS   0x2000UL
#define FLAG_FLAGS   0x4000UL
#define FLAG_SEND_RETRY   0x8000UL
#define FLAG_ACTION_NEEDED   0x10000UL
#define FLAG_ACTION_IN_PROCESS   0x20000UL
#define FLAG_HALTED   0x40000UL
#define FLAG_XON   0x80000UL
#define FLAG_SEND_DELAYED   0x100000UL
#define FLAG_SEND_IMMEDIATE   0x1UL
#define FLAG_NOT_SEND_CAN   0x2UL
#define ST_VOID   0
 Definition of all possible types of argument, contained in class.
#define ST_PERCENTS255   1
#define ST_HSV255   2
#define ST_HS   3
#define ST_RGB   4
#define ST_RGBW   5
#define ST_TENS   6
#define ST_FLOAT   7
#define ST_FLOAT_CELSIUS   8
#define ST_FLOAT_FARENHEIT   9
#define ST_INT32   10
#define ST_UINT32   11
#define ST_STRING   12
#define MAP_SCALE   1
 Mapping options for doMapping()/doReverseMapping().
#define MAP_VAL_CMD   2

Typedefs

typedef char cmdstr[10]
typedef char ch_type[9]

Functions

int txt2cmd (char *payload)
int replaceTypeToInt (aJsonObject *verb)

Variables

const cmdstr commands_P[] PROGMEM

Macro Definition Documentation

◆ ch_typeNum

#define ch_typeNum   sizeof(ch_type_P)/sizeof(ch_type)

◆ CMD_AUTO

#define CMD_AUTO   0xe

◆ CMD_COOL

#define CMD_COOL   0x15

◆ CMD_DISABLE

#define CMD_DISABLE   0xb

◆ CMD_DN

#define CMD_DN   9

◆ CMD_DRY

#define CMD_DRY   0x16

◆ CMD_ENABLE

#define CMD_ENABLE   0xa

◆ CMD_FAN

#define CMD_FAN   0xf

◆ CMD_FREEZE

#define CMD_FREEZE   0xd

◆ CMD_HALT

#define CMD_HALT   5

◆ CMD_HEAT

#define CMD_HEAT   0x14

◆ CMD_HEATCOOL

#define CMD_HEATCOOL   0x13

◆ CMD_HIGH

#define CMD_HIGH   0x10

◆ CMD_HSV

#define CMD_HSV   0x18

◆ CMD_JSON

#define CMD_JSON   -2

◆ CMD_LOW

#define CMD_LOW   0x12

◆ CMD_MASK

#define CMD_MASK   0xffUL

Low byte of the packed I_CMD int - command code.

◆ CMD_MED

#define CMD_MED   0x11

◆ CMD_OFF

#define CMD_OFF   2

◆ CMD_ON

#define CMD_ON   1

Definition of Commands.

Command codes (indexes of commands_P). Codes 1..9 are decimal, 0xA..0x19 are hex. Commands up to CMD_FAN (0xF) are "channel commands" that affect the whole channel state; the rest are device-specific (AC modes, color, reset). CMD_VOID/CMD_UNKNOWN/CMD_JSON are special non-wired codes used internally.

◆ CMD_RESET

#define CMD_RESET   0x19

◆ CMD_RESTORE

#define CMD_RESTORE   3

◆ CMD_RGB

#define CMD_RGB   0x17

◆ CMD_TOGGLE

#define CMD_TOGGLE   4

◆ CMD_UNFREEZE

#define CMD_UNFREEZE   0xc

◆ CMD_UNKNOWN

#define CMD_UNKNOWN   -1

◆ CMD_UP

#define CMD_UP   8

◆ CMD_VOID

#define CMD_VOID   0

◆ CMD_XOFF

#define CMD_XOFF   7

◆ CMD_XON

#define CMD_XON   6

◆ commandsNum

#define commandsNum   sizeof(commands_P)/sizeof(cmdstr)

◆ FLAG_ACTION_IN_PROCESS

#define FLAG_ACTION_IN_PROCESS   0x20000UL

◆ FLAG_ACTION_NEEDED

#define FLAG_ACTION_NEEDED   0x10000UL

◆ FLAG_COMMAND

#define FLAG_COMMAND   0x1000UL

◆ FLAG_DISABLED

#define FLAG_DISABLED   0x100UL

State flags packed with the command in the I_CMD item element (FLAG_MASK bits):

  • FLAG_DISABLED - channel disabled (needs ENABLE to unlock)
  • FLAG_LOCKED_CMD / FLAG_LOCKED_SET - frozen: commands / values are blocked
  • FLAG_FREEZED - both locked
  • FLAG_SEND_DEFFERED - status publish is pending (no network / low RAM)
  • FLAG_COMMAND / FLAG_PARAMETERS / FLAG_FLAGS - what to include in the next status
  • FLAG_SEND_RETRY - retry the failed Modbus transaction
  • FLAG_ACTION_NEEDED / FLAG_ACTION_IN_PROCESS - driver action state machine
  • FLAG_HALTED - turned off by CMD_HALT (CMD_RESTORE to return)
  • FLAG_XON - turned on by CMD_XON (CMD_XOFF to release)
  • FLAG_SEND_DELAYED - publish remaining time of a delayed command

SendStatus options:

  • FLAG_SEND_IMMEDIATE - do not defer the publish
  • FLAG_NOT_SEND_CAN - skip publishing to CAN

◆ FLAG_FLAGS

#define FLAG_FLAGS   0x4000UL

◆ FLAG_FREEZED

#define FLAG_FREEZED   0x600UL

◆ FLAG_HALTED

#define FLAG_HALTED   0x40000UL

◆ FLAG_LOCKED_CMD

#define FLAG_LOCKED_CMD   0x200UL

◆ FLAG_LOCKED_SET

#define FLAG_LOCKED_SET   0x400UL

◆ FLAG_MASK

#define FLAG_MASK   0x00ffff00UL

High two bytes of the packed I_CMD int - state flags (FLAG_*).

◆ FLAG_NOT_SEND_CAN

#define FLAG_NOT_SEND_CAN   0x2UL

◆ FLAG_PARAMETERS

#define FLAG_PARAMETERS   0x2000UL

◆ FLAG_SEND_DEFFERED

#define FLAG_SEND_DEFFERED   0x800UL

◆ FLAG_SEND_DELAYED

#define FLAG_SEND_DELAYED   0x100000UL

◆ FLAG_SEND_IMMEDIATE

#define FLAG_SEND_IMMEDIATE   0x1UL

◆ FLAG_SEND_RETRY

#define FLAG_SEND_RETRY   0x8000UL

◆ FLAG_XON

#define FLAG_XON   0x80000UL

◆ MAP_SCALE

#define MAP_SCALE   1

Mapping options for doMapping()/doReverseMapping().

◆ MAP_VAL_CMD

#define MAP_VAL_CMD   2

◆ ST_FLOAT

#define ST_FLOAT   7

◆ ST_FLOAT_CELSIUS

#define ST_FLOAT_CELSIUS   8

◆ ST_FLOAT_FARENHEIT

#define ST_FLOAT_FARENHEIT   9

◆ ST_HS

#define ST_HS   3

◆ ST_HSV255

#define ST_HSV255   2

◆ ST_INT32

#define ST_INT32   10

◆ ST_PERCENTS255

#define ST_PERCENTS255   1

◆ ST_RGB

#define ST_RGB   4

◆ ST_RGBW

#define ST_RGBW   5

◆ ST_STRING

#define ST_STRING   12

◆ ST_TENS

#define ST_TENS   6

◆ ST_UINT32

#define ST_UINT32   11

◆ ST_VOID

#define ST_VOID   0

Definition of all possible types of argument, contained in class.

Storage type codes (ST_*) - how the 4-byte itemCmd parameter word is interpreted (value representation of a channel).

Typedef Documentation

◆ ch_type

typedef char ch_type[9]

Short textual names of channel types (CH_*); array indexes match CH_DIMMER(0)..CH_SPRINKLER(23). Used to resolve "type":"DMX" etc. in config.

◆ cmdstr

typedef char cmdstr[10]

Textual names of item commands; array indexes match the CMD_* codes (CMD_ON=1 ... CMD_RESET=0x19).

  • "ON" (1) - turn channel ON
  • "OFF" (2) - turn channel OFF
  • "REST" (3) - restore: turn ON only if previously halted (CMD_HALT)
  • "TOGGLE" (4) - toggle ON/OFF
  • "HALT" (5) - turn OFF, stays locked until REST
  • "XON" (6) - momentary ON, stays on until XOFF
  • "XOFF" (7) - release a channel turned on by XON
  • "INCREASE" (8) / "DECREASE" (9) - step the value up / down
  • "ENABLE" (0xA) - enable channel (for PID - enable regulation; for XON/XOFF - lift limitation)
  • "DISABLE" (0xB) - disable channel
  • "UNFREEZE" (0xC) / "FREEZE" (0xD) - unlock / lock commands and values
  • "AUTO" (0xE) - thermostat/AC auto mode
  • "FAN_ONLY" (0xF) - AC fan-only mode
  • "HIGH" (0x10) / "MEDIUM" (0x11) / "LOW" (0x12) - AC/vent fan levels
  • "HEAT_COOL" (0x13) - AC auto heat/cool mode
  • "HEAT" (0x14) / "COOL" (0x15) / "DRY" (0x16) - thermostat/AC modes
  • "RGB" (0x17) - set color in RGB notation
  • "HSV" (0x18) - set color in HSV notation
  • "RESET" (0x19) - reset device to defaults

Function Documentation

◆ replaceTypeToInt()

int replaceTypeToInt ( aJsonObject * verb)
Returns
the channel type code (CH_*) for a config "type" verb (string or int).

◆ txt2cmd()

int txt2cmd ( char * payload)

Translate a text payload to a command code.

Parameters
payload- text command word, number or color ("ON", "-5", "#FF0000")
Returns
CMD_* code; CMD_VOID for plain numbers, CMD_UNKNOWN if unrecognized

Translate a text payload to a command code.

Parameters
payload- text command word ("ON", "HALT", ...), number or color
Returns
CMD_* code; CMD_VOID for plain numbers, CMD_UNKNOWN if unrecognized

Variable Documentation

◆ PROGMEM

const ch_type ch_type_P [] PROGMEM
Initial value:
=
{
"","ON","OFF","REST","TOGGLE","HALT","XON","XOFF","INCREASE","DECREASE",
"ENABLE","DISABLE","UNFREEZE","FREEZE",
"AUTO","FAN_ONLY",
"HIGH","MEDIUM","LOW","HEAT_COOL",
"HEAT","COOL","DRY","RGB","HSV","RESET"
}