2017-09-21 1 views
1

Ich möchte eine Anwendung schreiben, um die Tasten dieses Fußpedals, das ich in NodeJS habe, neu zuordnen. Ich habe eine ähnliche Bibliothek für mein Fußpedal gefunden; Es codiert jedoch den USB-Pfad für das Gerät, das für Linux nicht OSX ist. was einen Fehler wirft:Wie identifiziert man den "Pfad" des USB-Gerätes auf osx und createReadStream seine Daten vom Knoten?

failed to open file { Error: ENOENT: no such file or directory, open '/dev/usb/hiddev0' 
    errno: -2, 
    code: 'ENOENT', 
    syscall: 'open', 
    path: '/dev/usb/hiddev0' 

Frage: Wie kann ich den USB-Pfad für das Gerät zu identifizieren, so dass ich kann createReadStream von Daten von einem USB-Gerät.

Terminal-Befehl:

system_profiler SPUSBDataType 

Ausgang:

VEC USB Footpedal: 

       Product ID: 0x00ff 
       Vendor ID: 0x05f3 (PI Engineering, Inc) 
       Version: 1.20 
       Speed: Up to 1.5 Mb/sec 
       Manufacturer: VEC 
       Location ID: 0x1d112000/9 
       Current Available (mA): 500 
       Current Required (mA): 100 
       Extra Operating Current (mA): 0 


#! /usr/bin/env node 
'use strict'; 

const fs = require('fs'); 
const robot = require('robotjs'); 

const DEFAULT_DEVICE_PATH = '/dev/usb/hiddev0'; // this path needs to change 
const DEFAULT_KEYS = ['a', 'b', 'c']; 
const RETRY_INTERVAL = 5 * 1000; 

const argv = require('yargs') 
      .array('k') 
      .alias('k', 'keys') 
      .alias('p', 'path') 
      .default('path', DEFAULT_DEVICE_PATH) 
      .default('k', []) 
      .argv; 

const keyMap = DEFAULT_KEYS.map((key, i) => (argv.keys[i] || key)); 
const state = [ false, false, false ]; 

function updateState(index, value) { 
    const previousState = state[index]; 
    const currentState = (value === 0x01); 

    if (previousState !== currentState) { 
    const key = keyMap[index]; 
    robot.keyToggle(key, currentState ? 'down' : 'up'); 
    } 

    state[index] = currentState; 
} 

function openFile() { 
    const stream = fs.createReadStream(argv.path); // so that I can read the stream here. 
    const size = 8; 
    const offset = 4; 

    stream.on('data', function(chunk) { 
    for (var i=0; i<chunk.length/size; i++) { 
     updateState(i, chunk[i * size + offset]); 
    } 
    }); 

    stream.on('error', function(err) { 
    console.log('failed to open file', err); 
    setTimeout(openFile, RETRY_INTERVAL); 
    }); 
} 

openFile(); 

Antwort

Verwandte Themen