-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLivingColors.h
executable file
·222 lines (195 loc) · 7.26 KB
/
LivingColors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*!
* \file LivingColors.h
* \version 1.1
* \date 29-01-2009
* \author George Mathijssen, [email protected]
*
* Copyright (c) 2008, 2009 George Mathijssen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* \internal
* Created: 03-10-2008
*/
#ifndef LIVINGCOLORS_H_
#define LIVINGCOLORS_H_
#include "CC2500.h"
#include "ColourConversion.h"
#include <inttypes.h>
#define MAXLAMPS 6
/*! \brief Class for interfacing with Philips LivingColors lamp.
*
* This class implements basic functions to communicate with the LivingColors lamp.
*/
class LivingColors
{
protected:
/*!
* CC2500 object to communicate with the LivingColors lamp.
*/
CC2500 m_cc2500;
/*!
* Sequence number which is used during communication with the LivingColors lamp. The sent
* sequence number must match the received sequence number.
*/
unsigned char m_sequence;
/*!
* 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 m_lamps[MAXLAMPS][10];
/*!
* Maximum number of lamps that can be controlled.
*/
unsigned char m_maxNumLamps;
/*!
* Number of stored lamp addresses.
*/
unsigned char m_numLamps;
public:
/*!
* Constructor.
*
* \param[in] pinCS Pin number of slave select, default is 10.
* \param[in] pinSCK Pin number of clock, default is 13 (Arduino standard).
* \param[in] pinMOSI Pin number of master output slave input, default is 11 (Arduino standard).
* \param[in] pinMISO Pin number of master input slave output, default is 12 (Arduino standard).
*/
LivingColors(unsigned char pinCS = 10,
unsigned char pinSCK = 13,
unsigned char pinMOSI = 11,
unsigned char pinMISO = 12);
/*!
* Destructor.
*/
~LivingColors();
/*!
* Initializes communication with the LivingColors lamp.
*/
void init();
/*!
* Returns the maximum number of storable lamps.
*
* \return Maximum number of lamps.
*/
unsigned char getMaxNumLamps();
/*!
* Returns the number of currently known lamps.
*
* \return Number of known adresses.
*/
unsigned char getNumLamps();
/*!
* Adds a lamp address to storage. Address must be 9 bytes long.
*
* \param[in] address Array holding lamp address.
* \return Lamp index for address or -1 on failure.
*/
char addLamp(unsigned char* address);
/*!
* Saves the address of lamp with given index in supplied array. Only fills array when index and
* address are valid.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] address Array for lamp address, must be at least 9 bytes long.
* \return True if array is filled with valid address, false otherwise.
*/
bool getLamp(unsigned char index, unsigned char* address);
/*!
* 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 learnLamps();
/*!
* Clears all lamp addresses.
*/
void clearLamps();
/*!
* Sets colour of lamp with given index. Updates colour only if lamp address is valid.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] r Red value for lamp (0-255).
* \param[in] g Green value for lamp (0-255).
* \param[in] b Blue value for lamp (0-255).
*/
void 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.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] h Hue value for lamp (0-255).
* \param[in] s Saturation value for lamp (0-255).
* \param[in] v Value value for lamp (0-255).
*/
void setLampColourHSV(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.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] r Red value for lamp (0-255).
* \param[in] g Green value for lamp (0-255).
* \param[in] b Blue value for lamp (0-255).
*/
void 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.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] h Hue value for lamp (0-255).
* \param[in] s Saturation value for lamp (0-255).
* \param[in] v Value value for lamp (0-255).
*/
void turnLampOnHSV(unsigned char index, unsigned char h, unsigned char s, unsigned char v);
/*!
* Turns lamp with given index off if lamp address is valid.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps();
*/
void turnLampOff(unsigned char index);
private:
/*!
* Checks if lamp address is already known, stores address if not known.
*
* \param[in] address Lamp address to check, length must be at least 10 bytes.
*/
void checkAddress(unsigned char* address);
/*!
* Sends command to lamp. Command can be on, off or set colour.
*
* \param[in] index Lamp index, must be 0 <= index < getNumLamps().
* \param[in] command Command to send (3 = set colour, 5 = on, 7 = off).
* \param[in] h Hue value to sent (0-255), must be corrected for LivingColors.
* \param[in] s Saturation value to sent (0-255).
* \param[in] v Value to sent (0-255).
*/
void sendCommand(unsigned char index,
unsigned char command,
unsigned char h,
unsigned char s,
unsigned char v);
/*!
* Copy constructor, disabled.
*/
LivingColors(const LivingColors& that);
/*!
* Assignment operator, disabled.
*/
LivingColors& operator=(const LivingColors& that);
};
#endif