diff --git a/lib/MiLight/FUT089PacketFormatter.cpp b/lib/MiLight/FUT089PacketFormatter.cpp index c9fecc6a..c28921d2 100644 --- a/lib/MiLight/FUT089PacketFormatter.cpp +++ b/lib/MiLight/FUT089PacketFormatter.cpp @@ -111,22 +111,30 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F); uint8_t arg = packetCopy[V2_ARGUMENT_INDEX]; + bool long_press = (packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80; if (command == FUT089_ON) { - if ((packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80) { - result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE; - } else if (arg == FUT089_MODE_SPEED_DOWN) { + if (arg == FUT089_MODE_SPEED_DOWN) { result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::MODE_SPEED_DOWN; + result[GroupStateFieldNames::LONG_PRESS] = long_press; } else if (arg == FUT089_MODE_SPEED_UP) { result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::MODE_SPEED_UP; + result[GroupStateFieldNames::LONG_PRESS] = long_press; } else if (arg == FUT089_WHITE_MODE) { result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::SET_WHITE; + result[GroupStateFieldNames::LONG_PRESS] = long_press; } else if (arg <= 8) { // Group is not reliably encoded in group byte. Extract from arg byte result[GroupStateFieldNames::STATE] = "ON"; bulbId.groupId = arg; + result[GroupStateFieldNames::LONG_PRESS] = long_press; } else if (arg >= 9 && arg <= 17) { result[GroupStateFieldNames::STATE] = "OFF"; bulbId.groupId = arg-9; + result[GroupStateFieldNames::LONG_PRESS] = long_press; + if (long_press) { + result[GroupStateFieldNames::STATE] = "ON"; + result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE; + } } } else if (command == FUT089_COLOR) { uint8_t rescaledColor = (arg - FUT089_COLOR_OFFSET) % 0x100; @@ -147,6 +155,7 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu } } else if (command == FUT089_MODE) { result[GroupStateFieldNames::MODE] = arg; + result[GroupStateFieldNames::LONG_PRESS] = long_press; } else { result["button_id"] = command; result["argument"] = arg; diff --git a/lib/MiLight/FUT091PacketFormatter.cpp b/lib/MiLight/FUT091PacketFormatter.cpp index 816e3776..f06b0207 100644 --- a/lib/MiLight/FUT091PacketFormatter.cpp +++ b/lib/MiLight/FUT091PacketFormatter.cpp @@ -32,16 +32,21 @@ BulbId FUT091PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F); uint8_t arg = packetCopy[V2_ARGUMENT_INDEX]; + bool long_press = (packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80; if (command == (uint8_t)FUT091Command::ON_OFF) { - if ((packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80) { - result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE; - } else if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte + if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte result[GroupStateFieldNames::STATE] = "ON"; + result[GroupStateFieldNames::LONG_PRESS] = long_press; bulbId.groupId = arg; } else { result[GroupStateFieldNames::STATE] = "OFF"; bulbId.groupId = arg-5; + result[GroupStateFieldNames::LONG_PRESS] = long_press; + if (long_press) { + result[GroupStateFieldNames::STATE] = "ON"; + result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE; + } } } else if (command == (uint8_t)FUT091Command::BRIGHTNESS) { uint8_t level = V2PacketFormatter::fromv2scale(arg, BRIGHTNESS_SCALE_MAX, 2, true); diff --git a/lib/Types/GroupStateField.h b/lib/Types/GroupStateField.h index e58dc2dc..3da86923 100644 --- a/lib/Types/GroupStateField.h +++ b/lib/Types/GroupStateField.h @@ -24,6 +24,7 @@ namespace GroupStateFieldNames { static const char HEX_COLOR[] = "hex_color"; static const char COMMAND[] = "command"; static const char COMMANDS[] = "commands"; + static const char LONG_PRESS[] = "long_press"; }; enum class GroupStateField { @@ -45,7 +46,8 @@ enum class GroupStateField { GROUP_ID, DEVICE_TYPE, OH_COLOR, - HEX_COLOR + HEX_COLOR, + LONG_PRESS }; class GroupStateFieldHelpers {