How to use the node-hid.HID 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 LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (transportInstance) {
        log("hid-verbose", "reusing opened transport instance");
        return transportInstance;
      }

      const device = getDevices()[0];
      if (!device) throw new CantOpenDevice("no device found");
      log("hid-verbose", "new HID transport");
      transportInstance = new TransportNodeHidSingleton(
        new HID.HID(device.path)
      );
      const unlisten = listenDevices(
        () => {},
        () => {
          // assume any ledger disconnection concerns current transport
          if (transportInstance) {
            transportInstance.emit("disconnect");
          }
        }
      );
      const onDisconnect = () => {
        if (!transportInstance) return;
        log("hid-verbose", "transport instance was disconnected");
        transportInstance.off("disconnect", onDisconnect);
        transportInstance = null;
        unlisten();
github nardi / rbkey-midi / rbkey.js View on Github external
module.exports = function RBKeyboard() {
    var devices = HID.devices();
    var validDevs = _.filter(devices,
        function(d) { return d.vendorId == 7085 && d.productId == 13104; });
    if (!validDevs.length)
        throw new Error('No usable devices found.');

    var device = new HID.HID(validDevs[0].path);
    var noteData = [];
    for (var i = 0; i < 25; i++) noteData[i] = false;
    var dpadData = {};
    var dirs = { Left: 6, Right: 2, Up: 0, Down: 4 };
    _.each(dirs, function(v, k) { dpadData[k] = false });
	var buttonData = {};
    var buttons = { 1: 1, A: 2, B: 4, 2: 8 };
    _.each(buttons, function(v, k) { buttonData[k] = false });
    var touchData = 0;
    var touchButtonData = false;

    function processData(data) {
        // Uncomment these lines to print the raw data, useful for development
        //_.each(data, function(d) { util.print(d + ' '); });
        //console.log();
github iamapig120 / simpad-control-panel / app / script.js View on Github external
document.getElementById('selBtn').addEventListener('click', async e => {
  if (devices && devices.length > 0) {
    if (device) device.close()
    clearTimeout(timeOutSet)
    const selectObject = JSON.parse(sel.value)
    const deviceInfoBlock = deviceList[selectObject.index]
    device = new HID.HID(selectObject.path)
    device.on('data', data => getDataFunction(data))
    // getAllSettings().then(() => initSettings())

    // 加载HTML
    const page2HTML = new Promise(resolve => {
      fs.readFile(
        path.join(
          __dirname,
          '/devices/',
          deviceInfoBlock.description,
          '/page2.html'
        ),
        (err, data) => {
          if (err) {
            throw err
          }
github limpkin / mooltipass / Mooltiapp / app / test_app / html / index.html View on Github external
button.addEventListener('click', function() {
      connection = new HID.HID( atob(this.path) );
      console.log( connection.getDeviceInfo() );
      connection.setNonBlocking(0);
      connection.readTimeout(500);
      connection.on('error', function(error) {
        console.log('got error from device', error );
      } );
    });
    output.appendChild( button );
github rdepena / node-dualshock-controller / examples / deviceDiscoveryHelp.js View on Github external
var HID = require('node-hid');
console.log(HID.devices());

var controller = new HID.HID(1356, 616);

controller.on('data', function(data) {
    for (var i = 0; i < data.length; i++) {
        if (i === 30) {
            console.log(i + " " + data[i]);
        }
    }
});
github floating / frame / main / signers / ledger / Ledger / index.js View on Github external
async getDevice () {
    if (this.pause) throw new Error('Device access is paused')
    if (Date.now() - this.lastUse < 300) await this.wait(300)
    await this.releaseDevice()
    this.pause = true
    this.currentDevice = new HID.HID(this.devicePath)
    this.currentTransport = new TransportNodeHid(this.currentDevice)
    return new Eth(this.currentTransport)
  }
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-noevents / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (path) {
        return new TransportNodeHidNoEvents(new HID.HID(path));
      }
      const device = getDevices()[0];
      if (!device) throw new TransportError("NoDevice", "NoDevice");
      return new TransportNodeHidNoEvents(new HID.HID(device.path));
    });
  }
github iamapig120 / simpad-control-panel / app / devices / sayoo2c / script.js View on Github external
devices.forEach(d => {
        let deviceToSend = new HID.HID(d.path)
        templeData.forEach(data => {
          if (promiseObj) {
            promiseObj.then(() => sendData(data, deviceToSend))
          } else {
            promiseObj = sendData(data, deviceToSend)
          }
        })
      })
      promiseObj.then(() =>
github jedcn / blync-core / lib / blync-light-manager.js View on Github external
return blyncLightDevices.map(function(device) {
    return new BlyncLight(new HID.HID(device.path));
  });
};
github rdepena / node-dualshock-controller / lib / device.js View on Github external
if (devices.length < 1) {
            return linuxConnector.getConnectedDevice();
        } else {
            //choose the bluetooth device:
            var blueToothConnection = devices.filter(function (device) {
                return device.path.toLowerCase().indexOf('bluetooth') > -1;
            })[0];

            //this might not do. refactor this.
            var path = blueToothConnection ? blueToothConnection.path : devices[0].path;

            //we have a node-hid device but the path is not correct.
            if (path === '0001:000f:00') {
                return linuxConnector.getConnectedDevice();
            }
            return new HID.HID(path);
        }
    }
};

node-hid

USB HID device access library

BSD-3-Clause
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis

Similar packages