LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
itemCmd Class Reference

Command + value container passed between items, drivers and MQTT. More...

#include <itemCmd.h>

Public Member Functions

 itemCmd (uint8_t _type=ST_VOID, uint8_t _code=CMD_VOID)
 Constructor with definition of type and command.
 itemCmd (float val)
 Constructor with definition of FLOAT value in storage.
 itemCmd (Item *item)
 Constructor with loading value from Item.
 itemCmd (char *cmd)
itemCmd assignFrom (itemCmd from, short chanType=-1)
bool loadItem (Item *item, uint16_t optionsFlag=FLAG_PARAMETERS)
bool loadItemDef (Item *item, uint16_t optionsFlag=FLAG_PARAMETERS)
bool saveItem (Item *item, uint16_t optionsFlag=FLAG_PARAMETERS)
itemCmd Int (int32_t i)
itemCmd uInt (uint32_t i)
itemCmd Float (float f)
itemCmd Tens (int32_t i)
itemCmd Tens_raw (int32_t i)
itemCmd Cmd (uint8_t i)
itemCmd Cmd (itemCmd 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)
itemCmd Str (char *str)
bool setH (uint16_t)
bool setS (uint8_t)
bool setColorTemp (int)
int getColorTemp ()
uint16_t getH ()
uint16_t getS ()
itemCmd setArgType (uint8_t)
itemCmd convertTo (uint8_t)
uint8_t getStoragetypeByChanType (short chanType)
itemCmd Percents (int i)
itemCmd Percents255 (int i)
uint8_t getSuffix ()
itemCmd setSuffix (uint8_t suffix)
bool incrementPercents (long int, long int limit)
bool incrementH (long int)
bool incrementS (long int)
bool incrementTemp (long int dif)
long int getInt ()
long int getTens ()
long int getTens_raw ()
float getFloat ()
char * getString ()
long int getSingleInt ()
short getPercents (bool inverse=false)
short getPercents255 (bool inverse=false)
bool setPercents (int percents)
uint8_t getCmd ()
uint8_t getArgType ()
uint8_t getCmdParam ()
char * toString (char *Buffer, int bufLen, int sendFlags=FLAG_COMMAND|FLAG_PARAMETERS, bool scale100=false)
bool isCommand ()
bool isChannelCommand ()
bool isValue ()
bool isColor ()
itemCmd setDefault ()
itemCmd setChanType (short chanType)
void debugOut ()
itemCmd doMapping (aJsonObject *mappingData)
itemCmd doReverseMapping (aJsonObject *mappingData)
bool scale100 ()

Public Attributes

itemCmdStore cmd
 Packed command word: code, storage type, suffix.
itemArgStore param
 Packed parameter: number / float / string / color.

Detailed Description

Command + value container passed between items, drivers and MQTT.

itemCmd packs a command code (CMD_*), a typed value (ST_* storage) and a topic suffix (S_*) into two 32-bit words (itemCmdStore + itemArgStore). It is the universal currency of the control core: parsed from text or JSON, converted to the channel's storage type, executed by the driver and serialized back to text for status publishing.

Constructor & Destructor Documentation

◆ itemCmd() [1/4]

itemCmd::itemCmd ( uint8_t _type = ST_VOID,
uint8_t _code = CMD_VOID )

Constructor with definition of type and command.

Create a command of the given code with an empty parameter of the given storage type.

Parameters
type- type of value (ST_???, ST_VOID by default)
code- code of command (CMD_VOID by default)

◆ itemCmd() [2/4]

itemCmd::itemCmd ( float val)

Constructor with definition of FLOAT value in storage.

Create a value with ST_FLOAT storage.

Parameters
float
type- type of value (ST_FLOAT or ST_FLOAT_CELSIUS or ST_FLOAT_FARENHEIT) - optional

◆ itemCmd() [3/4]

itemCmd::itemCmd ( Item * item)

Constructor with loading value from Item.

Create a copy of the currently stored command/value of the item.

Parameters
Item

◆ itemCmd() [4/4]

itemCmd::itemCmd ( char * _cmd)

Parse a text command/value ("ON", "50", "-1.5", "#FF0000", "HSV:100,50,255").

 \brief Constructor with textual definition of command
 \param cmd - name of cmd 

todo - extend to values

Member Function Documentation

