Jump to the bootloader without crashing.
This commit is contained in:
38
usb/uhk.js
38
usb/uhk.js
@@ -47,13 +47,9 @@ class DelayMs {
|
||||
}
|
||||
}
|
||||
|
||||
function sendUsbPacketsByCallback(packetProvider) {
|
||||
function sendUsbPacketsByCallback(packetProvider, options) {
|
||||
let packet = packetProvider()
|
||||
|
||||
if (!packet) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (packet instanceof DelayMs) {
|
||||
setTimeout(() => {
|
||||
sendUsbPacketsByCallback(packetProvider);
|
||||
@@ -61,6 +57,10 @@ function sendUsbPacketsByCallback(packetProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(packet instanceof Buffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Sending: ', bufferToString(packet));
|
||||
|
||||
let [endpointIn, endpointOut] = usbEndpoints || getUsbEndpoints();
|
||||
@@ -69,25 +69,31 @@ function sendUsbPacketsByCallback(packetProvider) {
|
||||
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:', bufferToString(receivedBuffer));
|
||||
|
||||
if (options.noReceive) {
|
||||
sendUsbPacketsByCallback(packetProvider);
|
||||
})
|
||||
} else {
|
||||
endpointIn.transfer(64, function(err2, receivedBuffer) {
|
||||
if (err2) {
|
||||
console.error("USB error: %s", err2);
|
||||
process.exit(2);
|
||||
}
|
||||
console.log('Received:', bufferToString(receivedBuffer));
|
||||
sendUsbPacketsByCallback(packetProvider);
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function sendUsbPacket(packet) {
|
||||
sendUsbPackets([packet]);
|
||||
function sendUsbPacket(packet, options={}) {
|
||||
sendUsbPackets([packet], options);
|
||||
}
|
||||
|
||||
function sendUsbPackets(packets) {
|
||||
function sendUsbPackets(packets, options={}) {
|
||||
sendUsbPacketsByCallback(() => {
|
||||
return packets.shift();
|
||||
})
|
||||
}, options)
|
||||
}
|
||||
|
||||
exports = module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user