2014-02-14 13:18:19 +00:00
|
|
|
/*
|
|
|
|
If an id is also specified and a window with a matching id has been shown before, the remembered bounds of the window will be used instead.
|
|
|
|
*/
|
2014-08-14 14:23:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-07 15:40:52 +00:00
|
|
|
function startApplication() {
|
2014-10-01 12:08:15 +00:00
|
|
|
var applicationStartTime = new Date().getTime();
|
|
|
|
|
2013-04-08 15:29:52 +00:00
|
|
|
chrome.app.window.create('main.html', {
|
|
|
|
id: 'main-window',
|
2014-04-19 20:43:19 +00:00
|
|
|
frame: 'chrome',
|
2014-07-16 22:28:54 +00:00
|
|
|
innerBounds: {
|
2015-11-01 17:22:12 +00:00
|
|
|
minWidth: 1024, // changed from 960
|
2015-10-26 21:54:05 +00:00
|
|
|
minHeight: 700 // changed from 625
|
2015-11-01 17:22:12 +00:00
|
|
|
|
2014-07-16 22:28:54 +00:00
|
|
|
}
|
2014-08-10 04:01:44 +00:00
|
|
|
}, function (createdWindow) {
|
2014-10-01 12:08:15 +00:00
|
|
|
createdWindow.contentWindow.addEventListener('load', function () {
|
|
|
|
createdWindow.contentWindow.catch_startup_time(applicationStartTime);
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-10-01 12:08:15 +00:00
|
|
|
createdWindow.onClosed.addListener(function () {
|
2015-01-10 21:37:44 +00:00
|
|
|
// automatically close the port when application closes
|
2014-10-01 12:08:15 +00:00
|
|
|
// save connectionId in separate variable before createdWindow.contentWindow is destroyed
|
|
|
|
var connectionId = createdWindow.contentWindow.serial.connectionId,
|
|
|
|
valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid,
|
|
|
|
mincommand = createdWindow.contentWindow.MISC.mincommand;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-11-22 05:31:46 +00:00
|
|
|
if (connectionId && valid_connection) {
|
2014-06-27 15:31:12 +00:00
|
|
|
// code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message
|
2015-01-10 21:01:02 +00:00
|
|
|
// sending exit command just in case the cli tab was open.
|
2014-06-27 15:31:12 +00:00
|
|
|
// reset motors to default (mincommand)
|
2015-01-10 21:01:02 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
var bufferOut = new ArrayBuffer(5),
|
|
|
|
bufView = new Uint8Array(bufferOut);
|
2015-01-10 21:01:02 +00:00
|
|
|
|
|
|
|
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') });
|
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
bufferOut = new ArrayBuffer(22);
|
|
|
|
bufView = new Uint8Array(bufferOut);
|
|
|
|
var checksum = 0;
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
bufView[0] = 36; // $
|
|
|
|
bufView[1] = 77; // M
|
|
|
|
bufView[2] = 60; // <
|
|
|
|
bufView[3] = 16; // data length
|
|
|
|
bufView[4] = 214; // MSP_SET_MOTOR
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
checksum = bufView[3] ^ bufView[4];
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
for (var i = 0; i < 16; i += 2) {
|
|
|
|
bufView[i + 5] = mincommand & 0x00FF;
|
|
|
|
bufView[i + 6] = mincommand >> 8;
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
checksum ^= bufView[i + 5];
|
|
|
|
checksum ^= bufView[i + 6];
|
|
|
|
}
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
bufView[5 + 16] = checksum;
|
2014-06-27 15:31:12 +00:00
|
|
|
|
2015-01-10 21:37:44 +00:00
|
|
|
chrome.serial.send(connectionId, bufferOut, function (sendInfo) {
|
|
|
|
chrome.serial.disconnect(connectionId, function (result) {
|
|
|
|
console.log('SERIAL: Connection closed - ' + result);
|
|
|
|
});
|
2014-06-27 15:31:12 +00:00
|
|
|
});
|
2015-01-10 21:37:44 +00:00
|
|
|
}, 100);
|
2014-11-22 05:31:46 +00:00
|
|
|
} else if (connectionId) {
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.serial.disconnect(connectionId, function (result) {
|
2013-12-06 17:32:32 +00:00
|
|
|
console.log('SERIAL: Connection closed - ' + result);
|
2013-06-19 11:06:14 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 15:29:52 +00:00
|
|
|
});
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:40:52 +00:00
|
|
|
chrome.app.runtime.onLaunched.addListener(startApplication);
|
2013-11-12 06:15:18 +00:00
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.runtime.onInstalled.addListener(function (details) {
|
2014-03-08 05:25:15 +00:00
|
|
|
if (details.reason == 'update') {
|
2014-09-08 10:14:41 +00:00
|
|
|
var previousVersionArr = details.previousVersion.split('.'),
|
|
|
|
currentVersionArr = chrome.runtime.getManifest().version.split('.');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-10 12:24:14 +00:00
|
|
|
// only fire up notification sequence when one of the major version numbers changed
|
2014-09-08 10:14:41 +00:00
|
|
|
if (currentVersionArr[0] > previousVersionArr[0] || currentVersionArr[1] > previousVersionArr[1]) {
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.storage.local.get('update_notify', function (result) {
|
2014-08-14 15:03:47 +00:00
|
|
|
if (result.update_notify === 'undefined' || result.update_notify) {
|
2014-05-10 12:24:14 +00:00
|
|
|
var manifest = chrome.runtime.getManifest();
|
|
|
|
var options = {
|
|
|
|
priority: 0,
|
|
|
|
type: 'basic',
|
|
|
|
title: manifest.name,
|
|
|
|
message: chrome.i18n.getMessage('notifications_app_just_updated_to_version', [manifest.version]),
|
|
|
|
iconUrl: '/images/icon_128.png',
|
|
|
|
buttons: [{'title': chrome.i18n.getMessage('notifications_click_here_to_start_app')}]
|
|
|
|
};
|
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.notifications.create('baseflight_update', options, function (notificationId) {
|
2014-05-10 12:24:14 +00:00
|
|
|
// empty
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-10 04:01:44 +00:00
|
|
|
chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
|
2013-11-12 06:15:18 +00:00
|
|
|
if (notificationId == 'baseflight_update') {
|
2014-10-07 15:40:52 +00:00
|
|
|
startApplication();
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
2013-04-08 15:29:52 +00:00
|
|
|
});
|