-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
280 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const {validate} = require('../../lifx'); | ||
|
||
const Packet = { | ||
size: 1 + 1 + 1 + 1 + 1 + 1 | ||
}; | ||
|
||
/** | ||
* Converts the given packet specific object into a packet | ||
* @param {Object} obj object with configuration data | ||
* @param {Number} obj.tileIndex an 8bit value | ||
* @param {Number} obj.length an 8bit value | ||
* @param {Number} obj.reserved an 8bit value | ||
* @param {Number} obj.x an 8bit value | ||
* @param {Number} obj.y an 8bit value | ||
* @param {Number} obj.width an 8bit value | ||
* @return {Buffer} packet | ||
*/ | ||
Packet.toBuffer = function(obj) { | ||
const buf = Buffer.alloc(this.size); | ||
buf.fill(0); | ||
let offset = 0; | ||
|
||
['tileIndex', 'length', 'reserved', 'x', 'y', 'width'].forEach((field) => { | ||
validate.isUInt8(obj[field], `getTileState64:${field}`); | ||
}); | ||
buf.writeUInt8(obj.tileIndex, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.length, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.reserved, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.x, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.y, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.width, offset); | ||
offset += 1; | ||
|
||
return buf; | ||
}; | ||
|
||
module.exports = Packet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
|
||
const {validate} = require('../../lifx'); | ||
|
||
const Packet = { | ||
size: (obj) => 1 + 1 + 1 + 1 + 1 + 1 + 4 + | ||
(obj.colors.length * (2 + 2 + 2 + 2)), | ||
HSBK: { | ||
toBuffer: (obj, buf, offset) => { | ||
validate.isUInt16(obj.hue, 'setTileState64:HSBK:hue'); | ||
buf.writeUInt16LE(obj.hue, offset); | ||
offset += 2; | ||
|
||
validate.isUInt16(obj.saturation, 'setTileState64:HSBK:saturation'); | ||
buf.writeUInt16LE(obj.saturation, offset); | ||
offset += 2; | ||
|
||
validate.isUInt16(obj.brightness, 'setTileState64:HSBK:brightness'); | ||
buf.writeUInt16LE(obj.brightness, offset); | ||
offset += 2; | ||
|
||
validate.isUInt16(obj.kelvin, 'setTileState64:HSBK:kelvin'); | ||
buf.writeUInt16LE(obj.kelvin, offset); | ||
offset += 2; | ||
|
||
return offset; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Converts the given packet specific object into a packet | ||
* @param {Object} obj object with configuration data | ||
* @param {Number} obj.tileIndex 8bit value | ||
* @param {Number} obj.length 8bit value | ||
* @param {Number} obj.reserved 8bit value | ||
* @param {Number} obj.x 8bit value | ||
* @param {Number} obj.y 8bit value | ||
* @param {Number} obj.width 8bit value | ||
* @param {Number} obj.duration 8bit value | ||
* @param {Number} [obj.duration] transition time in milliseconds | ||
* @param {Array} obj.colors an array of HSBK values | ||
* @return {Buffer} packet | ||
*/ | ||
Packet.toBuffer = function(obj) { | ||
const buf = Buffer.alloc(Packet.size(obj)); | ||
buf.fill(0); | ||
let offset = 0; | ||
|
||
['tileIndex', 'length', 'reserved', 'x', 'y', 'width'].forEach((field) => { | ||
validate.isUInt8(obj[field], `setTileState64:${field}`); | ||
}); | ||
// obj.stream field has unknown function so leave it as 0 | ||
buf.writeUInt8(obj.tileIndex, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.length, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.reserved || 0, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.x, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.y, offset); | ||
offset += 1; | ||
buf.writeUInt8(obj.width, offset); | ||
offset += 1; | ||
validate.isUInt32(obj.duration, 'setTileState64:duration'); | ||
buf.writeUInt32LE(obj.duration, offset); | ||
offset += 4; | ||
obj.colors.forEach((color) => { | ||
offset = Packet.HSBK.toBuffer(color, buf, offset); | ||
}); | ||
return buf; | ||
}; | ||
|
||
module.exports = Packet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
const Packet = { | ||
size: | ||
1 + | ||
16 * (2 + 2 + 2 + 2 + 4 + 4 + 1 + 1 + 1 + 4 + 4 + 4 + 8 + 8 + 2 + 2 + 4) + | ||
1, | ||
Tile: { | ||
toObject: function(buf, offset) { | ||
const tile = {}; | ||
tile.accelMeasX = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.accelMeasY = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.accelMeasZ = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.reserved0 = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.userX = buf.readUInt32LE(offset); | ||
offset += 4; | ||
tile.userY = buf.readUInt32LE(offset); | ||
offset += 4; | ||
tile.width = buf.readUInt8(offset); | ||
offset += 1; | ||
tile.height = buf.readUInt8(offset); | ||
offset += 1; | ||
tile.reserved1 = buf.readUInt8(offset); | ||
offset += 1; | ||
tile.deviceVersionVendor = buf.readUInt32LE(offset); | ||
offset += 4; | ||
tile.deviceVersionProduct = buf.readUInt32LE(offset); | ||
offset += 4; | ||
tile.deviceVersionVersion = buf.readUInt32LE(offset); | ||
offset += 4; | ||
tile.firmwareBuild = { | ||
low: buf.readUInt32LE(offset), | ||
high: buf.readUInt32LE(offset + 4) | ||
}; | ||
offset += 8; | ||
tile.reserved2 = { | ||
low: buf.readUInt32LE(offset), | ||
high: buf.readUInt32LE(offset + 4) | ||
}; | ||
offset += 8; | ||
tile.firmwareVersionMinor = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.firmwareVersionMajor = buf.readUInt16LE(offset); | ||
offset += 2; | ||
tile.reserved3 = buf.readUInt32LE(offset); | ||
offset += 4; | ||
return {offset, tile}; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Converts packet specific data from a buffer to an object | ||
* @param {Buffer} buf Buffer containing only packet specific data no header | ||
* @return {Object} Information contained in packet | ||
*/ | ||
Packet.toObject = function(buf) { | ||
if (buf.length !== this.size) { | ||
throw new Error(`Invalid length given for stateDeviceChain LIFX packet:${buf.length}:${this.size}`); | ||
} | ||
let offset = 0; | ||
const obj = {}; | ||
obj.startIndex = buf.readUInt8(offset); | ||
offset += 1; | ||
obj.tileDevices = new Array(16).fill(undefined).map(() => { | ||
const ret = Packet.Tile.toObject(buf, offset); | ||
offset = ret.offset; | ||
return ret.tile; | ||
}); | ||
obj.totalCount = buf.readUInt8(offset); | ||
offset += 1; | ||
return obj; | ||
}; | ||
|
||
module.exports = Packet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.