This is a fork of Blinkstick library, but now in TypeScript with Promises.
BlinkStick Node provides an interface to control Blinkstick devices connected to your computer with Node.js.
What is BlinkStick? It's a smart USB-controlled LED device. More info about it here:
AbortSignal
(this is only partially supported, your mileage may vary)undefined
]If you want to buy me a BlinkStick device for testing purposes, please email me.
Install libudev
and libusb
development packages:
sudo apt-get install libusb-1.0-0-dev libudev-dev -y
Install using npm:
npm install @ginden/blinkstick-v2
Using async APIs is the recommended way. While even sync APIs use Promises, they block the event loop, which is not a good practice.
Read docs of node-hid
for more
information.
import { BlinkStick, findFirstAsync } from '@ginden/blinkstick-v2';
const blinkstick = await findFirstAsync();
If you are using Async API, you might accidentally let Blinkstick
instance to be garbage-collected. This will emit a
warning, because Blinkstick
instance holds reference to C API object. To avoid it, just call close
or
use explicit resource management.
Direct construction of BlinkStick
is not recommended.
import { BlinkStick, findFirst } from '@ginden/blinkstick-v2';
const blinkstick = findFirst();
// Color names are allowed
await blinkstick.pulse('red');
// "random" is also allowed
await blinkstick.pulse('random');
// RGB values are allowed
await blinkstick.pulse(100, 0, 0);
// RGB values as hex string are allowed
await blinkstick.pulse('#ff0000');
// RGB values as hex string are allowed
await blinkstick.pulse('ff0000');
// Well, even rgb(255, 0, 0) is allowed
await blinkstick.pulse('rgb(255, 0, 0)');
await blinkstick.setColor('red');
If you get an error message on Linux:
Error: cannot open device with path /dev/hidraw0
Please run the following command and restart your computer:
echo "KERNEL==\"hidraw*\", SUBSYSTEM==\"hidraw\", ATTRS{idVendor}==\"20a0\", ATTRS{idProduct}==\"41e5\", MODE=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick-hid.rules
Open pull requests, you are welcome.
To run tests, you need to have Blinkstick device connected to your computer. This makes it impossible to run tests on CI, and even typical automated testing is rather challenging.
Run npm run test:manual
and follow the instructions. You should physically see the device changing colors, and you
will answer yes/no to the questions.
Just run npm test
and it will run the tests. You can also run npm test -- --watch
to run the tests in watch mode.
Copyright (c) 2014 Agile Innovative Ltd and contributors
Released under MIT license.