Support up to 32 devices for Hue emulation

This commit is contained in:
Stephan Hadinger 2019-09-23 22:57:20 +02:00
parent d364bb29bc
commit 93c031eb01
1 changed files with 24 additions and 6 deletions

View File

@ -376,18 +376,36 @@ void HueLightStatus2(uint8_t device, String *response)
} }
// generate a unique lightId mixing local IP address and device number // generate a unique lightId mixing local IP address and device number
// it is limited to 16 devices. // it is limited to 32 devices.
// last 24 bits of Mac address + 4 bits of local light // last 24 bits of Mac address + 4 bits of local light + high bit for relays 16-31, relay 32 is mapped to 0
uint32_t EncodeLightId(uint8_t idx) uint32_t EncodeLightId(uint8_t relay_id)
{ {
uint8_t mac[6]; uint8_t mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
uint32_t id = (mac[3] << 20) | (mac[4] << 12) | (mac[5] << 4) | (idx & 0xF); uint32_t id = 0;
if (relay_id >= 32) { // for Relay #32, we encode as 0
relay_id = 0;
}
if (relay_id > 15) {
id = (1 << 28);
}
id |= (mac[3] << 20) | (mac[4] << 12) | (mac[5] << 4) | (relay_id & 0xF);
return id; return id;
} }
uint32_t DecodeLightId(uint32_t id) { // get hue_id and decode the relay_id
return id & 0xF; // 4 LSB decode to 1-15, if bit 28 is set, it encodes 16-31, if 0 then 32
uint32_t DecodeLightId(uint32_t hue_id) {
uint8_t relay_id = hue_id & 0xF;
if (hue_id & (1 << 28)) { // check if bit 25 is set, if so we have
relay_id += 16;
}
if (0 == relay_id) { // special value 0 is actually relay #32
relay_id = 32;
}
return relay_id;
} }
static const char * FIRST_GEN_UA[] = { // list of User-Agents signature static const char * FIRST_GEN_UA[] = { // list of User-Agents signature