How to use the node-hid.devices function in node-hid

To help you get started, we’ve selected a few node-hid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github igbopie / spherov2.js / src / examples / lib / nimbus.ts View on Github external
enum Buttons {
  A = 4,
  B = 5,
  X = 6,
  Y = 7,
  LeftStickY = 14,
  LeftStickX = 13,
  RightStickY = 16,
  RightStickX = 15,
  R2 = 11,
  L2 = 10,
}

const MAX_D_PAD = 127;
const devs = devices();
const deviceInfo = devs.find((d) => d.vendorId === 273 && d.productId === 5152);

if ( !deviceInfo ) {
  // tslint:disable-next-line:no-console
    console.error('Could not find device in device list');
    process.exit(1);
}

const device = new HID( deviceInfo.path );
const calculate = ({ xRaw, yRaw }: { xRaw: number, yRaw: number }) => {
  const x = xRaw / MAX_D_PAD;
  const y = yRaw / MAX_D_PAD;
  const module = Math.sqrt(x * x + y * y);
  let angle = (Math.atan(y / x) * (180 / Math.PI)) * - 1 + 90;
  if (x < 0) {
    angle += 180;
github boutch55555 / x2x0-agan / setbrightness.js View on Github external
#!/usr/bin/env node
var HID = require('node-hid');
fs = require('fs');

var devices = HID.devices();
device = new HID.HID(4292,33742); // same ID for both boards I got

// Board has 16 levels, the OS sees 21, so I remap the values and keep the 5 extra at max brightness. 
// Mappings might be off depending on the driver. Check values on /sys/class/backlight/*/actual_brightness.
// Was 0-100 by 5 intervals in my case. With the edp kernel patch it was 1-4439 with 222 increments.
var mapping = [['0', '0'], ['5', '16'],['10', '32'], ['15', '48'], ['20', '64'], ['25', '80'], ['30', '96'], ['35', '112'], ['40', '128'], ['45', '144'], ['50', '160'], ['55', '176'], ['60', '192'], ['65', '208'], ['70', '224'], ['75', '240'], ['80', '240'], ['85', '240'], ['90', '240'], ['95', '240'], ['100', '240']]

var myMap = new Map(mapping);

// file path might change depending on the driver. 
fs.readFile('/sys/class/backlight/acpi_video0/actual_brightness', 'utf8', function (err,data) {
  if (err) {
    return console.log(err);
  }
  data = data.replace("\n", ''); // clear the newline
  data = myMap.get(data); // get corresponding value
github todbot / Blink1Control2 / main.js View on Github external
});

  // initialize runtime reference to main window
  //runtime.windowId = mainWindow.id;

  //mainWindow.loadUrl('file://' + __dirname + '/dist/index.html#/todtests');
  mainWindow.loadUrl('file://' + __dirname + '/dist/index.html');
  mainWindow.focus();

  mainWindow.openDevTools();  

  mainWindow.on('closed', function () {
    mainWindow = null;
  });

  var devices = HID.devices();
  //console.log("devices: ", devices);
  console.log("blink1 serials:", Blink1.devices() ); // returns array of serial numbers 
  //var blink1 = new Blink1();
  //blink1.fadeToRGB(400 , 255,0,255 ); // r, g, b: 0 - 255
  //blink1.close();


/*
  // Dock Menu (Mac)
  if (process.platform === 'darwin') {
    var dockMenu = Menu.buildFromTemplate([
      { label: 'New Window', click: function() { console.log('New Window'); } },
      { label: 'New Window with Settings', submenu: [
        { label: 'Basic' },
        { label: 'Pro'},
      ]},
github mvines / sainsmart-relay16 / relay16.js View on Github external
constructor()
  {
    let USB_VID = 0x0416;
    let USB_PID = 0x5020;

    let HID = require('node-hid');

    // Generated by mapRelays()
    this.relayBitmap = [128, 256, 64, 512, 32, 1024, 16, 2048, 8, 4096, 4, 8192, 2, 16384, 1, 32768];

    console.log('Detected devices:', HID.devices(USB_VID, USB_PID));
    this.hid = new HID.HID(USB_VID, USB_PID);
  }
github limpkin / mooltipass / mooltiapp / app / preload.js View on Github external
getDevices(options, callback) {
		var output = [];
		this.options = options;
		this.devices = HID.devices();
		for ( var I = 0; I < this.devices.length; I++ ) {
			if (options.filters[0].productId === this.devices[I].productId && options.filters[0].vendorId === this.devices[I].vendorId && (mooltipass.app.os == "linux" || options.filters[0].usagePage === this.devices[I].usagePage)) {
				/* see https://github.com/signal11/hidapi/pull/6 for linux */
				//console.log(this.devices[I])
				this.devices[I].deviceId = I;
				output.push(this.devices[I]);
			}
		}
		callback ( output );
	},
	getUserSelectedDevices(options, callback) {
github andrew / node-xbox-controller / lib / xbox.js View on Github external
XboxController.prototype.loadController = function () {

  HID.devices().forEach((function (d) {
    var product = (typeof d === 'object' && d.product) || '';
    if (product.toLowerCase().indexOf(this.name.toLowerCase()) !== -1) {
      this.hid = new HID.HID(d.path);
      console.log(chalk.green('notice: '), 'Xbox controller connected.');
      this.emit('connected');
      location = this.hid;
    }
  }).bind(this));

  if (this.hid === false && !this._controllerLoadingInterval) {
    this._controllerLoadingInterval = setInterval(function () {
      this.loadController();
    }.bind(this), 2000);
  }

  try {
github ARMmbed / dapjs / examples / daplink-serial / hid.js View on Github external
return new Promise((resolve, reject) => {
        let devices = hid.devices();
        devices = devices.filter(device => device.vendorId === vendorID);

        if (devices.length === 0) {
            return reject("No devices found");
        }

        process.stdin.setRawMode(true);
        process.stdin.setEncoding("utf8");
        process.stdin.on("readable", () => {
            let input = process.stdin.read();
            if (input === "\u0003") {
                process.exit();
            } else {
                let index = parseInt(input);
                if (index && index <= devices.length) {
                    process.stdin.setRawMode(false);
github ARMmbed / dapjs / examples / daplink-flash / hid.js View on Github external
return new Promise((resolve, reject) => {
        let devices = hid.devices();
        devices = devices.filter(device => device.vendorId === vendorID);

        if (devices.length === 0) {
            return reject("No devices found");
        }

        process.stdin.setRawMode(true);
        process.stdin.setEncoding("utf8");
        process.stdin.on("readable", () => {
            let input = process.stdin.read();
            if (input === "\u0003") {
                process.exit();
            } else {
                let index = parseInt(input);
                if (index && index <= devices.length) {
                    process.stdin.setRawMode(false);
github suchipi / switch-joy-con / index.js View on Github external
function listConnectedJoyCons() {
  const devices = HID.devices();
  return devices
    .filter(device => device.vendorId === 1406)
    .map(device => {
      return Object.assign({}, device, {
        open() {
          if (device.productId === 8198) {
            return new JoyConLeft(device.path);
          } else if (device.productId === 8199) {
            return new JoyConRight(device.path);
          } else {
            throw new Error("Unknown Joy-Con model");
          }
        }
      });
    });
}

node-hid

USB HID device access library

BSD-3-Clause
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages