Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
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 );
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]);
}
}
});
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)
}
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));
});
}
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(() =>
return blyncLightDevices.map(function(device) {
return new BlyncLight(new HID.HID(device.path));
});
};
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);
}
}
};