From 71008b6aadb0603ff265a67ba4119bf2e10a0700 Mon Sep 17 00:00:00 2001 From: Roeland Lutters Date: Sat, 10 Jan 2015 22:01:02 +0100 Subject: [PATCH 1/2] Sending exit command on closing configurator. --- eventPage.js | 19 ++++++++++++++++--- main.html | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) mode change 100644 => 100755 main.html diff --git a/eventPage.js b/eventPage.js index 9d1b7bd078..5cc725949b 100755 --- a/eventPage.js +++ b/eventPage.js @@ -27,10 +27,23 @@ 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; + + var bufferOut = new ArrayBuffer(5); + var bufView = new Uint8Array(bufferOut); + + bufView[0] = 0x65; // e + bufView[1] = 0x78; // x + bufView[2] = 0x69; // i + bufView[3] = 0x74; // t + bufView[4] = 0x0D; // enter + + chrome.serial.send(connectionId, bufferOut, function () { console.log('Send exit') }); + + bufferOut = new ArrayBuffer(29); + bufView = new Uint8Array(bufferOut); + var checksum = 0; bufView[0] = 36; // $ bufView[1] = 77; // M 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 @@ - + - - + + From 8372092beb7661e6441cfb270da4699a526fa299 Mon Sep 17 00:00:00 2001 From: Roeland Lutters Date: Sat, 10 Jan 2015 22:37:44 +0100 Subject: [PATCH 2/2] Fixing broken motors mincommand on configurator close. --- eventPage.js | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/eventPage.js b/eventPage.js index 5cc725949b..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, @@ -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);