diff options
author | Roeland Lutters <Roeland.lutters@telenet.be> | 2015-01-11 00:37:44 +0300 |
---|---|---|
committer | Roeland Lutters <Roeland.lutters@telenet.be> | 2015-01-11 00:37:44 +0300 |
commit | 8372092beb7661e6441cfb270da4699a526fa299 (patch) | |
tree | c8346073fd68f476e9aa6f91e545751b0b573ff0 /eventPage.js | |
parent | 71008b6aadb0603ff265a67ba4119bf2e10a0700 (diff) |
Fixing broken motors mincommand on configurator close.
Diffstat (limited to 'eventPage.js')
-rwxr-xr-x | eventPage.js | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/eventPage.js b/eventPage.js index 5cc72594..5a994e64 100755 --- a/eventPage.js +++ b/eventPage.js @@ -19,7 +19,7 @@ function startApplication() { }); createdWindow.onClosed.addListener(function () { - // autoamtically close the port when application closes + // automatically close the port when application closes // save connectionId in separate variable before createdWindow.contentWindow is destroyed var connectionId = createdWindow.contentWindow.serial.connectionId, valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid, @@ -30,8 +30,8 @@ function startApplication() { // sending exit command just in case the cli tab was open. // reset motors to default (mincommand) - var bufferOut = new ArrayBuffer(5); - var bufView = new Uint8Array(bufferOut); + var bufferOut = new ArrayBuffer(5), + bufView = new Uint8Array(bufferOut); bufView[0] = 0x65; // e bufView[1] = 0x78; // x @@ -41,33 +41,35 @@ function startApplication() { chrome.serial.send(connectionId, bufferOut, function () { console.log('Send exit') }); - bufferOut = new ArrayBuffer(29); - bufView = new Uint8Array(bufferOut); - var checksum = 0; + setTimeout(function() { + bufferOut = new ArrayBuffer(22); + bufView = new Uint8Array(bufferOut); + var checksum = 0; - bufView[0] = 36; // $ - bufView[1] = 77; // M - bufView[2] = 60; // < - bufView[3] = 16; // data length - bufView[4] = 214; // MSP_SET_MOTOR + bufView[0] = 36; // $ + bufView[1] = 77; // M + bufView[2] = 60; // < + bufView[3] = 16; // data length + bufView[4] = 214; // MSP_SET_MOTOR - checksum = bufView[3] ^ bufView[4]; + checksum = bufView[3] ^ bufView[4]; - for (var i = 0; i < 16; i += 2) { - bufView[i + 5] = mincommand & 0x00FF; - bufView[i + 6] = mincommand >> 8; + for (var i = 0; i < 16; i += 2) { + bufView[i + 5] = mincommand & 0x00FF; + bufView[i + 6] = mincommand >> 8; - checksum ^= bufView[i + 5]; - checksum ^= bufView[i + 6]; - } + checksum ^= bufView[i + 5]; + checksum ^= bufView[i + 6]; + } - bufView[5 + 16] = checksum; + bufView[5 + 16] = checksum; - chrome.serial.send(connectionId, bufferOut, function (sendInfo) { - chrome.serial.disconnect(connectionId, function (result) { - console.log('SERIAL: Connection closed - ' + result); + chrome.serial.send(connectionId, bufferOut, function (sendInfo) { + chrome.serial.disconnect(connectionId, function (result) { + console.log('SERIAL: Connection closed - ' + result); + }); }); - }); + }, 100); } else if (connectionId) { chrome.serial.disconnect(connectionId, function (result) { console.log('SERIAL: Connection closed - ' + result); |