diff --git a/eventPage.js b/eventPage.js index 9d1b7bd078..5a994e6419 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, @@ -27,34 +27,49 @@ function startApplication() { if (connectionId && valid_connection) { // code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message + // sending exit command just in case the cli tab was open. // reset motors to default (mincommand) - var bufferOut = new ArrayBuffer(22), - bufView = new Uint8Array(bufferOut), - checksum = 0; - bufView[0] = 36; // $ - bufView[1] = 77; // M - bufView[2] = 60; // < - bufView[3] = 16; // data length - bufView[4] = 214; // MSP_SET_MOTOR + var bufferOut = new ArrayBuffer(5), + bufView = new Uint8Array(bufferOut); - checksum = bufView[3] ^ bufView[4]; + bufView[0] = 0x65; // e + bufView[1] = 0x78; // x + bufView[2] = 0x69; // i + bufView[3] = 0x74; // t + bufView[4] = 0x0D; // enter - for (var i = 0; i < 16; i += 2) { - bufView[i + 5] = mincommand & 0x00FF; - bufView[i + 6] = mincommand >> 8; + chrome.serial.send(connectionId, bufferOut, function () { console.log('Send exit') }); - checksum ^= bufView[i + 5]; - checksum ^= bufView[i + 6]; - } + setTimeout(function() { + bufferOut = new ArrayBuffer(22); + bufView = new Uint8Array(bufferOut); + var checksum = 0; - bufView[5 + 16] = checksum; + bufView[0] = 36; // $ + bufView[1] = 77; // M + bufView[2] = 60; // < + bufView[3] = 16; // data length + bufView[4] = 214; // MSP_SET_MOTOR - chrome.serial.send(connectionId, bufferOut, function (sendInfo) { - chrome.serial.disconnect(connectionId, function (result) { - console.log('SERIAL: Connection closed - ' + result); + checksum = bufView[3] ^ bufView[4]; + + 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]; + } + + bufView[5 + 16] = checksum; + + 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); diff --git a/main.html b/main.html old mode 100644 new mode 100755 index 45a010b6b9..cb2a05c32b --- a/main.html +++ b/main.html @@ -1,12 +1,12 @@ - + - - + +