Преглед на файлове

RGBW: determine group from button ID for on/off commands

Chris Mullins преди 8 години
родител
ревизия
3ba3a24226
променени са 1 файла, в които са добавени 5 реда и са изтрити 0 реда
  1. 5 0
      lib/MiLight/RgbwPacketFormatter.cpp

+ 5 - 0
lib/MiLight/RgbwPacketFormatter.cpp

@@ -3,6 +3,7 @@
 #include <Units.h>
 
 #define STATUS_COMMAND(status, groupId) ( RGBW_GROUP_1_ON + ((groupId - 1)*2) + status )
+#define GROUP_FOR_STATUS_COMMAND(buttonId) ( (buttonId - 1) / 2 )
 
 void RgbwPacketFormatter::initializePacket(uint8_t* packet) {
   size_t packetPtr = 0;
@@ -101,6 +102,10 @@ void RgbwPacketFormatter::parsePacket(const uint8_t* packet, JsonObject& result)
 
   if (command >= RGBW_ALL_ON && command <= RGBW_GROUP_4_OFF) {
     result["state"] = (command % 2) ? "ON" : "OFF";
+    // Determine group ID from button ID for on/off. The remote's state is from
+    // the last packet sent, not the current one, and that can be wrong for
+    // on/off commands.
+    result["group_id"] = GROUP_FOR_STATUS_COMMAND(command);
   } else if (command == RGBW_BRIGHTNESS) {
     uint8_t brightness = 31;
     brightness -= packet[RGBW_BRIGHTNESS_GROUP_INDEX] >> 3;