◆ assignFrom()

itemCmd itemCmd::assignFrom ( itemCmd from,
short chanType = -1 )

Convert the value of from to the storage type appropriate for chanType and copy it to *this.

◆ Cmd() [1/2]

itemCmd itemCmd::Cmd ( itemCmd i)

Copy the command code and parameter from another itemCmd.

◆ Cmd() [2/2]

itemCmd itemCmd::Cmd ( uint8_t i)

Set the command code (and S_CMD suffix).

◆ convertTo()

itemCmd itemCmd::convertTo ( uint8_t type)

Convert the stored value to the given storage type (ST_*).

◆ debugOut()

void itemCmd::debugOut ( )

Dump the command to the debug serial.

◆ doMapping()

itemCmd itemCmd::doMapping ( aJsonObject * mappingData)

Map the unified command/value to a device-specific value via mappingData.

◆ doReverseMapping()

itemCmd itemCmd::doReverseMapping ( aJsonObject * mappingData)

Map a device-specific value back to the unified representation.

◆ Float()

itemCmd itemCmd::Float ( float f)

Set the parameter to a float (ST_FLOAT).

◆ getArgType()

uint8_t itemCmd::getArgType ( )
Returns
the parameter storage type (ST_*).

◆ getCmd()

uint8_t itemCmd::getCmd ( )
Returns
the command code (CMD_*).

◆ getCmdParam()

uint8_t itemCmd::getCmdParam ( )
Returns
the reserved cmdParam field.

◆ getColorTemp()

int itemCmd::getColorTemp ( )
Returns
stored color temperature in mireds (153..500), -1 if none.

Return color tempetature parameter from HSV or HSV255 types. return 153..500 value in success. -1 - if no value stored

◆ getFloat()

float itemCmd::getFloat ( )
Returns
the parameter as a float.

◆ getH()

uint16_t itemCmd::getH ( )
Returns
stored hue (0..365).

◆ getInt()

long int itemCmd::getInt ( )
Returns
the parameter as a signed 32-bit int.

◆ getPercents()

short itemCmd::getPercents ( bool inverse = false)
Returns
the value as percent 0..100 (inverse flips low/high).

◆ getPercents255()

short itemCmd::getPercents255 ( bool inverse = false)
Returns
the value as percent 0..255.

◆ getS()

uint16_t itemCmd::getS ( )
Returns
stored saturation (0..100).

◆ getSingleInt()

long int itemCmd::getSingleInt ( )
Returns
the parameter as a single int (first byte of a color, etc).

◆ getStoragetypeByChanType()

uint8_t itemCmd::getStoragetypeByChanType ( short chanType)
Returns
the default storage type (ST_*) for the given channel type.

◆ getString()

char * itemCmd::getString ( )
Returns
the parameter as a string (ST_STRING).

◆ getSuffix()

uint8_t itemCmd::getSuffix ( )
Returns
the topic suffix code (S_*) of this command.

◆ getTens()

long int itemCmd::getTens ( )
Returns
the parameter as a fixed-point value in tens.

◆ getTens_raw()

long int itemCmd::getTens_raw ( )
Returns
the raw fixed-point parameter (no scaling).

◆ HS()

itemCmd itemCmd::HS ( uint16_t h,
uint8_t s )

Set hue and saturation only (ST_HS).

◆ HSV()

itemCmd itemCmd::HSV ( uint16_t h,
uint8_t s,
uint8_t v )

Set an HSV255 color (hue 0..365, sat 0..100, value 0..255).

◆ HSV255()

itemCmd itemCmd::HSV255 ( uint16_t h,
uint8_t s,
uint8_t v )

Set an HSV255 color (ST_HSV255 storage).

◆ incrementH()

bool itemCmd::incrementH ( long int dif)

Increase/decrease the hue by step (with wrap-around).

◆ incrementPercents()

bool itemCmd::incrementPercents ( long int dif,
long int limit )

Increase/decrease a percent/int/float value by step, clamped to [0, limit].

◆ incrementS()

bool itemCmd::incrementS ( long int dif)

Increase/decrease the saturation by step.

◆ incrementTemp()

bool itemCmd::incrementTemp ( long int dif)

Increase/decrease the temperature by step.

◆ Int()

itemCmd itemCmd::Int ( int32_t i)

