Expose uhk.sendUsbPacket() and vastly simplify {write,read}-eeprom.js by using it. Make led_pwm.js use uhk.js instead of the obsoleted util.js file.

This commit is contained in:
László Monda
2017-01-15 02:20:44 +01:00
parent 339602178a
commit bdb9c85031
4 changed files with 61 additions and 69 deletions

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env node
let uhk = require('./uhk');
let [endpointIn, endpointOut] = uhk.getUsbEndpoints();
var arg = process.argv[2] || '';
if (arg.length === 0) {
@@ -8,18 +7,4 @@ if (arg.length === 0) {
process.exit(1);
}
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);
process.exit(1);
}
endpointIn.transfer(64, function(err2, receivedBuffer) {
if (err2) {
console.error("USB error: %s", err2);
process.exit(2);
}
console.log('Received', uhk.bufferToString(receivedBuffer));
})
});
uhk.sendUsbPacket(Buffer.concat([new Buffer([uhk.usbCommands.writeEeprom, arg.length+2, 0x00, 0x00]), new Buffer(arg, 'utf8')]))