misfit-bolt
Advanced tools
Comparing version 0.0.4 to 0.1.0
23
index.js
@@ -52,2 +52,3 @@ 'use strict'; | ||
}); | ||
return this; | ||
} | ||
@@ -66,6 +67,8 @@ | ||
this.light.write(buffer); | ||
return this; | ||
} | ||
setRGBA(red, gree, blue, alpha) { | ||
this.set([red, gree, blue, alpha].join(',')); | ||
setRGBA(rgba) { | ||
// TODO: validate rgba values. | ||
return this.set(rgba.join(',')); | ||
} | ||
@@ -83,2 +86,3 @@ | ||
}); | ||
return this; | ||
} | ||
@@ -103,13 +107,14 @@ | ||
}); | ||
return this; | ||
} | ||
off() { | ||
this.set("CLTMP 3200,0"); | ||
return this.set("CLTMP 3200,0"); | ||
} | ||
on() { | ||
this.set("CLTMP 3200,1"); | ||
return this.set("CLTMP 3200,1"); | ||
} | ||
static discover(done, uuid) { | ||
static discover(done, uuids) { | ||
if (typeof done !== 'function') { | ||
@@ -121,4 +126,8 @@ throw new Error('Bolt.discover : first argument should be a function'); | ||
if (peripheral.advertisement.localName == advertisementName) { | ||
if (uuid !== undefined && peripheral.uuid != uuid) { | ||
return; | ||
if (uuids !== undefined) { | ||
if (!(uuids instanceof Array)) { | ||
throw new Error('Bolt.discover : second optional argument should be an array'); | ||
} else if (uuids.indexOf(peripheral.uuid) == -1) { | ||
return; | ||
} | ||
} | ||
@@ -125,0 +134,0 @@ done(new Bolt(peripheral)); |
{ | ||
"name": "misfit-bolt", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Misfit Bolt Javascript Interface", | ||
@@ -15,3 +15,5 @@ "keywords": [ | ||
"test": "./bin/mocha .", | ||
"patch-release": "npm version patch && npm publish && git push --follow-tags" | ||
"patch-release": "npm version patch && npm publish && git push --follow-tags", | ||
"minor-release": "npm version minor && npm publish && git push --follow-tags", | ||
"major-release": "npm version major && npm publish && git push --follow-tags" | ||
}, | ||
@@ -18,0 +20,0 @@ "main": "index.js", |
174
README.md
# Misfit Bolt Javascript Interface | ||
Thin wrapper on the top of [sandeepmistry/noble](https://github.com/sandeepmistry/noble), that discovers Misfit Bolt bulbs, and allows turning them on/off and changing their color, as well as reading their currently set color. | ||
Thin wrapper around [sandeepmistry/noble](https://github.com/sandeepmistry/noble), that helps Misfit Bolt bulbs discovery, and allows turning them on/off and changing their color and brightness, as well as reading their currently set values. | ||
@@ -19,20 +19,79 @@ | ||
## API | ||
## API Methods | ||
### Discover | ||
### discover | ||
**Type** static | ||
**Arguments** | ||
1. callback (*function*): function to be invoked once a Bolt is discovered. Takes a `Bolt` instance as first argument. | ||
2. uuids (*Array*, optional): list of Bolt uuid to discover. | ||
**Returns** | ||
`undefined` | ||
**Example** | ||
```javascript | ||
Bolt.discover(callback(bolt), [uuid]); | ||
Bolt.discover(function(bolt) { | ||
// do something with bolt instance | ||
}, ['29852E52-67A0-490A-BC55-7FAB809AD0C0']); | ||
``` | ||
### Connect | ||
### connect | ||
**Type** instance | ||
**Arguments** | ||
1. callback (*function*): gets called when connection is complete. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
bolt.connect(callback); | ||
bolt.connect(function() { | ||
// do something with bolt instance | ||
}); | ||
``` | ||
### Disconnect | ||
### disconnect | ||
**Type** instance | ||
**Arguments** | ||
1. callback (*function*, optional): gets called when disconnection is complete. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
bolt.connect([callback]); | ||
bolt.disconnect(); | ||
``` | ||
### On | ||
### on | ||
**Type** instance | ||
**Arguments** | ||
none | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
@@ -42,3 +101,17 @@ bolt.on(); | ||
### Off | ||
### off | ||
**Type** instance | ||
**Arguments** | ||
none | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
@@ -48,3 +121,17 @@ bolt.off(); | ||
### Set | ||
### set | ||
**Type** instance | ||
**Arguments** | ||
1. value (*String*): value to set on bulb. Mostly in the form or RGBA. Accepts "CLTMP 3200,0" or "CLTMP 3200,1" (used for toggle on / off). Other undocumented formats might exist. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
@@ -54,22 +141,72 @@ bolt.set("228,41,15,10"); | ||
### SetRGBA | ||
### setRGBA | ||
**Type** instance | ||
**Arguments** | ||
1. value (*Array*): value to set on bulb. Although not enforced yet, should be in the form of `[red, gree, blue, alpha]`. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
bolt.setRGBA(228,41,15,10); | ||
bolt.setRGBA([228,41,15,10]); | ||
``` | ||
### Get | ||
### get | ||
**Type** instance | ||
**Arguments** | ||
1. callback (*function*): function invoked when value is available. Return value of `String` type. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
bolt.get(callback(currentValue)); | ||
bolt.get(function(value) { | ||
// do something with value | ||
}); | ||
``` | ||
### GetRGBA | ||
### getRGBA | ||
**Type** instance | ||
**Arguments** | ||
1. callback (*function*): function invoked when value is available. Return value of `Array` type. | ||
**Returns** | ||
instance | ||
**Example** | ||
```javascript | ||
bolt.get(callback(currentRGBAValue)); | ||
bolt.get(function(rgbaValue) { | ||
// do something with rgbaValue | ||
}); | ||
``` | ||
## Example | ||
## Usage | ||
```javascript | ||
// Discover every nearby Bolt | ||
Bolt.discover(function(bolt) { | ||
// Each time a bolt is discovered, connect to it | ||
bolt.connect(function() { | ||
@@ -83,2 +220,3 @@ var i = 0, | ||
// Change color every 500 ms | ||
setInterval(function(){ | ||
@@ -85,0 +223,0 @@ var color = colors[i++ % colors.length]; |
Sorry, the diff of this file is not supported yet
15817
343
232