Set the parameter to a signed 32-bit int (ST_INT32).

◆ isChannelCommand()

bool itemCmd::isChannelCommand ( )
Returns
true if this is a whole-channel command (not a subcommand).

◆ isColor()

bool itemCmd::isColor ( )
Returns
true if this carries a color (HSV/RGB/RGBW).

◆ isCommand()

bool itemCmd::isCommand ( )
Returns
true if this is a command (not just a value).

◆ isValue()

bool itemCmd::isValue ( )
Returns
true if this carries a value.

◆ loadItem()

bool itemCmd::loadItem ( Item * item,
uint16_t optionsFlag = FLAG_PARAMETERS )

Load the stored command/value of the item into *this according to optionsFlag.

◆ loadItemDef()

bool itemCmd::loadItemDef ( Item * item,
uint16_t optionsFlag = FLAG_PARAMETERS )

Like loadItem(), but falls back to channel defaults for a never-controlled item.

◆ Percents()

itemCmd itemCmd::Percents ( int i)

Set the parameter to a percent value 0..100 (ST_PERCENTS255 storage).

◆ Percents255()

itemCmd itemCmd::Percents255 ( int i)

Set the parameter to a percent value 0..255 (ST_PERCENTS255 storage).

◆ RGB()

itemCmd itemCmd::RGB ( uint8_t r,
uint8_t g,
uint8_t b )

Set an RGB color (ST_RGB).

◆ RGBW()

itemCmd itemCmd::RGBW ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t w )

Set an RGBW color (ST_RGBW).

◆ saveItem()

bool itemCmd::saveItem ( Item * item,
uint16_t optionsFlag = FLAG_PARAMETERS )

Write *this back to the item storage (command, value, flags) according to optionsFlag.

◆ scale100()

bool itemCmd::scale100 ( )

Scale a 0..255 value to 0..100 in place.

Returns
true on success.

◆ setArgType()

itemCmd itemCmd::setArgType ( uint8_t type)

Change the parameter storage type (ST_*).

◆ setChanType()

itemCmd itemCmd::setChanType ( short chanType)

Set the storage type appropriate for the given channel type.

◆ setColorTemp()

bool itemCmd::setColorTemp ( int t)

Set the color temperature in mireds (153..500).

Returns
true on success.

Setup color tempetature parameter for HSV or HSV255 types. It must be 153..500 (mireds) value. Internally 1 - cold, 101 - warm light

◆ setDefault()

itemCmd itemCmd::setDefault ( )

Set the value to the channel default for the current storage type.

◆ setH()

bool itemCmd::setH ( uint16_t h)

Set the hue component (0..365).

Returns
true on success.

◆ setPercents()

bool itemCmd::setPercents ( int percents)

Set the value from a percent 0..100.

Returns
true on success.

◆ setS()

bool itemCmd::setS ( uint8_t s)

Set the saturation component (0..100).

Returns
true on success.

◆ setSuffix()

itemCmd itemCmd::setSuffix ( uint8_t suffix)

Set the topic suffix code (S_*).

◆ Str()

itemCmd itemCmd::Str ( char * str)

Set the parameter to a string pointer (ST_STRING).

◆ Tens()

itemCmd itemCmd::Tens ( int32_t i)

Set the parameter to a fixed-point value in tens (ST_TENS, scaled by TENS_BASE).

◆ Tens_raw()

itemCmd itemCmd::Tens_raw ( int32_t i)

Set the parameter to a raw fixed-point value in tens (ST_TENS, pre-scaled).

◆ toString()

char * itemCmd::toString ( char * Buffer,
int bufLen,
int sendFlags = FLAG_COMMAND | FLAG_PARAMETERS,
bool scale100 = false )

Serialize the command and/or value to a text payload for MQTT.

Parameters
sendFlags- FLAG_COMMAND and/or FLAG_PARAMETERS select what to print
scale100- scale 0..255 values to 0..100

◆ uInt()

itemCmd itemCmd::uInt ( uint32_t i)

Set the parameter to an unsigned 32-bit int (ST_UINT32).

Member Data Documentation

◆ cmd

itemCmdStore itemCmd::cmd

Packed command word: code, storage type, suffix.

◆ param

itemArgStore itemCmd::param

Packed parameter: number / float / string / color.


The documentation for this class was generated from the following files: