|
@@ -52,7 +52,44 @@ void FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject& resul
|
|
|
|
|
|
|
|
result["device_id"] = (packetCopy[2] << 8) | packetCopy[3];
|
|
result["device_id"] = (packetCopy[2] << 8) | packetCopy[3];
|
|
|
result["group_id"] = packetCopy[7];
|
|
result["group_id"] = packetCopy[7];
|
|
|
- result["device_type"] = "rgb_cct";
|
|
|
|
|
|
|
+ result["device_type"] = "fut089";
|
|
|
|
|
+
|
|
|
|
|
+ uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F);
|
|
|
|
|
+ uint8_t arg = packetCopy[V2_ARGUMENT_INDEX];
|
|
|
|
|
+
|
|
|
|
|
+ if (command == FUT089_ON) {
|
|
|
|
|
+ if (arg == FUT089_MODE_SPEED_DOWN) {
|
|
|
|
|
+ result["command"] = "mode_speed_down";
|
|
|
|
|
+ } else if (arg == FUT089_MODE_SPEED_UP) {
|
|
|
|
|
+ result["command"] = "mode_speed_up";
|
|
|
|
|
+ } else if (arg == FUT089_WHITE_MODE) {
|
|
|
|
|
+ result["command"] = "white_mode";
|
|
|
|
|
+ } else if (arg <= 8) { // Group is not reliably encoded in group byte. Extract from arg byte
|
|
|
|
|
+ result["state"] = "ON";
|
|
|
|
|
+ result["group_id"] = arg;
|
|
|
|
|
+ } else if (arg >= 9 && arg <= 17) {
|
|
|
|
|
+ result["state"] = "OFF";
|
|
|
|
|
+ result["group_id"] = arg-9;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (command == FUT089_COLOR) {
|
|
|
|
|
+ uint8_t rescaledColor = (arg - FUT089_COLOR_OFFSET) % 0x100;
|
|
|
|
|
+ uint16_t hue = Units::rescale<uint16_t, uint16_t>(rescaledColor, 360, 255.0);
|
|
|
|
|
+ result["hue"] = hue;
|
|
|
|
|
+ } else if (command == FUT089_KELVIN) {
|
|
|
|
|
+ result["color_temp"] = Units::whiteValToMireds(arg, 100);
|
|
|
|
|
+ } else if (command == FUT089_BRIGHTNESS) {
|
|
|
|
|
+ uint8_t level = constrain(arg, 0, 100);
|
|
|
|
|
+ result["brightness"] = Units::rescale<uint8_t, uint8_t>(level, 255, 100);
|
|
|
|
|
+ // saturation == kelvin. arg ranges are the same, so won't be able to parse
|
|
|
|
|
+ // both unless state is persisted
|
|
|
|
|
+ } else if (command == FUT089_SATURATION) {
|
|
|
|
|
+ result["saturation"] = constrain(arg, 0, 100);
|
|
|
|
|
+ } else if (command == FUT089_MODE) {
|
|
|
|
|
+ result["mode"] = arg;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result["button_id"] = command;
|
|
|
|
|
+ result["argument"] = arg;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (! result.containsKey("state")) {
|
|
if (! result.containsKey("state")) {
|
|
|
result["state"] = "ON";
|
|
result["state"] = "ON";
|