UPDATE 1.0.0 - Changed:
- Nuimo will now keep scanning after discovering a device. You must manually call stop() to cease.
Node.js v6.0+ required.
npm install nuimojs --save
Nuimo.js uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are certain dependencies which may need installed first.
Note: Nuimo.js has been tested on macOS 10.11 and Debian/Raspbian on the Raspberry Pi 3 Model B. It is also reported to work on Windows 10 (See these notes).
let Nuimo = require("nuimojs"),
nuimo = new Nuimo();
Examples are available in the "examples" directory.
Note: Subclass of EventEmitter.
An optional whitelist of UUID's to discover. Leave undefined to discover all, or specify an array (For multiple devices) or string (For a single device).
Begins scanning for Nuimo devices.
Stops scanning for Nuimo devices.
Returns an array of all the connected devices (Items are instances of Device).
Return the Device matching the requested UUID if it is connected.
Triggered when a new Nuimo device is discovered.
Note: Subclass of EventEmitter.
Device unique identifier.
The current battery level as a percentage between 0-100.
Received Signal Strength Indicator (RSSI) value of the device.
Connects to a previously discovered Nuimo device. The callback is triggered when the device is ready for interacting with.
Outputs a pattern to the 9x9 LED matrix on the front of the device.
Matrix is either:
- An array of 81 items, each representing one of the 81 LED's, starting at the top left. Each item in the array should be either 0 or 1.
- A buffer of 11 bytes, each bit representing one of the 81 LED's, with the last 7 of the 11th byte being unused.
Brightness is a value between 0-255. Timeout is how long the pattern should appear for (In milliseconds).
Two options are currently available (If options is undefined, both are disabled by default):
- options.onionSkinning (boolean) - Allows smoother transitions between matrices.
- options.builtinMatrix (boolean) - Use the inbuilt matrix (Undocumented, subject to change).
Note: Options may also be specified as an integer representing a bitfield, with the following values:
- ONION_SKINNING - 16
- BUILTIN_MATRIX - 32
Examples:
setLEDMatrix(yourmatrix, yourbrightness, yourtimeout); // Default
setLEDMatrix(yourmatrix, yourbrightness, yourtimeout, {
onionSkinning: true,
builtinMatrix: true
}); // Enable onion skinning and inbuilt matrix
setLEDMatrix(yourmatrix, yourbrightness, yourtimeout, 16 + 32); // Using bitfield, enable onion skinning and inbuilt matrix
Triggered when the device is ready for interacting with.
Triggered when the device is disconnected.
Triggered when the battery level drops. (Note: Level is as a percentage between 0-100)
Triggered when the RSSI changes.
The following events are triggered when the device is interacted with:
Triggered when the user presses down on the central button.
Triggered when the user releases the central button.
Triggered when the user swipes in a direction on the central pad. Direction can be one of: Nuimo.Swipe.LEFT, Nuimo.Swipe.RIGHT, Nuimo.Swipe.UP, or Nuimo.Swipe.DOWN.
Individual events are also triggered: "swipeLeft", "swipeRight", "swipeUp", "swipeDown". No direction is passed to the callback for these events.
Triggered when the user touches an area on the central pad. Area can be one of: Nuimo.Area.LEFT, Nuimo.Area.RIGHT, Nuimo.Area.TOP, Nuimo.Area.BOTTOM, Nuimo.Area.LONGLEFT, Nuimo.Area.LONGRIGHT, Nuimo.Area.LONGTOP, or Nuimo.Area.LONGBOTTOM.
Individual events are also triggered: "touchLeft", "touchRight", "touchTop", "touchBottom", "longTouchLeft", "longTouchRight", "longTouchTop", "longTouchBottom". No area is passed to the callback for these events.
Triggered when the user rotates the outer ring. The amount is the amount of degrees the ring was rotated (Negative for counterclockwise).
Triggered when the user waves their hand over the sensor. Direction is either Nuimo.Fly.LEFT or Nuimo.Fly.RIGHT.
Individual events are also triggered: "flyLeft", "flyRight". No direction is passed to the callback for these events.
Note: In earlier Nuimo firmware versions, speed could be 0, 1, or 2. In later versions, speed is always 0.
Note: This was previously named "detect", which is now deprecated.
Triggered when a hand is detected over the sensor. The distance represents how close the hand is to the sensor (Between 0-255, 255 being farthest away).
Note: This event is continuously triggered as long as a hand is detected.