Rename util.js to uhk.js and refactor the dependent scripts to utilize its API.
This commit is contained in:
@@ -1,34 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var test_led_command_id = 2;
|
||||
|
||||
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 state = 1;
|
||||
|
||||
setInterval(function() {
|
||||
state = state ? 0 : 1
|
||||
console.log('Sending ', state);
|
||||
endpointOut.transfer(new Buffer([test_led_command_id, state]), function(err) {
|
||||
endpointOut.transfer(new Buffer([uhk.usbCommands.setTestLed, state]), function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
process.exit(1);
|
||||
@@ -38,7 +19,7 @@ setInterval(function() {
|
||||
console.error("USB error: %s", err2);
|
||||
process.exit(2);
|
||||
}
|
||||
console.log('Received', util.bufferToString(receivedBuffer));
|
||||
console.log('Received', uhk.bufferToString(receivedBuffer));
|
||||
})
|
||||
});
|
||||
}, 500)
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
let uhk = require('./uhk');
|
||||
let [endpointIn, endpointOut] = uhk.getUsbEndpoints();
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var jumpToBootloaderCommandId = 1;
|
||||
|
||||
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];
|
||||
|
||||
var payload = new Buffer([jumpToBootloaderCommandId]);
|
||||
console.log('Sending ', util.bufferToString(payload));
|
||||
var payload = new Buffer([uhk.usbCommands.jumpToBootloader]);
|
||||
console.log('Sending ', uhk.bufferToString(payload));
|
||||
endpointOut.transfer(payload, function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
@@ -35,6 +14,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));
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,32 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
let uhk = require('./uhk');
|
||||
let [endpointIn, endpointOut] = uhk.getUsbEndpoints();
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var ledMatrixSize = 144;
|
||||
var ledCountToUpdatePerCommand = ledMatrixSize / 3;
|
||||
var writeLedDriverCommandId = 3;
|
||||
var leftLedDriverAddress = 0b1110100;
|
||||
var rightLedDriverAddress = 0b1110111;
|
||||
|
||||
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];
|
||||
|
||||
var state = 1;
|
||||
|
||||
var ledsLeft = new Buffer(ledMatrixSize);
|
||||
@@ -39,7 +19,7 @@ var matrixId = 0;
|
||||
|
||||
var initLedCommands = [
|
||||
[ // only enable the LEDs that are actually in the matrix
|
||||
writeLedDriverCommandId,
|
||||
uhk.usbCommands.writeLedDriver,
|
||||
leftLedDriverAddress,
|
||||
19,
|
||||
0,
|
||||
@@ -54,7 +34,7 @@ var initLedCommands = [
|
||||
0, 0b00011111,
|
||||
],
|
||||
[ // only enable the LEDs that are actually in the matrix
|
||||
writeLedDriverCommandId,
|
||||
uhk.usbCommands.writeLedDriver,
|
||||
rightLedDriverAddress,
|
||||
19,
|
||||
0,
|
||||
@@ -68,9 +48,9 @@ var initLedCommands = [
|
||||
0, 0,
|
||||
0, 0,
|
||||
],
|
||||
[writeLedDriverCommandId, leftLedDriverAddress, 2, 0xfd, 0x0b], // switch to function page
|
||||
[writeLedDriverCommandId, leftLedDriverAddress, 2, 0xc2, 0xff], // enable the ghost image prevention bit
|
||||
[writeLedDriverCommandId, leftLedDriverAddress, 2, 0xfd, 0x00], // switch to page 0
|
||||
[uhk.usbCommands.writeLedDriver, leftLedDriverAddress, 2, 0xfd, 0x0b], // switch to function page
|
||||
[uhk.usbCommands.writeLedDriver, leftLedDriverAddress, 2, 0xc2, 0xff], // enable the ghost image prevention bit
|
||||
[uhk.usbCommands.writeLedDriver, leftLedDriverAddress, 2, 0xfd, 0x00], // switch to page 0
|
||||
]
|
||||
|
||||
var ledCommandId = 0;
|
||||
@@ -97,14 +77,14 @@ function updateLeds() {
|
||||
// console.log('update')
|
||||
var buffer = Buffer.concat([
|
||||
new Buffer([
|
||||
writeLedDriverCommandId,
|
||||
uhk.usbCommands.writeLedDriver,
|
||||
matrixId ? rightLedDriverAddress : leftLedDriverAddress,
|
||||
ledCountToUpdatePerCommand,
|
||||
0x24 + ledIndex
|
||||
]),
|
||||
(matrixId ? ledsRight : ledsLeft).slice(ledIndex, ledIndex + ledCountToUpdatePerCommand)
|
||||
]);
|
||||
console.log('iter: '+letterIdx+' out:', util.bufferToString(buffer))
|
||||
console.log('iter: '+letterIdx+' out:', uhk.bufferToString(buffer))
|
||||
endpointOut.transfer(buffer, function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
@@ -116,7 +96,7 @@ function updateLeds() {
|
||||
console.error("USB error: %s", err2);
|
||||
process.exit(2);
|
||||
}
|
||||
// console.log('Received', util.bufferToString(receivedBuffer));
|
||||
// console.log('Received', uhk.bufferToString(receivedBuffer));
|
||||
|
||||
ledIndex += ledCountToUpdatePerCommand;
|
||||
if (ledIndex >= ledMatrixSize) {
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
let uhk = require('./uhk');
|
||||
let [endpointIn, endpointOut] = uhk.getUsbEndpoints();
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var readEepromCommandId = 6;
|
||||
|
||||
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];
|
||||
|
||||
var payload = new Buffer([readEepromCommandId, 63, 0x00, 0x00]);
|
||||
console.log('Sending ', util.bufferToString(payload));
|
||||
var payload = new Buffer([uhk.usbCommands.readEeprom, 63, 0x00, 0x00]);
|
||||
console.log('Sending ', uhk.bufferToString(payload));
|
||||
endpointOut.transfer(payload, function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
@@ -35,6 +14,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));
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,33 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var usb = require('usb');
|
||||
var util = require('./util');
|
||||
|
||||
var vid = 0x16d3;
|
||||
var pid = 0x05ea;
|
||||
var readMergeSensorCommandId = 7;
|
||||
|
||||
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] || '';
|
||||
|
||||
|
||||
function readMergeSensor() {
|
||||
var payload = new Buffer([readMergeSensorCommandId]);
|
||||
console.log('Sending ', util.bufferToString(payload));
|
||||
var payload = new Buffer([uhk.usbCommands.readMergeSensor]);
|
||||
console.log('Sending ', uhk.bufferToString(payload));
|
||||
endpointOut.transfer(payload, function(err) {
|
||||
if (err) {
|
||||
console.error("USB error: %s", err);
|
||||
@@ -38,7 +16,7 @@ function readMergeSensor() {
|
||||
console.error("USB error: %s", err2);
|
||||
process.exit(2);
|
||||
}
|
||||
console.log('Received', util.bufferToString(receivedBuffer));
|
||||
console.log('Received', uhk.bufferToString(receivedBuffer));
|
||||
setTimeout(readMergeSensor, 500)
|
||||
var areHalvesMerged = receivedBuffer[1] === 1;
|
||||
console.log('The keyboards halves are ' + (areHalvesMerged ? 'merged' : 'split'))
|
||||
|
||||
@@ -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