Rename util.js to uhk.js and refactor the dependent scripts to utilize its API.
This commit is contained in:
@@ -1,27 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var writeEepromCommandId = 5;
|
||||
|
||||
var device = usb.findByIds(vid, pid);
|
||||
device.open();
|
||||
|
||||
var usbInterface = device.interface(0);
|
||||
|
||||
// https://github.com/tessel/node-usb/issues/147
|
||||
// The function 'isKernelDriverActive' is not available on Windows and not even needed.
|
||||
if (process.platform !== 'win32' && usbInterface.isKernelDriverActive()) {
|
||||
usbInterface.detachKernelDriver();
|
||||
}
|
||||
usbInterface.claim();
|
||||
|
||||
var endpointIn = usbInterface.endpoints[0];
|
||||
var endpointOut = usbInterface.endpoints[1];
|
||||
let uhk = require('./uhk');
|
||||
let [endpointIn, endpointOut] = uhk.getUsbEndpoints();
|
||||
var arg = process.argv[2] || '';
|
||||
|
||||
if (arg.length === 0) {
|
||||
@@ -29,8 +8,8 @@ if (arg.length === 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var payload = Buffer.concat([new Buffer([writeEepromCommandId, arg.length+2, 0x00, 0x00]), new Buffer(arg, 'utf8')]);
|
||||
console.log('Sending ', util.bufferToString(payload));
|
||||
var payload = Buffer.concat([new Buffer([uhk.usbCommands.writeEeprom, arg.length+2, 0x00, 0x00]), new Buffer(arg, 'utf8')]);
|
||||
console.log('Sending ', uhk.bufferToString(payload));
|
||||
endpointOut.transfer(payload, function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
@@ -41,6 +20,6 @@ endpointOut.transfer(payload, function(err) {
|
||||
console.error("USB error: %s", err2);
|
||||
process.exit(2);
|
||||
}
|
||||
console.log('Received', util.bufferToString(receivedBuffer));
|
||||
console.log('Received', uhk.bufferToString(receivedBuffer));
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user