Added support for passing brightness in % to the ReST API
This commit is contained in:
parent
e70018ec9d
commit
0a41a25163
@ -125,12 +125,22 @@ function readModeData(mode, reader)
|
||||
function lsb(value) { return value & 0xFF; }
|
||||
function msb(value) { return (value >> 8) & 0xFF; }
|
||||
|
||||
|
||||
function getBrightness(value)
|
||||
{
|
||||
if (typeof(value) == 'string' && value.substr(-1) === '%')
|
||||
return (Number(value.substr(0, value.length - 1)) * 4096 / 100);
|
||||
|
||||
return Number(value) || 0;
|
||||
}
|
||||
|
||||
|
||||
function writeModeData(mode, data)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case protocol.Mode.Static:
|
||||
if (typeof(data.brightness) == 'undefined') data.brightness = 0;
|
||||
var brightness = getBrightness(data.brightness);
|
||||
|
||||
return new Buffer([protocol.Command.SetMode, mode, lsb(data.brightness), msb(data.brightness)]);
|
||||
|
||||
@ -143,27 +153,27 @@ function writeModeData(mode, data)
|
||||
buffer.writeInt8(mode, 1);
|
||||
|
||||
for (var index = 0; index < valueCount; index++)
|
||||
buffer.writeInt16LE(brightness[index], 2 + (index * 2));
|
||||
buffer.writeInt16LE(getBrightness(brightness[index]), 2 + (index * 2));
|
||||
|
||||
return buffer;
|
||||
|
||||
case protocol.Mode.Alternate:
|
||||
if (typeof(data.brightness) == 'undefined') data.brightness = 0;
|
||||
var brightness = getBrightness(data.brightness);
|
||||
if (typeof(data.interval) == 'undefined') data.interval = 500;
|
||||
|
||||
return new Buffer([protocol.Command.SetMode, mode,
|
||||
lsb(data.interval), msb(data.interval),
|
||||
lsb(data.brightness), msb(data.brightness)]);
|
||||
lsb(brightness), msb(brightness)]);
|
||||
|
||||
case protocol.Mode.Slide:
|
||||
if (typeof(data.brightness) == 'undefined') data.brightness = 0;
|
||||
var brightness = getBrightness(data.brightness);
|
||||
if (typeof(data.interval) == 'undefined') data.interval = 500;
|
||||
if (typeof(data.direction) == 'undefined') data.direction = 0;
|
||||
if (typeof(data.fadeOutTime) == 'undefined') data.fadeOutTime = 0;
|
||||
|
||||
return new Buffer([protocol.Command.SetMode, mode,
|
||||
lsb(data.interval), msb(data.interval),
|
||||
lsb(data.brightness), msb(data.brightness),
|
||||
lsb(brightness), msb(brightness),
|
||||
data.direction,
|
||||
lsb(data.fadeOutTime), msb(data.fadeOutTime)]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user