1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 07:15:18 +03:00

Merge pull request #51 from Roeland54/development

Sending "exit" command on closing configurator.
This commit is contained in:
Dominic Clifton 2015-01-12 06:28:00 +00:00
commit 23e3832845
2 changed files with 39 additions and 24 deletions

View file

@ -19,7 +19,7 @@ function startApplication() {
}); });
createdWindow.onClosed.addListener(function () { 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 // save connectionId in separate variable before createdWindow.contentWindow is destroyed
var connectionId = createdWindow.contentWindow.serial.connectionId, var connectionId = createdWindow.contentWindow.serial.connectionId,
valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid, valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid,
@ -27,34 +27,49 @@ function startApplication() {
if (connectionId && valid_connection) { if (connectionId && valid_connection) {
// code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message // 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) // reset motors to default (mincommand)
var bufferOut = new ArrayBuffer(22),
bufView = new Uint8Array(bufferOut),
checksum = 0;
bufView[0] = 36; // $ var bufferOut = new ArrayBuffer(5),
bufView[1] = 77; // M bufView = new Uint8Array(bufferOut);
bufView[2] = 60; // <
bufView[3] = 16; // data length
bufView[4] = 214; // MSP_SET_MOTOR
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) { chrome.serial.send(connectionId, bufferOut, function () { console.log('Send exit') });
bufView[i + 5] = mincommand & 0x00FF;
bufView[i + 6] = mincommand >> 8;
checksum ^= bufView[i + 5]; setTimeout(function() {
checksum ^= bufView[i + 6]; 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) { checksum = bufView[3] ^ bufView[4];
chrome.serial.disconnect(connectionId, function (result) {
console.log('SERIAL: Connection closed - ' + result); 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) { } else if (connectionId) {
chrome.serial.disconnect(connectionId, function (result) { chrome.serial.disconnect(connectionId, function (result) {
console.log('SERIAL: Connection closed - ' + result); console.log('SERIAL: Connection closed - ' + result);

6
main.html Normal file → Executable file
View file

@ -1,12 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="cTn" /> <meta name="author" content="cTn" />
<link type="text/css" rel="stylesheet" href="./main.css" media="all" /> <link type="text/css" rel="stylesheet" href="./main.css" media="all" />
<link type="text/css" rel="stylesheet" href="./js/libraries/jquery.nouislider.min.css" rel="stylesheet"> <link type="text/css" rel="stylesheet" href="./js/libraries/jquery.nouislider.min.css">
<link type="text/css" rel="stylesheet" href="./js/libraries/jquery.nouislider.pips.min.css" rel="stylesheet"> <link type="text/css" rel="stylesheet" href="./js/libraries/jquery.nouislider.pips.min.css">
<link type="text/css" rel="stylesheet" href="./tabs/landing.css" media="all" /> <link type="text/css" rel="stylesheet" href="./tabs/landing.css" media="all" />
<link type="text/css" rel="stylesheet" href="./tabs/setup.css" media="all" /> <link type="text/css" rel="stylesheet" href="./tabs/setup.css" media="all" />