Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiZoneSetEffect #27

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ $ npm install node-lifx-lan
* [lightSetInfrared() method](#LifxLanDevice-lightSetInfrared-method)
* [multiZoneSetColorZones() method](#LifxLanDevice-multiZoneSetColorZones-method)
* [multiZoneGetColorZones() method](#LifxLanDevice-multiZoneGetColorZones-method)
* [multiZoneSetEffect() method](#LifxLanDevice-multiZoneSetEffect-method)
* [tileGetDeviceChain() method](#LifxLanDevice-tileGetDeviceChain-method)
* [tileSetUserPosition() method](#LifxLanDevice-tileSetUserPosition-method)
* [tileGetTileState64() method](#LifxLanDevice-tileGetTileState64-method)
Expand Down Expand Up @@ -1780,6 +1781,35 @@ The code above will output the result as follows:
}
```

### <a id="LifxLanDevice-multiZoneSetEffect-method">multiZoneSetEffect(*params*) method</a>

The `multiZoneSetEffect()` method sets the firmware effect to display on a multizone device [[SetMultiZoneEffect - 508](https://lan.developer.lifx.com/docs/firmware-effects#section-setmultizoneeffect-508)]. This method returns a `Promise` object.

This method takes a hash object as an argument containing properties as follows:

Property | Type | Requred | Description
:-----------|:--------|:---------|:-----------
`type` | Integer | Required | `0`: OFF, `1`: MOVE
`speed` | Integer | Required | Time in milliseconds for a complete animation cycle to occur
`duration` | Integer | Optional | Duration of effect in milliseconds. The default value is `0` a.k.a. infinite
`direction` | Integer | Optional | `0`: TOWARDS, `1`: AWAY

```JavaScript
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.multiZoneSetEffect({
type : 1,
speed : 1000,
duration : 0,
direction : 1
});
}).then((res) => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
```

### <a id="LifxLanDevice-tileGetDeviceChain-method">tileGetDeviceChain() method</a>

The `tileGetDeviceChain()` method returns information about the tiles in the chain [[GetDeviceChain - 701](https://lan.developer.lifx.com/docs/tile-messages#section-getdevicechain-701)]. This method returns a `Promise` object.
Expand Down Expand Up @@ -2130,6 +2160,8 @@ Note that the actual number of elements in the `tiles` array equals however many
---------------------------------------
## <a id="Release-Note">Release Note</a>

* v0.4.1 (2020-04-24)
* Added support for [multizone effects](https://lan.developer.lifx.com/docs/firmware-effects) (thanks to [@paddy2k])
* v0.4.0 (2019-10-08)
* Supported the [tile messages](https://lan.developer.lifx.com/docs/tile-messages) (thanks to [@furey](https://github.com/futomi/node-lifx-lan/pull/19))
* v0.3.1 (2018-09-17)
Expand Down
61 changes: 61 additions & 0 deletions lib/lifx-lan-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ LifxLanComposer.prototype._composePayload = function(type, payload) {
return this._composePayload501(payload);
} else if(type === 502) { // multiZoneGetColorZones
return this._composePayload502(payload);
} else if(type === 508) { // setMultiZoneEffect
return this._composePayload508(payload);
} else if(type === 703) { // tileSetUserPosition
return this._composePayload703(payload);
} else if(type === 707) { // tileGetTitleState64
Expand Down Expand Up @@ -952,4 +954,63 @@ LifxLanComposer.prototype._composePayload715 = function(payload) {
return {buffer: buf};
};

/* ------------------------------------------------------------------
* Method: _composePayload508(payload) : SetMultiZoneEffect
* - payload:
* - type | Integer | Required | 0 or 1
* - speed | Integer | Required | Speed in milliseconds
* - duration | Integer | Optional | Duration in milliseconds (default: 0 - infinite)
* - direction | Integer | Optional | (default: 0)
* ---------------------------------------------------------------- */
//
LifxLanComposer.prototype._composePayload508 = function(payload) {
const instance_id = mCrypto.randomBytes(4).readUInt32LE(0, true);

// Check the parameter `type`
let type = payload['type'];
if(typeof(type) !== 'number' || type % 1 !== 0) {
return {error: new Error('The value of the `type` must be an integer.')};
} else if(!(type === 0 || type === 1)) {
return {error: new Error('The value of the `type` must be 0 or 1.')};
}

// Check the `speed`
let speed = 0;
if('speed' in payload) {
speed = payload['speed'];
if(typeof(speed) !== 'number' || speed % 1 !== 0 || speed < 0 || speed > 65535) {
return {error: new Error('The `speed` must be an integer between 0 and 65535.')};
}
}

// Check the `duration`
let duration = 0;
if('duration' in payload) {
duration = payload['duration'] * 1000000; // convert from miliseconds to nanoseconds
if(typeof(duration) !== 'number' || duration % 1 !== 0 || duration < 0 || duration > Math.pow(2, 64)) {
return {error: new Error('The `duration` must be an integer between 0 and 2^64.')};
}
}

// Check the parameter `direction`
let direction = 0;
if('direction' in payload) {
direction = payload['direction'];
if(typeof(direction) !== 'number' || direction % 1 !== 0) {
return {error: new Error('The value of the `direction` must be an integer.')};
} else if(!(direction === 0 || direction === 1)) {
return {error: new Error('The value of the `direction` must be 0 or 1.')};
}
}

// Compose a payload
let buf = Buffer.alloc(63);
buf.writeUInt32LE(instance_id, 0);
buf.writeUInt8(type, 4);
buf.writeUInt32LE(speed, 7);
buf.writeBigInt64LE(BigInt(duration), 11);
buf.writeUInt32LE(direction, 31);
return {buffer: buf};
}

module.exports = new LifxLanComposer();
15 changes: 15 additions & 0 deletions lib/lifx-lan-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,21 @@ LifxLanDevice.prototype.lightSetInfrared = function (params) {
return this._request(122, params);
};


/* ------------------------------------------------------------------
* Method: multiZoneSetEffect(params)
* - params:
* - brightness | Float | Required | 0.0 - 1.0
* - type | Integer | Required | OFF or MOVE
* - speed | Integer | Required | Speed in milliseconds
* - duration | Integer | Optional | Duration in milliseconds (default: 0 - infinite)
* - direction | Integer | Optional | TOWARDS or AWAY (default: TOWARDS)
* ---------------------------------------------------------------- */
LifxLanDevice.prototype.multiZoneSetEffect = function (params) {
return this._request(508, params);
};


/* ------------------------------------------------------------------
* Method: multiZoneSetColorZones(params)
* - params:
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-lifx-lan",
"version": "0.4.0",
"version": "0.4.1",
"description": "The node-lifx-lan is a Node.js module which allows you to communicate with the Wi-Fi LED smart light products \"LIFX\" using the LAN protocol.",
"main": "./lib/lifx-lan.js",
"files": [
Expand All @@ -27,6 +27,5 @@
"url": "https://github.com/futomi/node-lifx-lan.git"
},
"readmeFilename": "README.md",
"dependencies": {
}
"dependencies": {}
}