|
@@ -1,5 +1,6 @@
|
|
|
#include <RgbwPacketFormatter.h>
|
|
#include <RgbwPacketFormatter.h>
|
|
|
#include <MiLightButtons.h>
|
|
#include <MiLightButtons.h>
|
|
|
|
|
+#include <Units.h>
|
|
|
|
|
|
|
|
#define STATUS_COMMAND(status, groupId) ( RGBW_GROUP_1_ON + ((groupId - 1)*2) + status )
|
|
#define STATUS_COMMAND(status, groupId) ( RGBW_GROUP_1_ON + ((groupId - 1)*2) + status )
|
|
|
|
|
|
|
@@ -49,7 +50,7 @@ void RgbwPacketFormatter::updateStatus(MiLightStatus status, uint8_t groupId) {
|
|
|
|
|
|
|
|
void RgbwPacketFormatter::updateBrightness(uint8_t value) {
|
|
void RgbwPacketFormatter::updateBrightness(uint8_t value) {
|
|
|
// Expect an input value in [0, 100]. Map it down to [0, 25].
|
|
// Expect an input value in [0, 100]. Map it down to [0, 25].
|
|
|
- const uint8_t adjustedBrightness = rescale(value, 25, 100);
|
|
|
|
|
|
|
+ const uint8_t adjustedBrightness = Units::rescale(value, 25, 100);
|
|
|
|
|
|
|
|
// The actual protocol uses a bizarre range where min is 16, max is 23:
|
|
// The actual protocol uses a bizarre range where min is 16, max is 23:
|
|
|
// [16, 15, ..., 0, 31, ..., 23]
|
|
// [16, 15, ..., 0, 31, ..., 23]
|
|
@@ -71,7 +72,7 @@ void RgbwPacketFormatter::command(uint8_t command, uint8_t arg) {
|
|
|
|
|
|
|
|
void RgbwPacketFormatter::updateHue(uint16_t value) {
|
|
void RgbwPacketFormatter::updateHue(uint16_t value) {
|
|
|
const int16_t remappedColor = (value + 40) % 360;
|
|
const int16_t remappedColor = (value + 40) % 360;
|
|
|
- updateColorRaw(rescale(remappedColor, 255, 360));
|
|
|
|
|
|
|
+ updateColorRaw(Units::rescale(remappedColor, 255, 360));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void RgbwPacketFormatter::updateColorRaw(uint8_t value) {
|
|
void RgbwPacketFormatter::updateColorRaw(uint8_t value) {
|
|
@@ -105,12 +106,16 @@ void RgbwPacketFormatter::parsePacket(const uint8_t* packet, JsonObject& result)
|
|
|
brightness -= packet[RGBW_BRIGHTNESS_GROUP_INDEX] >> 3;
|
|
brightness -= packet[RGBW_BRIGHTNESS_GROUP_INDEX] >> 3;
|
|
|
brightness += 17;
|
|
brightness += 17;
|
|
|
brightness %= 32;
|
|
brightness %= 32;
|
|
|
- result["level"] = rescale<uint8_t, uint8_t>(brightness, 100, 25);
|
|
|
|
|
|
|
+ result["level"] = Units::rescale<uint8_t, uint8_t>(brightness, 100, 25);
|
|
|
} else if (command == RGBW_COLOR) {
|
|
} else if (command == RGBW_COLOR) {
|
|
|
- uint16_t remappedColor = rescale<uint16_t, uint16_t>(packet[RGBW_COLOR_INDEX], 360.0, 255.0);
|
|
|
|
|
|
|
+ uint16_t remappedColor = Units::rescale<uint16_t, uint16_t>(packet[RGBW_COLOR_INDEX], 360.0, 255.0);
|
|
|
remappedColor = (remappedColor + 320) % 360;
|
|
remappedColor = (remappedColor + 320) % 360;
|
|
|
result["hue"] = remappedColor;
|
|
result["hue"] = remappedColor;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (! result.containsKey("state")) {
|
|
|
|
|
+ result["state"] = "ON";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void RgbwPacketFormatter::format(uint8_t const* packet, char* buffer) {
|
|
void RgbwPacketFormatter::format(uint8_t const* packet, char* buffer) {
|