#include <LivingColors.h>
Public Member Functions | |
LivingColors (unsigned char pinCS=10, unsigned char pinSCK=13, unsigned char pinMOSI=11, unsigned char pinMISO=12) | |
~LivingColors () | |
void | init () |
unsigned char | getMaxNumLamps () |
unsigned char | getNumLamps () |
char | addLamp (unsigned char *address) |
bool | getLamp (unsigned char index, unsigned char *address) |
void | learnLamps () |
void | clearLamps () |
void | setLampColourRGB (unsigned char index, unsigned char r, unsigned char g, unsigned char b) |
void | setLampColourHSV (unsigned char index, unsigned char h, unsigned char s, unsigned char v) |
void | turnLampOnRGB (unsigned char index, unsigned char r, unsigned char g, unsigned char b) |
void | turnLampOnHSV (unsigned char index, unsigned char h, unsigned char s, unsigned char v) |
void | turnLampOff (unsigned char index) |
Protected Attributes | |
CC2500 | m_cc2500 |
unsigned char | m_sequence |
unsigned char | m_lamps [MAXLAMPS][10] |
unsigned char | m_maxNumLamps |
unsigned char | m_numLamps |
Private Member Functions | |
void | checkAddress (unsigned char *address) |
void | sendCommand (unsigned char index, unsigned char command, unsigned char h, unsigned char s, unsigned char v) |
LivingColors (const LivingColors &that) | |
LivingColors & | operator= (const LivingColors &that) |
This class implements basic functions to communicate with the LivingColors lamp.
LivingColors::LivingColors | ( | unsigned char | pinCS = 10 , |
|
unsigned char | pinSCK = 13 , |
|||
unsigned char | pinMOSI = 11 , |
|||
unsigned char | pinMISO = 12 | |||
) |
Constructor.
[in] | pinCS | Pin number of slave select, default is 10. |
[in] | pinSCK | Pin number of clock, default is 13 (Arduino standard). |
[in] | pinMOSI | Pin number of master output slave input, default is 11 (Arduino standard). |
[in] | pinMISO | Pin number of master input slave output, default is 12 (Arduino standard). |
LivingColors::~LivingColors | ( | ) |
Destructor.
LivingColors::LivingColors | ( | const LivingColors & | that | ) | [private] |
Copy constructor, disabled.
void LivingColors::init | ( | ) |
unsigned char LivingColors::getMaxNumLamps | ( | ) |
Returns the maximum number of storable lamps.
unsigned char LivingColors::getNumLamps | ( | ) |
Returns the number of currently known lamps.
char LivingColors::addLamp | ( | unsigned char * | address | ) |
Adds a lamp address to storage. Address must be 9 bytes long.
[in] | address | Array holding lamp address. |
bool LivingColors::getLamp | ( | unsigned char | index, | |
unsigned char * | address | |||
) |
Saves the address of lamp with given index in supplied array. Only fills array when index and address are valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | address | Array for lamp address, must be at least 9 bytes long. |
void LivingColors::learnLamps | ( | ) |
Tries to learn lamp addresses by snooping the commands which are sent by the official remote. The learning time period is about 5 seconds; hold the official remote very close to the board and press some commands (e.g. change colour, off, on).
void LivingColors::clearLamps | ( | ) |
Clears all lamp addresses.
void LivingColors::setLampColourRGB | ( | unsigned char | index, | |
unsigned char | r, | |||
unsigned char | g, | |||
unsigned char | b | |||
) |
Sets colour of lamp with given index. Updates colour only if lamp address is valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | r | Red value for lamp (0-255). |
[in] | g | Green value for lamp (0-255). |
[in] | b | Blue value for lamp (0-255). |
void LivingColors::setLampColourHSV | ( | unsigned char | index, | |
unsigned char | h, | |||
unsigned char | s, | |||
unsigned char | v | |||
) |
Sets colour of lamp with given index. Updates colour only if lamp address is valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | h | Hue value for lamp (0-255). |
[in] | s | Saturation value for lamp (0-255). |
[in] | v | Value value for lamp (0-255). |
void LivingColors::turnLampOnRGB | ( | unsigned char | index, | |
unsigned char | r, | |||
unsigned char | g, | |||
unsigned char | b | |||
) |
Turns lamp with given index on and sets colour if lamp address is valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | r | Red value for lamp (0-255). |
[in] | g | Green value for lamp (0-255). |
[in] | b | Blue value for lamp (0-255). |
void LivingColors::turnLampOnHSV | ( | unsigned char | index, | |
unsigned char | h, | |||
unsigned char | s, | |||
unsigned char | v | |||
) |
Turns lamp with given index on and sets colour if lamp address is valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | h | Hue value for lamp (0-255). |
[in] | s | Saturation value for lamp (0-255). |
[in] | v | Value value for lamp (0-255). |
void LivingColors::turnLampOff | ( | unsigned char | index | ) |
Turns lamp with given index off if lamp address is valid.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(); |
void LivingColors::checkAddress | ( | unsigned char * | address | ) | [private] |
Checks if lamp address is already known, stores address if not known.
[in] | address | Lamp address to check, length must be at least 10 bytes. |
void LivingColors::sendCommand | ( | unsigned char | index, | |
unsigned char | command, | |||
unsigned char | h, | |||
unsigned char | s, | |||
unsigned char | v | |||
) | [private] |
Sends command to lamp. Command can be on, off or set colour.
[in] | index | Lamp index, must be 0 <= index < getNumLamps(). |
[in] | command | Command to send (3 = set colour, 5 = on, 7 = off). |
[in] | h | Hue value to sent (0-255), must be corrected for LivingColors. |
[in] | s | Saturation value to sent (0-255). |
[in] | v | Value to sent (0-255). |
LivingColors& LivingColors::operator= | ( | const LivingColors & | that | ) | [private] |
Assignment operator, disabled.
CC2500 LivingColors::m_cc2500 [protected] |
CC2500 object to communicate with the LivingColors lamp.
unsigned char LivingColors::m_sequence [protected] |
Sequence number which is used during communication with the LivingColors lamp. The sent sequence number must match the received sequence number.
unsigned char LivingColors::m_lamps[MAXLAMPS][10] [protected] |
Address storage for lamps. The first byte indicates a valid address (0x01), the next 9 bytes are the lamp address.
A lamp address consists of a unique lamp identifier (first 4 bytes) and a unique remote identifier (last 5 bytes).
unsigned char LivingColors::m_maxNumLamps [protected] |
Maximum number of lamps that can be controlled.
unsigned char LivingColors::m_numLamps [protected] |
Number of stored lamp addresses.