Skip to content

Commit

Permalink
Merge pull request #99 from sidoh/1.4.1
Browse files Browse the repository at this point in the history
1.4.1
  • Loading branch information
sidoh authored Jul 15, 2017
2 parents 5832c6a + 9869fcc commit cc0b0ea
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/MiLight/CctPacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ void CctPacketFormatter::parsePacket(const uint8_t* packet, JsonObject& result)
uint8_t onOffGroupId = cctCommandIdToGroup(command);
if (onOffGroupId < 255) {
result["state"] = cctCommandToStatus(command) == ON ? "ON" : "OFF";
} else if (command == CCT_BRIGHTNESS_DOWN) {
result["command"] = "brightness_down";
} else if (command == CCT_BRIGHTNESS_UP) {
result["command"] = "brightness_up";
} else if (command == CCT_TEMPERATURE_DOWN) {
result["command"] = "temperature_down";
} else if (command == CCT_TEMPERATURE_UP) {
result["command"] = "temperature_up";
} else {
result["button_id"] = command;
}

if (! result.containsKey("state")) {
Expand Down
12 changes: 10 additions & 2 deletions lib/MiLight/RgbCctPacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ void RgbCctPacketFormatter::parsePacket(const uint8_t *packet, JsonObject& resul
uint8_t arg = packetCopy[RGB_CCT_ARGUMENT_INDEX];

if (command == RGB_CCT_ON) {
// Group is not reliably encoded in group byte. Extract from arg byte
if (arg < 5) {
if (arg == RGB_CCT_MODE_SPEED_DOWN) {
result["command"] = "mode_speed_down";
} else if (arg == RGB_CCT_MODE_SPEED_UP) {
result["command"] = "mode_speed_up";
} else if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte
result["state"] = "ON";
result["group_id"] = arg;
} else {
Expand Down Expand Up @@ -158,6 +161,11 @@ void RgbCctPacketFormatter::parsePacket(const uint8_t *packet, JsonObject& resul
result["brightness"] = Units::rescale<uint8_t, uint8_t>(level, 255, 100);
} else if (command == RGB_CCT_SATURATION) {
result["saturation"] = constrain(arg - RGB_CCT_SATURATION_OFFSET, 0, 100);
} else if (command == RGB_CCT_MODE) {
result["mode"] = arg;
} else {
result["button_id"] = command;
result["argument"] = arg;
}

if (! result.containsKey("state")) {
Expand Down
10 changes: 10 additions & 0 deletions lib/MiLight/RgbPacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ void RgbPacketFormatter::parsePacket(const uint8_t* packet, JsonObject& result)
uint16_t remappedColor = Units::rescale<uint16_t, uint16_t>(packet[RGB_COLOR_INDEX], 360.0, 255.0);
remappedColor = (remappedColor + 320) % 360;
result["hue"] = remappedColor;
} else if (command == RGB_MODE_DOWN) {
result["command"] = "previous_mode";
} else if (command == RGB_MODE_UP) {
result["command"] = "next_mode";
} else if (command == RGB_SPEED_DOWN) {
result["command"] = "mode_speed_down";
} else if (command == RGB_SPEED_UP) {
result["command"] = "mode_speed_up";
} else {
result["button_id"] = command;
}

if (! result.containsKey("state")) {
Expand Down
13 changes: 13 additions & 0 deletions lib/MiLight/RgbwPacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -111,6 +116,14 @@ void RgbwPacketFormatter::parsePacket(const uint8_t* packet, JsonObject& result)
uint16_t remappedColor = Units::rescale<uint16_t, uint16_t>(packet[RGBW_COLOR_INDEX], 360.0, 255.0);
remappedColor = (remappedColor + 320) % 360;
result["hue"] = remappedColor;
} else if (command == RGBW_SPEED_DOWN) {
result["command"] = "mode_speed_down";
} else if (command == RGBW_SPEED_UP) {
result["command"] = "mode_speed_up";
} else if (command == RGBW_DISCO_MODE) {
result["mode"] = packet[0] & ~RGBW;
} else {
result["button_id"] = command;
}

if (! result.containsKey("state")) {
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lib_deps_external =
ArduinoJson
PubSubClient
https://github.com/ratkins/RGBConverter
build_flags = !python .get_version.py
build_flags = !python .get_version.py -DMQTT_MAX_PACKET_SIZE=200
# -D MQTT_DEBUG
# -D MILIGHT_UDP_DEBUG
# -D DEBUG_PRINTF
Expand Down

0 comments on commit cc0b0ea

Please sign in to comment.