betaflight-configurator/tabs/gps.js

159 lines
4.7 KiB
JavaScript
Raw Normal View History

'use strict';
TABS.gps = {};
2014-08-12 14:05:22 +00:00
TABS.gps.initialize = function (callback) {
var self = this;
if (GUI.active_tab != 'gps') {
GUI.active_tab = 'gps';
}
2014-03-08 05:25:15 +00:00
function load_html() {
$('#content').load("./tabs/gps.html", process_html);
}
MSP.send_message(MSP_codes.MSP_STATUS, false, false, load_html);
2015-11-30 22:41:24 +00:00
function set_online(){
$('#connect').hide();
$('#waiting').show();
$('#loadmap').hide();
}
function set_offline(){
$('#connect').show();
$('#waiting').hide();
$('#loadmap').hide();
}
function process_html() {
2015-11-30 22:41:24 +00:00
// translate to user-selected languageconsole.log('Online');
localize();
function get_raw_gps_data() {
MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, get_comp_gps_data);
}
function get_comp_gps_data() {
MSP.send_message(MSP_codes.MSP_COMP_GPS, false, false, get_gpsvinfo_data);
}
function get_gpsvinfo_data() {
MSP.send_message(MSP_codes.MSP_GPS_SV_INFO, false, false, update_ui);
}
function update_ui() {
2014-05-20 19:01:44 +00:00
var lat = GPS_DATA.lat / 10000000;
var lon = GPS_DATA.lon / 10000000;
var url = 'https://maps.google.com/?q=' + lat + ',' + lon;
2014-05-08 08:56:41 +00:00
$('.GPS_info td.fix').html((GPS_DATA.fix) ? chrome.i18n.getMessage('gpsFixTrue') : chrome.i18n.getMessage('gpsFixFalse'));
2014-05-04 11:27:12 +00:00
$('.GPS_info td.alt').text(GPS_DATA.alt + ' m');
$('.GPS_info td.lat a').prop('href', url).text(lat.toFixed(4) + ' deg');
$('.GPS_info td.lon a').prop('href', url).text(lon.toFixed(4) + ' deg');
2014-05-04 11:27:12 +00:00
$('.GPS_info td.speed').text(GPS_DATA.speed + ' cm/s');
$('.GPS_info td.sats').text(GPS_DATA.numSat);
$('.GPS_info td.distToHome').text(GPS_DATA.distanceToHome + ' m');
// Update GPS Signal Strengths
var e_ss_table = $('div.GPS_signal_strength table tr:not(.titles)');
for (var i = 0; i < GPS_DATA.chn.length; i++) {
var row = e_ss_table.eq(i);
2014-05-04 11:27:12 +00:00
$('td', row).eq(0).text(GPS_DATA.svid[i]);
$('td', row).eq(1).text(GPS_DATA.quality[i]);
$('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]);
}
var message = {
action: 'center',
lat: lat,
lon: lon,
};
var frame = document.getElementById('map');
if (navigator.onLine) {
$('#connect').hide();
2015-12-02 21:30:09 +00:00
//if(lat != 0 && lon != 0){
if(GPS_DATA.fix){
frame.contentWindow.postMessage(message, '*');
$('#loadmap').show();
$('#waiting').hide();
}else{
$('#loadmap').hide();
$('#waiting').show();
}
}else{
$('#connect').show();
$('#waiting').hide();
$('#loadmap').hide();
}
}
// enable data pulling
GUI.interval_add('gps_pull', function gps_update() {
// avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support.
if (!have_sensor(CONFIG.activeSensors, 'gps')) {
//return;
}
get_raw_gps_data();
}, 75, true);
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
}, 250, true);
2014-07-10 16:27:04 +00:00
2015-11-30 22:41:24 +00:00
//check for internet connection on load
if (navigator.onLine) {
console.log('Online');
set_online();
2015-11-30 22:41:24 +00:00
} else {
console.log('Offline');
set_offline();
2015-11-30 22:41:24 +00:00
}
$("#check").on('click',function(){
if (navigator.onLine) {
console.log('Online');
set_online();
2015-11-30 22:41:24 +00:00
} else {
console.log('Offline');
set_offline();
2015-11-30 22:41:24 +00:00
}
});
var frame = document.getElementById('map');
$('#zoom_in').click(function() {
console.log('zoom in');
var message = {
action: 'zoom_in',
};
frame.contentWindow.postMessage(message, '*');
2015-11-30 22:41:24 +00:00
});
$('#zoom_out').click(function() {
console.log('zoom out');
var message = {
action: 'zoom_out'
};
frame.contentWindow.postMessage(message, '*');
2015-11-30 22:41:24 +00:00
});
GUI.content_ready(callback);
}
2014-07-10 16:27:04 +00:00
};
2014-08-12 14:05:22 +00:00
TABS.gps.cleanup = function (callback) {
2014-07-10 16:27:04 +00:00
if (callback) callback();
2016-06-16 05:25:11 +00:00
};