Skip to content

Commit b8bc2dc

Browse files
committed
added invertValue parameter to full color saturation command. This may be set to true to get a proper percentage saturation. Note, the native Milight saturation value is inverted, where 0 is maximum saturation.
fixed full color rgb command which did not provide the proper hue for red (#ff0000).
1 parent 9f4decd commit b8bc2dc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/commandsV6.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,13 @@ RgbFullColorCommand.prototype.brightness = function(zone, percent){
212212
return [0x31, 0x00, 0x00, 0x08, 0x03, bn, 0x00, 0x00, 0x00, zn]
213213
};
214214

215-
RgbFullColorCommand.prototype.saturation = function(zone, percent){
216-
var sn = Math.min(Math.max(percent, 0x00), 0x64);
215+
// if invertValue is not set, 0 is max imum saturation!
216+
RgbFullColorCommand.prototype.saturation = function(zone, saturationValue, invertValue){
217+
var sn = Math.min(Math.max(saturationValue, 0x00), 0x64);
217218
var zn = Math.min(Math.max(zone, 0x00), 0x04);
219+
if (invertValue) {
220+
sn = 0x64 - sn;
221+
}
218222
return [0x31, 0x00, 0x00, 0x08, 0x02, sn, 0x00, 0x00, 0x00, zn]
219223
};
220224

@@ -233,10 +237,11 @@ RgbFullColorCommand.prototype.hue = function(zone, hue, enableLegacyColorWheel){
233237

234238
RgbFullColorCommand.prototype.rgb = function(zone, r, g, b) {
235239
var hsv=helper.rgbToHsv(r, g, b);
236-
var hue = hsv[0] * 0xFF % 0x167;
240+
var hue = (hsv[0] == 0)?0xB0:hsv[0] * 0xFF % 0x167;
237241
return [
238242
this.hue(zone, hue),
239-
this.saturation(zone, hsv[1])
243+
this.saturation(zone, hsv[1], true),
244+
this.brightness(zone, hsv[2])
240245
]
241246
};
242247

0 commit comments

Comments
 (0)