HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Interfaces::ColourControl::HS_Colour Struct Reference

Helper class that supports the Hue and Saturation colour mode. More...

#include <colour_control.h>

+ Collaboration diagram for HF::Interfaces::ColourControl::HS_Colour:

Public Member Functions

 HS_Colour (uint16_t _hue, uint8_t _saturation)
 Constructor. More...
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (Common::ByteArray &array, uint16_t offset=0) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t unpack (const Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
int compare (const HS_Colour &other) const
 Compare this attribute with the given attribute in other. More...
 
float changed (const HS_Colour &other) const
 This method is used to get the percentage of change that the attribute has in relation to the value present in other. More...
 
bool operator== (const HS_Colour &other) const
 Operator equal.
 
bool operator!= (const HS_Colour &other) const
 Operator not equal.
 

Static Public Member Functions

static int32_t invert_angle (int32_t angle, uint16_t max_value)
 Helper method to invert a traveling angle. More...
 
static int32_t get_travel_distance (const Direction dir, uint16_t initial, uint16_t final, uint16_t max)
 Helper method to get the angle between two hue/saturation values. More...
 

Static Public Attributes

static constexpr uint16_t min_size
 Minimum pack/unpack required data size.
 

Detailed Description

Helper class that supports the Hue and Saturation colour mode.

This class implements the necessary functions for message serialization.

Definition at line 117 of file colour_control.h.

Constructor & Destructor Documentation

◆ HS_Colour()

HF::Interfaces::ColourControl::HS_Colour::HS_Colour ( uint16_t  _hue,
uint8_t  _saturation 
)
inline

Constructor.

Parameters
[in]_huehue colour value.
[in]_saturationsaturation colour value.

Definition at line 130 of file colour_control.h.

130  :
131  saturation(_saturation)
132  {
133  hue = _hue < HUE ? _hue : HUE - 1;
134  }

Member Function Documentation

◆ changed()

float HF::Interfaces::ColourControl::HS_Colour::changed ( const HS_Colour other) const
inline

This method is used to get the percentage of change that the attribute has in relation to the value present in other.

Parameters
[in]otherattribute holding a previous value.
Returns
float indicating the percentage of change.

Definition at line 210 of file colour_control.h.

211  {
212  if (this->hue != other.hue)
213  {
214  return (100 * (this->hue - other.hue) / static_cast<float>(this->hue));
215  }
216  else
217  {
218  if (this->hue != other.hue)
219  {
220  return (100 * (this->hue - other.hue) / static_cast<float>(this->hue));
221  }
222  else
223  {
224  return 0.0f;
225  }
226  }
227  }

◆ compare()

int HF::Interfaces::ColourControl::HS_Colour::compare ( const HS_Colour other) const
inline

Compare this attribute with the given attribute in other.

This method should return < 0 if this attribute is less that, 0 if it is equal and > 0 if greater that the other attribute.

Parameters
[in]otherattribute to compare to.
Return values
<0if attribute less than other;
0if attribute equal to other;
>0if attribute greater than other.

Definition at line 190 of file colour_control.h.

191  {
192  if (this->hue != other.hue)
193  {
194  return (this->hue - other.hue);
195  }
196  else
197  {
198  if (this->hue != other.hue)
199  {
200  return (this->hue - other.hue);
201  }
202  else
203  {
204  return 0;
205  }
206  }
207  }

◆ get_travel_distance()

static int32_t HF::Interfaces::ColourControl::HS_Colour::get_travel_distance ( const Direction  dir,
uint16_t  initial,
uint16_t  final,
uint16_t  max 
)
static

Helper method to get the angle between two hue/saturation values.

This method takes in consideration the direction of travel from the initial to the final value.

Parameters
[in]dirthe travel direction.
[in]initialthe initial value.
[in]finalthe final value.
[in]maxthe maximum value.
Returns
the angle between the final and initial value.

◆ invert_angle()

static int32_t HF::Interfaces::ColourControl::HS_Colour::invert_angle ( int32_t  angle,
uint16_t  max_value 
)
static

Helper method to invert a traveling angle.

This method returns the exterior angle from an internal one, or an interior from an exterior angle.

Note
This also inverts the angle signal. If the input angle is positive (CW rotation), the output is negative (CCW rotation).
Parameters
[in]anglethe angle to invert.
[in]max_valuethe max value for the angle.
Returns
the inverted angle.

◆ pack()

uint16_t HF::Interfaces::ColourControl::HS_Colour::pack ( Common::ByteArray array,
uint16_t  offset = 0 
) const

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

◆ size()

uint16_t HF::Interfaces::ColourControl::HS_Colour::size ( ) const
inline

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Definition at line 178 of file colour_control.h.

References min_size.

179  {
180  return min_size;
181  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.

◆ unpack()

uint16_t HF::Interfaces::ColourControl::HS_Colour::unpack ( const Common::ByteArray array,
uint16_t  offset = 0 
)

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

The documentation for this struct was generated from the following file: