Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "node-hid in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-hid' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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;
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();
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();
#!/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
});

  // 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'},
      ]},
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);
  }
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) {
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
          }
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 );
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 {

Is your System Free of Underlying Vulnerabilities?
Find Out Now