hyperion.ng
LedDevicePhilipsHue.h
1 #pragma once
2 
3 // STL includes
4 #include <set>
5 
6 // Qt includes
7 #include <QNetworkAccessManager>
8 #include <QTimer>
9 
10 // Leddevice includes
11 #include <leddevice/LedDevice.h>
12 
13 // Forward declaration
14 struct CiColorTriangle;
15 
19 struct CiColor
20 {
22  float x;
24  float y;
26  float bri;
27 
40  static CiColor rgbToCiColor(float red, float green, float blue, CiColorTriangle colorSpace);
41 
47  static bool isPointInLampsReach(CiColor p, CiColorTriangle colorSpace);
48 
56  static float crossProduct(CiColor p1, CiColor p2);
57 
68 
76  static float getDistanceBetweenTwoPoints(CiColor p1, CiColor p2);
77 };
78 
79 bool operator==(CiColor p1, CiColor p2);
80 bool operator!=(CiColor p1, CiColor p2);
81 
86 {
87  CiColor red, green, blue;
88 };
89 
90 class PhilipsHueBridge : public QObject
91 {
92  Q_OBJECT
93 
94 private:
95  Logger* _log;
97  QNetworkAccessManager manager;
99  QString host;
101  QString username;
103  QTimer bTimer;
104 
105 private slots:
110  void resolveReply(QNetworkReply* reply);
111 
112 public slots:
116  void bConnect(void);
117 
118 signals:
122  void newLights(QMap<quint16,QJsonObject> map);
123 
124 public:
125  PhilipsHueBridge(Logger* log, QString host, QString username);
126 
132  void post(QString route, QString content);
133 };
134 
139 {
140 private:
141  Logger* _log;
142  PhilipsHueBridge* bridge;
144  unsigned int id;
145  bool on;
146  unsigned int transitionTime;
147  CiColor color;
149  QString modelId;
150  CiColorTriangle colorSpace;
152  QString originalState;
153 
157  void set(QString state);
158 
159 public:
160  // Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
161  // Light strips, color iris, ...
162  static const std::set<QString> GAMUT_A_MODEL_IDS;
163  // Hue bulbs, spots, ...
164  static const std::set<QString> GAMUT_B_MODEL_IDS;
165  // Hue Lightstrip plus, go ...
166  static const std::set<QString> GAMUT_C_MODEL_IDS;
167 
175  PhilipsHueLight(Logger* log, PhilipsHueBridge* bridge, unsigned int id, QJsonObject values);
176  ~PhilipsHueLight();
177 
181  void setOn(bool on);
182 
186  void setTransitionTime(unsigned int transitionTime);
187 
192  void setColor(CiColor color, float brightnessFactor = 1.0f);
193  CiColor getColor() const;
194 
197  CiColorTriangle getColorSpace() const;
198 
199 };
200 
210 {
211 
212  Q_OBJECT
213 
214 public:
220  LedDevicePhilipsHue(const QJsonObject &deviceConfig);
221 
225  virtual ~LedDevicePhilipsHue();
226 
228  static LedDevice* construct(const QJsonObject &deviceConfig);
229 
230 public slots:
232  virtual void start();
233 
234 private slots:
239  void newLights(QMap<quint16, QJsonObject> map);
240 
241  void stateChanged(bool newState);
242 
243 protected:
251  virtual int write(const std::vector<ColorRgb> & ledValues);
252  bool init(const QJsonObject &deviceConfig);
253 
254 private:
256  PhilipsHueBridge* _bridge;
257 
259  bool switchOffOnBlack;
261  float brightnessFactor;
264  int transitionTime;
266  std::vector<unsigned int> lightIds;
268  std::vector<PhilipsHueLight> lights;
269 };
Definition: Logger.h:32
Definition: LedDevicePhilipsHue.h:90
Interface (pure virtual base class) for LedDevices.
Definition: LedDevice.h:32
static float getDistanceBetweenTwoPoints(CiColor p1, CiColor p2)
Definition: LedDevicePhilipsHue.cpp:116
Implementation for the Philips Hue system.
Definition: LedDevicePhilipsHue.h:209
Color triangle to define an available color space for the hue lamps.
Definition: LedDevicePhilipsHue.h:85
A color point in the color space of the hue system.
Definition: LedDevicePhilipsHue.h:19
static CiColor getClosestPointToPoint(CiColor a, CiColor b, CiColor p)
Definition: LedDevicePhilipsHue.cpp:95
static bool isPointInLampsReach(CiColor p, CiColorTriangle colorSpace)
Definition: LedDevicePhilipsHue.cpp:78
float x
X component.
Definition: LedDevicePhilipsHue.h:22
static CiColor rgbToCiColor(float red, float green, float blue, CiColorTriangle colorSpace)
Converts an RGB color to the Hue xy color space and brightness.
Definition: LedDevicePhilipsHue.cpp:18
float y
Y component.
Definition: LedDevicePhilipsHue.h:24
static float crossProduct(CiColor p1, CiColor p2)
Definition: LedDevicePhilipsHue.cpp:73
Simple class to hold the id, the latest color, the color space and the original state.
Definition: LedDevicePhilipsHue.h:138
float bri
The brightness.
Definition: LedDevicePhilipsHue.h:26