Merge pull request #14924 from s-hadinger/fix_zigbee_compilation

Fix Zigbee compilation with Hue emulation
This commit is contained in:
s-hadinger 2022-02-20 17:13:16 +01:00 committed by GitHub
commit a5147ae250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -623,11 +623,7 @@ void HueLightStatus2(uint8_t device, String *response)
// it is limited to 32 devices. // it is limited to 32 devices.
// last 24 bits of Mac address + 4 bits of local light + high bit for relays 16-31, relay 32 is mapped to 0 // last 24 bits of Mac address + 4 bits of local light + high bit for relays 16-31, relay 32 is mapped to 0
// Zigbee extension: bit 29 = 1, and last 16 bits = short address of Zigbee device // Zigbee extension: bit 29 = 1, and last 16 bits = short address of Zigbee device
#ifndef USE_ZIGBEE uint32_t EncodeLightIdZigbee(uint8_t relay_id, uint16_t z_shortaddr)
uint32_t EncodeLightId(uint8_t relay_id)
#else
uint32_t EncodeLightId(uint8_t relay_id, uint16_t z_shortaddr = 0)
#endif
{ {
uint8_t mac[6]; uint8_t mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
@ -650,17 +646,17 @@ uint32_t EncodeLightId(uint8_t relay_id, uint16_t z_shortaddr = 0)
return id; return id;
} }
uint32_t EncodeLightId(uint8_t relay_id)
{
return EncodeLightIdZigbee(relay_id, 0);
}
// get hue_id and decode the relay_id // get hue_id and decode the relay_id
// 4 LSB decode to 1-15, if bit 28 is set, it encodes 16-31, if 0 then 32 // 4 LSB decode to 1-15, if bit 28 is set, it encodes 16-31, if 0 then 32
// Zigbee: // Zigbee:
// If the Id encodes a Zigbee device (meaning bit 29 is set) // If the Id encodes a Zigbee device (meaning bit 29 is set)
// it returns 0 and sets the 'shortaddr' to the device short address // it returns 0 and sets the 'shortaddr' to the device short address
#ifndef USE_ZIGBEE uint32_t DecodeLightIdZigbee(uint32_t hue_id, uint16_t * shortaddr)
uint32_t DecodeLightId(uint32_t hue_id)
#else
uint32_t DecodeLightId(uint32_t hue_id, uint16_t * shortaddr = nullptr)
#endif
{ {
uint8_t relay_id = hue_id & 0xF; uint8_t relay_id = hue_id & 0xF;
if (hue_id & (1 << 28)) { // check if bit 25 is set, if so we have if (hue_id & (1 << 28)) { // check if bit 25 is set, if so we have
@ -680,6 +676,11 @@ uint32_t DecodeLightId(uint32_t hue_id, uint16_t * shortaddr = nullptr)
return relay_id; return relay_id;
} }
uint32_t DecodeLightId(uint32_t hue_id)
{
return DecodeLightIdZigbee(hue_id, nullptr);
}
// Check if the Echo device is of 1st generation, which triggers different results // Check if the Echo device is of 1st generation, which triggers different results
inline uint32_t findEchoGeneration(void) { inline uint32_t findEchoGeneration(void) {
// don't try to guess from User-Agent anymore but use SetOption109 // don't try to guess from User-Agent anymore but use SetOption109
@ -971,7 +972,7 @@ void HueLights(String *path_req)
device = DecodeLightId(device_id); device = DecodeLightId(device_id);
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
uint16_t shortaddr; uint16_t shortaddr;
device = DecodeLightId(device_id, &shortaddr); device = DecodeLightIdZigbee(device_id, &shortaddr);
if (shortaddr) { if (shortaddr) {
code = ZigbeeHandleHue(shortaddr, device_id, response); code = ZigbeeHandleHue(shortaddr, device_id, response);
goto exit; goto exit;
@ -1004,7 +1005,7 @@ void HueLights(String *path_req)
device = DecodeLightId(device_id); device = DecodeLightId(device_id);
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
uint16_t shortaddr; uint16_t shortaddr;
device = DecodeLightId(device_id, &shortaddr); device = DecodeLightIdZigbee(device_id, &shortaddr);
if (shortaddr) { if (shortaddr) {
code = ZigbeeHueStatus(&response, shortaddr); code = ZigbeeHueStatus(&response, shortaddr);
goto exit; goto exit;

View File

@ -128,7 +128,7 @@ void ZigbeeCheckHue(String & response, bool * appending) {
// this bulb is advertized // this bulb is advertized
if (*appending) { response += ","; } if (*appending) { response += ","; }
response += "\""; response += "\"";
response += EncodeLightId(0, shortaddr); response += EncodeLightIdZigbee(0, shortaddr);
response += F("\":{\"state\":"); response += F("\":{\"state\":");
HueLightStatus1Zigbee(shortaddr, bulbtype, &response); // TODO HueLightStatus1Zigbee(shortaddr, bulbtype, &response); // TODO
HueLightStatus2Zigbee(shortaddr, &response); HueLightStatus2Zigbee(shortaddr, &response);
@ -145,7 +145,7 @@ void ZigbeeHueGroups(String * lights) {
if (bulbtype >= 0) { if (bulbtype >= 0) {
*lights += ",\""; *lights += ",\"";
*lights += EncodeLightId(0, shortaddr); *lights += EncodeLightIdZigbee(0, shortaddr);
*lights += "\""; *lights += "\"";
} }
} }