HueDriver
Source:
HueDriver.h
HueDriver¶
src/light/drivers/HueDriver.h:37Inherits:
DriverBase
Output driver: sends the buffer to Philips Hue bulbs as pixels, so a small grid runs any effect.
It reads its window of the shared buffer and pushes each light's color to the bridge, the same shape as NetworkSendDriver, over the Hue v1 HTTP API rather than UDP.
It is HTTP rather than a wire protocol, so the rate is bounded by connection churn. Each PUT opens a fresh connection. That gives smooth ambient color, not real time.
Prior art: the Hue v1 CLIP API public documentation; the effect-as-output mapping is our own.
Public Attributes¶
uint8_t bridgeIp = {}
: The bridge's LAN IP, entered in the UI (4 octets).
char appKey = {}
: The Hue username/app key: filled by the Pair button, then persisted.
Public Methods¶
inline HueDriver()
: Default to the RGB preset: this driver reads the output back as RGB to make an HSV.
virtual inline bool hasCorrectionControls() const override
: Hue converts to HSV, RGB-fixed, so there is no correction UI to show.
virtual inline void defineDriverControls() override
: Bind the bridge address, the pairing button, the room and light filters, and the window.
virtual inline void setSourceBuffer(Buffer * buf) override
: Take the shared source buffer this driver reads its window from.
virtual inline void onControlChanged(const char * controlName) override
: React to a control change: start pairing, re-point the bridge, or re-derive the subset.
virtual inline void tick() override
: Do at most one bounded PUT, and only once the rate-limit interval has elapsed.
virtual inline void tick1s() override
: Run the slower bridge work: the pairing poll, the light fetch, and the announce.
virtual inline void release() override
: Stop any in-flight pairing and release the dropdown-name heap, then chain to the base.
inline bool wouldPushForTest(uint8_t idx, uint8_t r, uint8_t g, uint8_t b, char * outBody, size_t cap)
: Test seam: whether a light's RGB would be sent, and the body it would send.
inline void parseLightsForTest(const char * json)
: Test seam: parse a real /lights JSON body through fetchLights' color-light extractor.
inline uint8_t lightCountForTest() const
: Count of kept color+reachable lights.
inline uint16_t hueIdForTest(uint8_t i) const
: The bridge light id at window index i, or 0 when out of range.
inline int8_t colorCountForTest() const
: The same count as the read-only control / bridge field; 0 before any fetch.
inline void parseGroupsForTest(const char * json)
: Test seam: parse a real groups body through the room extractor.
inline uint8_t roomCountForTest() const
: Count of kept Rooms (bridge groups with type=="Room").
inline void setRoomForTest(uint8_t r)
: Select a room and re-derive the driven subset, as the dropdown does.
inline void setLightForTest(uint8_t l)
: Select light l within the chosen room and re-derive the driven subset.
inline void refreshStatusForTest()
: Recompute the status line without waiting for a tick.
inline uint8_t drivenCountForTest() const
: How many lights survive the room+light filter: the set pushOneChangedLight walks.
inline uint16_t drivenIdForTest(uint8_t i) const
: The bridge light id at filtered index i, or 0 when out of range.
Public Static Methods¶
static inline void rgbToHsvForTest(uint8_t r, uint8_t g, uint8_t b, uint16_t & h, uint8_t & s, uint8_t & v)
: Test seam for the RGB→HSV mapping (no bridge needed).
static inline bool bodyLooksCompleteForTest(const char * body)
: Test seam: the truncation signal fetchLights grows against (a complete /lights body ends '}').
More info¶
The wire contract¶
Plain HTTP, no TLS, bench-confirmed on a BSB002 bridge:
POST /api pair, once the link button is pressed
GET /api/<key>/lights the lights, keyed by bridge id
GET /api/<key>/groups the rooms, each listing its lights
PUT /api/<key>/lights/<id>/state on, brightness, hue, saturation, transition
Which lights are driven¶
Only color-capable, reachable lights, narrowed further by the room and light selectors. The shared output Correction applies as it does on the LED drivers, so brightness reaches the Hue lights too.
