-
Notifications
You must be signed in to change notification settings - Fork 39
2024 Linux Instructions (node-hid 3.0.0, async TypeScript) #49
Copy link
Copy link
Open
Description
This project hasn't been updated in five years and didn't work on my Ubuntu 23.10. I was getting some python-related build errors when running npm install. Maybe because Ubuntu uses Python 3 by default, and the old node-hid package versions depend on Python 2.7 for building.
Luckily, this project only has one dependency, https://www.npmjs.com/package/node-hid, and the source-code on here is fairly straight-forward. I was able to start using my Blinkstick Pro again like so:
import { HIDAsync as Device, devicesAsync } from "node-hid"; // node-hid@3.0.0
const run = async () => {
const devices = await devicesAsync();
const bsDeviceInfo = devices.find(({ product }) => product === "BlinkStick");
if (!bsDeviceInfo) throw new Error("No BlinkStick found");
if (!bsDeviceInfo.path) throw new Error("BlinkStick does not have path");
const bs = await Device.open(bsDeviceInfo.path);
// Set LED at index 0 to red
const red = [255, 0, 0];
const index = 0;
await bs.sendFeatureReport(Buffer.from([5, 0, index, ...red]));
await bs.close();
};
run();Hope that helps people here to get started!
Some notes from me:
node-hidis well typed, so it's easy to explore.- Colors are represented as RGB values with type
[number, number, number], wherenumberis from 0-255 - You mainly interact with the BlinkStick through
sendFeatureReport- A FeatureReport is just a Buffer/Array of numbers
- The first element seems to be some kind of "command" parameter.
5is for setting a LED's color. - The rest is args for the command
- The first arg is called
channelin this repo, but I couldn't figure out what it's for - The second arg is the index of the LED you want to change
- The last three args are an RGB array for the color
- The first arg is called
node-hidalso has a synchronous API if you prefer- I only have the BlinkStick Pro so idk if this works for the other products
- Don't be discouraged to look at @arvydas's code in this repo, it should teach you how to do other things
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels