2014-08-09 17:38:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-14 14:41:49 +00:00
|
|
|
$(document).ready(function () {
|
2015-05-10 12:37:31 +00:00
|
|
|
|
2015-05-10 20:30:00 +00:00
|
|
|
GUI.updateManualPortVisibility = function(){
|
2015-05-10 19:51:16 +00:00
|
|
|
if ($('div#port-picker #port option:selected').data().isManual) {
|
|
|
|
$('#port-override-option').show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#port-override-option').hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-10 20:30:00 +00:00
|
|
|
GUI.updateManualPortVisibility();
|
2015-05-10 12:37:31 +00:00
|
|
|
|
|
|
|
$('#port-override').change(function () {
|
|
|
|
chrome.storage.local.set({'portOverride': $('#port-override').val()});
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.storage.local.get('portOverride', function (data) {
|
|
|
|
$('#port-override').val(data.portOverride);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('div#port-picker #port').change(function (target) {
|
2015-05-10 20:30:00 +00:00
|
|
|
GUI.updateManualPortVisibility();
|
2015-05-10 12:37:31 +00:00
|
|
|
});
|
|
|
|
|
2014-08-14 14:41:49 +00:00
|
|
|
$('div#port-picker a.connect').click(function () {
|
2013-11-14 06:27:35 +00:00
|
|
|
if (GUI.connect_lock != true) { // GUI control overrides the user control
|
2015-05-10 12:37:31 +00:00
|
|
|
|
|
|
|
var clicks = $(this).data('clicks');
|
|
|
|
var selected_baud = parseInt($('div#port-picker #baud').val());
|
|
|
|
var selected_port = $('div#port-picker #port option:selected').data().isManual ?
|
|
|
|
$('#port-override').val() :
|
|
|
|
String($('div#port-picker #port').val());
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-06-08 18:10:07 +00:00
|
|
|
if (selected_port != '0' && selected_port != 'DFU') {
|
2013-11-20 11:26:00 +00:00
|
|
|
if (!clicks) {
|
|
|
|
console.log('Connecting to: ' + selected_port);
|
|
|
|
GUI.connecting_to = selected_port;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-22 10:59:38 +00:00
|
|
|
// lock port select & baud while we are connecting / connected
|
|
|
|
$('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', true);
|
2014-05-06 14:19:30 +00:00
|
|
|
$('div#port-picker a.connect').text(chrome.i18n.getMessage('connecting'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-18 11:14:33 +00:00
|
|
|
serial.connect(selected_port, {bitrate: selected_baud}, onOpen);
|
2013-11-20 11:26:00 +00:00
|
|
|
} else {
|
2014-07-02 11:55:35 +00:00
|
|
|
GUI.timeout_kill_all();
|
2014-02-21 20:12:19 +00:00
|
|
|
GUI.interval_kill_all();
|
2013-11-14 06:27:35 +00:00
|
|
|
GUI.tab_switch_cleanup();
|
2014-07-09 14:10:02 +00:00
|
|
|
GUI.tab_switch_in_progress = false;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-18 11:14:33 +00:00
|
|
|
serial.disconnect(onClosed);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-01-26 23:43:09 +00:00
|
|
|
var wasConnected = CONFIGURATOR.connectionValid;
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2013-11-20 11:26:00 +00:00
|
|
|
GUI.connected_to = false;
|
2014-10-19 14:17:44 +00:00
|
|
|
CONFIGURATOR.connectionValid = false;
|
2015-01-26 21:37:31 +00:00
|
|
|
GUI.allowedTabs = GUI.defaultAllowedTabsWhenDisconnected.slice();
|
2014-10-19 14:17:44 +00:00
|
|
|
MSP.disconnect_cleanup();
|
|
|
|
PortUsage.reset();
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-15 17:45:46 +00:00
|
|
|
// Reset various UI elements
|
2014-06-16 12:13:30 +00:00
|
|
|
$('span.i2c-error').text(0);
|
|
|
|
$('span.cycle-time').text(0);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-22 10:59:38 +00:00
|
|
|
// unlock port select & baud
|
2013-12-29 10:15:04 +00:00
|
|
|
$('div#port-picker #port').prop('disabled', false);
|
|
|
|
if (!GUI.auto_connect) $('div#port-picker #baud').prop('disabled', false);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-10-19 14:17:44 +00:00
|
|
|
// reset connect / disconnect button
|
2014-05-06 14:19:30 +00:00
|
|
|
$(this).text(chrome.i18n.getMessage('connect'));
|
2014-02-03 08:15:13 +00:00
|
|
|
$(this).removeClass('active');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-10-19 14:17:44 +00:00
|
|
|
// reset active sensor indicators
|
|
|
|
sensor_status(0);
|
|
|
|
|
2015-01-26 23:43:09 +00:00
|
|
|
if (wasConnected) {
|
|
|
|
// detach listeners and remove element data
|
|
|
|
$('#content').empty();
|
|
|
|
}
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-26 21:37:31 +00:00
|
|
|
$('#tabs .tab_landing a').click();
|
2013-11-14 06:27:35 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-14 06:27:35 +00:00
|
|
|
$(this).data("clicks", !clicks);
|
2013-04-08 15:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-29 10:15:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// auto-connect
|
2014-08-14 14:41:49 +00:00
|
|
|
chrome.storage.local.get('auto_connect', function (result) {
|
2014-08-14 15:00:32 +00:00
|
|
|
if (result.auto_connect === 'undefined' || result.auto_connect) {
|
2014-05-08 13:05:21 +00:00
|
|
|
// default or enabled by user
|
2013-12-29 10:15:04 +00:00
|
|
|
GUI.auto_connect = true;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-04 23:45:25 +00:00
|
|
|
$('input.auto_connect').prop('checked', true);
|
2014-05-06 14:19:30 +00:00
|
|
|
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 13:05:21 +00:00
|
|
|
$('select#baud').val(115200).prop('disabled', true);
|
2013-12-29 10:15:04 +00:00
|
|
|
} else {
|
2014-05-08 13:05:21 +00:00
|
|
|
// disabled by user
|
|
|
|
GUI.auto_connect = false;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 13:05:21 +00:00
|
|
|
$('input.auto_connect').prop('checked', false);
|
|
|
|
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectDisabled'));
|
2013-12-29 10:15:04 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-29 10:15:04 +00:00
|
|
|
// bind UI hook to auto-connect checkbos
|
2014-08-14 14:41:49 +00:00
|
|
|
$('input.auto_connect').change(function () {
|
2013-12-29 10:15:04 +00:00
|
|
|
GUI.auto_connect = $(this).is(':checked');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-29 10:15:04 +00:00
|
|
|
// update title/tooltip
|
|
|
|
if (GUI.auto_connect) {
|
2014-05-06 14:19:30 +00:00
|
|
|
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-29 10:15:04 +00:00
|
|
|
$('select#baud').val(115200).prop('disabled', true);
|
|
|
|
} else {
|
2014-05-06 14:19:30 +00:00
|
|
|
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectDisabled'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-29 10:15:04 +00:00
|
|
|
if (!GUI.connected_to && !GUI.connecting_to) $('select#baud').prop('disabled', false);
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-04 23:45:25 +00:00
|
|
|
chrome.storage.local.set({'auto_connect': GUI.auto_connect});
|
2013-12-29 10:15:04 +00:00
|
|
|
});
|
2014-02-21 13:47:30 +00:00
|
|
|
});
|
2014-03-28 23:59:39 +00:00
|
|
|
|
2014-02-21 13:47:30 +00:00
|
|
|
PortHandler.initialize();
|
2014-03-28 23:59:39 +00:00
|
|
|
PortUsage.initialize();
|
2014-03-08 05:25:15 +00:00
|
|
|
});
|
2013-04-08 15:29:52 +00:00
|
|
|
|
2014-03-08 05:25:15 +00:00
|
|
|
function onOpen(openInfo) {
|
2014-02-03 09:07:54 +00:00
|
|
|
if (openInfo) {
|
2013-11-20 11:26:00 +00:00
|
|
|
// update connected_to
|
|
|
|
GUI.connected_to = GUI.connecting_to;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-20 11:26:00 +00:00
|
|
|
// reset connecting_to
|
|
|
|
GUI.connecting_to = false;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-06 14:19:30 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('serialPortOpened', [openInfo.connectionId]));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-06-18 18:13:26 +00:00
|
|
|
// save selected port with chrome.storage if the port differs
|
2014-08-14 14:41:49 +00:00
|
|
|
chrome.storage.local.get('last_used_port', function (result) {
|
|
|
|
if (result.last_used_port) {
|
2013-12-15 17:41:25 +00:00
|
|
|
if (result.last_used_port != GUI.connected_to) {
|
2013-06-18 18:13:26 +00:00
|
|
|
// last used port doesn't match the one found in local db, we will store the new one
|
2014-05-06 14:19:30 +00:00
|
|
|
chrome.storage.local.set({'last_used_port': GUI.connected_to});
|
2013-06-18 18:13:26 +00:00
|
|
|
}
|
2013-06-18 23:21:09 +00:00
|
|
|
} else {
|
|
|
|
// variable isn't stored yet, saving
|
2014-05-06 14:19:30 +00:00
|
|
|
chrome.storage.local.set({'last_used_port': GUI.connected_to});
|
2013-06-18 18:13:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-01-18 11:14:33 +00:00
|
|
|
serial.onReceive.addListener(read_serial);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-09-08 15:52:07 +00:00
|
|
|
// disconnect after 10 seconds with error if we don't get IDENT data
|
|
|
|
GUI.timeout_add('connecting', function () {
|
|
|
|
if (!CONFIGURATOR.connectionValid) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('noConfigurationReceived'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-09-08 15:52:07 +00:00
|
|
|
$('div#port-picker a.connect').click(); // disconnect
|
|
|
|
}
|
|
|
|
}, 10000);
|
2014-06-20 09:07:43 +00:00
|
|
|
|
2014-12-18 22:38:55 +00:00
|
|
|
|
2014-10-19 13:52:55 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
// request configuration data
|
|
|
|
MSP.send_message(MSP_codes.MSP_API_VERSION, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('apiVersionReceived', [CONFIG.apiVersion]));
|
2014-10-20 22:25:42 +00:00
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.apiVersionAccepted)) {
|
2015-01-02 19:27:43 +00:00
|
|
|
|
|
|
|
MSP.send_message(MSP_codes.MSP_FC_VARIANT, false, false, function () {
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_FC_VERSION, false, false, function () {
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
googleAnalytics.sendEvent('Firmware', 'Variant', CONFIG.flightControllerIdentifier + ',' + CONFIG.flightControllerVersion);
|
|
|
|
GUI.log(chrome.i18n.getMessage('fcInfoReceived', [CONFIG.flightControllerIdentifier, CONFIG.flightControllerVersion]));
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BUILD_INFO, false, false, function () {
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
googleAnalytics.sendEvent('Firmware', 'Using', CONFIG.buildInfo);
|
|
|
|
GUI.log(chrome.i18n.getMessage('buildInfoReceived', [CONFIG.buildInfo]));
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BOARD_INFO, false, false, function () {
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
googleAnalytics.sendEvent('Board', 'Using', CONFIG.boardIdentifier + ',' + CONFIG.boardVersion);
|
|
|
|
GUI.log(chrome.i18n.getMessage('boardInfoReceived', [CONFIG.boardIdentifier, CONFIG.boardVersion]));
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_UID, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('uniqueDeviceIdReceived', [CONFIG.uid[0].toString(16) + CONFIG.uid[1].toString(16) + CONFIG.uid[2].toString(16)]));
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-02 19:27:43 +00:00
|
|
|
// continue as usually
|
|
|
|
CONFIGURATOR.connectionValid = true;
|
2015-01-26 21:37:31 +00:00
|
|
|
GUI.allowedTabs = GUI.defaultAllowedTabsWhenConnected.slice();
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.4.0")) {
|
2015-01-26 21:37:31 +00:00
|
|
|
GUI.allowedTabs.splice(GUI.allowedTabs.indexOf('led_strip'), 1);
|
|
|
|
}
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
GUI.canChangePidController = semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion);
|
2015-01-29 17:27:50 +00:00
|
|
|
|
2015-01-26 21:37:31 +00:00
|
|
|
onConnect();
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-01-26 21:37:31 +00:00
|
|
|
$('#tabs ul.mode-connected .tab_setup a').click();
|
2015-01-02 19:27:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-10-19 13:52:55 +00:00
|
|
|
});
|
2015-01-02 19:27:43 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
GUI.log(chrome.i18n.getMessage('firmwareVersionNotSupported', [CONFIGURATOR.apiVersionAccepted]));
|
2015-01-06 19:35:58 +00:00
|
|
|
CONFIGURATOR.connectionValid = true; // making it possible to open the CLI tab
|
2015-01-26 21:37:31 +00:00
|
|
|
GUI.allowedTabs = ['cli'];
|
|
|
|
onConnect();
|
|
|
|
$('#tabs .tab_cli a').click();
|
2015-01-02 19:27:43 +00:00
|
|
|
}
|
2014-09-08 15:52:07 +00:00
|
|
|
});
|
2013-11-08 14:34:52 +00:00
|
|
|
} else {
|
|
|
|
console.log('Failed to open serial port');
|
2014-05-06 14:30:53 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('serialPortOpenFail'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-06 14:30:53 +00:00
|
|
|
$('div#port-picker a.connect').text(chrome.i18n.getMessage('connect'));
|
2014-03-08 05:25:15 +00:00
|
|
|
$('div#port-picker a.connect').removeClass('active');
|
|
|
|
|
2013-12-05 11:40:10 +00:00
|
|
|
// unlock port select & baud
|
|
|
|
$('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', false);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-08 14:34:52 +00:00
|
|
|
// reset data
|
|
|
|
$('div#port-picker a.connect').data("clicks", false);
|
2013-04-08 15:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-26 21:37:31 +00:00
|
|
|
function onConnect() {
|
|
|
|
GUI.timeout_remove('connecting'); // kill connecting timer
|
|
|
|
$('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active');
|
|
|
|
$('#tabs ul.mode-disconnected').hide();
|
|
|
|
$('#tabs ul.mode-connected').show();
|
2015-01-27 23:01:42 +00:00
|
|
|
|
|
|
|
if ("CLFL" == CONFIG.flightControllerIdentifier){
|
2015-10-23 14:00:03 +00:00
|
|
|
|
|
|
|
/* placing this elsewhere
|
|
|
|
var documentationButton = $('#button-documentation');
|
2015-01-29 18:01:37 +00:00
|
|
|
documentationButton.show();
|
|
|
|
documentationButton.html("Documentation for "+CONFIG.flightControllerVersion);
|
|
|
|
documentationButton.attr("href","https://github.com/cleanflight/cleanflight/tree/v{0}/docs".format(CONFIG.flightControllerVersion));
|
2015-10-23 14:00:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* just a thought
|
|
|
|
var sensor_state = $('#sensor-status');
|
|
|
|
sensor_state.show();
|
|
|
|
*/
|
|
|
|
|
|
|
|
var flashstate = $('#header_dataflash');
|
|
|
|
flashstate.show();
|
2015-01-27 23:01:42 +00:00
|
|
|
}
|
2015-01-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 15:29:52 +00:00
|
|
|
function onClosed(result) {
|
2014-02-03 08:15:13 +00:00
|
|
|
if (result) { // All went as expected
|
2014-05-06 14:19:30 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('serialPortClosedOk'));
|
2013-04-08 15:29:52 +00:00
|
|
|
} else { // Something went wrong
|
2014-05-06 14:19:30 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('serialPortClosedFail'));
|
2014-03-08 05:25:15 +00:00
|
|
|
}
|
2015-01-26 21:37:31 +00:00
|
|
|
|
2015-01-25 16:37:47 +00:00
|
|
|
$('#tabs ul.mode-connected').hide();
|
2015-01-26 21:37:31 +00:00
|
|
|
$('#tabs ul.mode-disconnected').show();
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-10-23 14:00:03 +00:00
|
|
|
|
|
|
|
var flashstate = $('#header_dataflash');
|
|
|
|
flashstate.hide();
|
|
|
|
|
|
|
|
/* just a thought
|
|
|
|
var sensor_state = $('#sensor-status');
|
|
|
|
sensor_state.hide();
|
|
|
|
*/
|
2013-04-08 15:29:52 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 11:14:33 +00:00
|
|
|
function read_serial(info) {
|
2014-09-08 15:52:07 +00:00
|
|
|
if (!CONFIGURATOR.cliActive) {
|
2014-03-02 17:36:28 +00:00
|
|
|
MSP.read(info);
|
2014-08-10 04:01:44 +00:00
|
|
|
} else if (CONFIGURATOR.cliActive) {
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.cli.read(info);
|
2014-01-22 19:35:37 +00:00
|
|
|
}
|
2013-04-08 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function sensor_status(sensors_detected) {
|
2013-12-24 18:17:59 +00:00
|
|
|
// initialize variable (if it wasn't)
|
2014-08-14 14:23:08 +00:00
|
|
|
if (!sensor_status.previous_sensors_detected) {
|
2013-12-24 18:17:59 +00:00
|
|
|
sensor_status.previous_sensors_detected = 0;
|
2013-04-08 18:07:47 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-12-24 18:17:59 +00:00
|
|
|
// update UI (if necessary)
|
2015-02-23 21:27:55 +00:00
|
|
|
if (sensor_status.previous_sensors_detected == sensors_detected) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-10 20:30:00 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
// set current value
|
|
|
|
sensor_status.previous_sensors_detected = sensors_detected;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
var e_sensor_status = $('div#sensor-status');
|
2013-04-08 18:07:47 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
if (have_sensor(sensors_detected, 'acc')) {
|
|
|
|
$('.accel', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.accel', e_sensor_status).removeClass('on');
|
|
|
|
}
|
2013-12-24 18:17:59 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
if (have_sensor(sensors_detected, 'gyro')) {
|
|
|
|
$('.gyro', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.gyro', e_sensor_status).removeClass('on');
|
|
|
|
}
|
2013-12-24 18:17:59 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
if (have_sensor(sensors_detected, 'baro')) {
|
|
|
|
$('.baro', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.baro', e_sensor_status).removeClass('on');
|
|
|
|
}
|
2013-12-24 18:17:59 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
if (have_sensor(sensors_detected, 'mag')) {
|
|
|
|
$('.mag', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.mag', e_sensor_status).removeClass('on');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_sensor(sensors_detected, 'gps')) {
|
|
|
|
$('.gps', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.gps', e_sensor_status).removeClass('on');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_sensor(sensors_detected, 'sonar')) {
|
|
|
|
$('.sonar', e_sensor_status).addClass('on');
|
|
|
|
} else {
|
|
|
|
$('.sonar', e_sensor_status).removeClass('on');
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
function have_sensor(sensors_detected, sensor_code) {
|
|
|
|
switch(sensor_code) {
|
|
|
|
case 'acc':
|
|
|
|
case 'gyro':
|
|
|
|
return bit_check(sensors_detected, 0);
|
|
|
|
case 'baro':
|
|
|
|
return bit_check(sensors_detected, 1);
|
|
|
|
case 'mag':
|
|
|
|
return bit_check(sensors_detected, 2);
|
|
|
|
case 'gps':
|
|
|
|
return bit_check(sensors_detected, 3);
|
|
|
|
case 'sonar':
|
|
|
|
return bit_check(sensors_detected, 4);
|
2013-12-24 18:17:59 +00:00
|
|
|
}
|
2015-02-23 21:27:55 +00:00
|
|
|
return false;
|
2013-04-08 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function highByte(num) {
|
|
|
|
return num >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
function lowByte(num) {
|
|
|
|
return 0x00FF & num;
|
|
|
|
}
|
|
|
|
|
2014-09-16 17:26:06 +00:00
|
|
|
function specificByte(num, pos) {
|
|
|
|
return 0x000000FF & (num >> (8 * pos));
|
|
|
|
}
|
|
|
|
|
2013-04-08 18:07:47 +00:00
|
|
|
function bit_check(num, bit) {
|
2013-12-12 16:10:10 +00:00
|
|
|
return ((num >> bit) % 2 != 0);
|
2013-04-10 13:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bit_set(num, bit) {
|
|
|
|
return num | 1 << bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function bit_clear(num, bit) {
|
|
|
|
return num & ~(1 << bit);
|
2015-10-23 14:00:03 +00:00
|
|
|
}
|