https://github.com/ros2jsguy/node-blink1-async
Asynchronous TypeScript api for controlling blink(1) USB LED devices. Based on the node-blink1 package.
https://github.com/ros2jsguy/node-blink1-async
Last synced: over 1 year ago
JSON representation
Asynchronous TypeScript api for controlling blink(1) USB LED devices. Based on the node-blink1 package.
- Host: GitHub
- URL: https://github.com/ros2jsguy/node-blink1-async
- Owner: ros2jsguy
- License: mit
- Created: 2021-06-08T04:15:21.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-30T04:40:52.000Z (about 5 years ago)
- Last Synced: 2024-10-30T00:10:55.164Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 292 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-blink1-async
Programmatically controlling [blink(1) USB LED devices](https://blink1.thingm.com/) is simple using **node-blink1-async**. Much of the API is asynchronous (i.e., returns Promise that you can await on) and fully [documented](https://ros2jsguy.github.io/node-blink1-async/). This module has been tested on Mac, Windows 10, and Ubuntu Linux on a Raspberry Pi 4.
 USB led on raspberry pi 4")
If you perfer a JS callback style API consider [node-blink1](https://www.npmjs.com/package/node-blink1).
# Prerequisites
* Node (v12+)
* blink(1) USB led device
Ensure your blink(1) is fully functional using the [blink(1) utilities](https://blink1.thingm.com/downloads/).
# Install
```
npm install https://github.com/ros2jsguy/node-blink-async
```
## Linux Users
Your device may need libusb installed:
```
sudo apt install libusb-1.0-0
```
See node-hid's [instructions for compiling from source](https://github.com/node-hid/node-hid#compiling-from-source)
You may find the 51-blink1.rules file useful in your device configuration process.
# TypeScript Example
```
import {Blink1, Blink1_LEDN, BlinkRate} from '@ros2jsguy/node-blink1-async';
async function example() {
// list all blink(1) devices
console.log('devices; ', Blink1.devices());
// output the version info of the default blink(1) device
let blink1: Blink1 = new Blink1();
console.log("version: " , await blink1.version() );
console.log('set color: red', await blink1.setRGB(255));
console.log('read rgb: ', await blink1.rgb(Blink1_LEDN.LEDA));
await Blink1.delay(2000);
console.log('Blink green at VERY_FAST rate (100 ms) for 5 seconds');
await blink1.blink(0, 255, 0, BlinkRate.VERY_FAST);
await Blink1.delay(5000);
console.log('Blink blue at SLOW rate (1000 ms) for 5 seconds');
await blink1.blink(0, 0, 255, BlinkRate.SLOW);
await Blink1.delay(5000);
console.log('Show solid yellow for 5 seconds');
await blink1.blink(255, 255, 0);
await Blink1.delay(5000);
// turn off the blink(1) output
await blink1.off();
// access the display pattern at line-1
console.log('Color pattern (line-1):', await blink1.readPatternLine(1));
// clear the memory of all display patterns.
console.log('Clearing pattern');
await blink1.clearPattern();
// confirm that display patterns are cleared
console.log('Color pattern (line-1):', await blink1.readPatternLine(1));
// close and release the blink(1) device
await blink1.close();
console.log('completed');
}
```
# Developer Notes
I develop mostly in TypeScript and prefer using modern JS features when I have the option.
Working directly with the node-blink1 package which has been around for awhile, felt too
retro for my liking, e.g., no jsdoc, callback-based api...
I mean no disrespect to the node-blink1 author(s) who's priority
for backward compatibility supercedes breaking the package just to use a new
wizbang language feature. While developing a robot using TypeScript
on a Raspi4 I wanted to integrate an old Blink1 led from my kit
into the design. That led me to creating this package that makes it easier to
to asynchronously control a Blink1 LED from TypeScript.
# Credits
This package uses the [node-blink1](https://www.npmjs.com/package/node-blink1) package to perform the low level control of Blink1 devices