1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 00:05:33 +03:00

Avoid using GPS commands for targets that do not have GPS support

compiled in.
This commit is contained in:
Dominic Clifton 2015-02-23 21:27:55 +00:00
parent 831e4a848e
commit 7bdd010eb0
3 changed files with 81 additions and 45 deletions

View file

@ -247,44 +247,67 @@ function sensor_status(sensors_detected) {
} }
// update UI (if necessary) // update UI (if necessary)
if (sensor_status.previous_sensors_detected != sensors_detected) { if (sensor_status.previous_sensors_detected == sensors_detected) {
var e_sensor_status = $('div#sensor-status'); return;
if (bit_check(sensors_detected, 0)) { // Gyroscope & accel detected
$('.gyro', e_sensor_status).addClass('on');
$('.accel', e_sensor_status).addClass('on');
} else {
$('.gyro', e_sensor_status).removeClass('on');
$('.accel', e_sensor_status).removeClass('on');
}
if (bit_check(sensors_detected, 1)) { // Barometer detected
$('.baro', e_sensor_status).addClass('on');
} else {
$('.baro', e_sensor_status).removeClass('on');
}
if (bit_check(sensors_detected, 2)) { // Magnetometer detected
$('.mag', e_sensor_status).addClass('on');
} else {
$('.mag', e_sensor_status).removeClass('on');
}
if (bit_check(sensors_detected, 3)) { // GPS detected
$('.gps', e_sensor_status).addClass('on');
} else {
$('.gps', e_sensor_status).removeClass('on');
}
if (bit_check(sensors_detected, 4)) { // Sonar detected
$('.sonar', e_sensor_status).addClass('on');
} else {
$('.sonar', e_sensor_status).removeClass('on');
}
// set current value
sensor_status.previous_sensors_detected = sensors_detected;
} }
// set current value
sensor_status.previous_sensors_detected = sensors_detected;
var e_sensor_status = $('div#sensor-status');
if (have_sensor(sensors_detected, 'acc')) {
$('.accel', e_sensor_status).addClass('on');
} else {
$('.accel', e_sensor_status).removeClass('on');
}
if (have_sensor(sensors_detected, 'gyro')) {
$('.gyro', e_sensor_status).addClass('on');
} else {
$('.gyro', e_sensor_status).removeClass('on');
}
if (have_sensor(sensors_detected, 'baro')) {
$('.baro', e_sensor_status).addClass('on');
} else {
$('.baro', e_sensor_status).removeClass('on');
}
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');
}
}
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);
}
return false;
} }
function highByte(num) { function highByte(num) {

View file

@ -13,7 +13,7 @@ TABS.gps.initialize = function (callback) {
$('#content').load("./tabs/gps.html", process_html); $('#content').load("./tabs/gps.html", process_html);
} }
MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, load_html); MSP.send_message(MSP_codes.MSP_STATUS, false, false, load_html);
function process_html() { function process_html() {
// translate to user-selected language // translate to user-selected language
@ -57,7 +57,14 @@ TABS.gps.initialize = function (callback) {
} }
// enable data pulling // enable data pulling
GUI.interval_add('gps_pull', get_raw_gps_data, 75, true); 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 // status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() { GUI.interval_add('status_pull', function status_pull() {

View file

@ -163,12 +163,14 @@ TABS.setup.initialize = function (callback) {
rssi_e.text(chrome.i18n.getMessage('initialSetupRSSIValue', [((ANALOG.rssi / 1023) * 100).toFixed(0)])); rssi_e.text(chrome.i18n.getMessage('initialSetupRSSIValue', [((ANALOG.rssi / 1023) * 100).toFixed(0)]));
}); });
MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, function () { if (have_sensor(CONFIG.activeSensors, 'gps')) {
gpsFix_e.html((GPS_DATA.fix) ? chrome.i18n.getMessage('gpsFixTrue') : chrome.i18n.getMessage('gpsFixFalse')); MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, function () {
gpsSats_e.text(GPS_DATA.numSat); gpsFix_e.html((GPS_DATA.fix) ? chrome.i18n.getMessage('gpsFixTrue') : chrome.i18n.getMessage('gpsFixFalse'));
gpsLat_e.text((GPS_DATA.lat / 10000000).toFixed(4) + ' deg'); gpsSats_e.text(GPS_DATA.numSat);
gpsLon_e.text((GPS_DATA.lon / 10000000).toFixed(4) + ' deg'); gpsLat_e.text((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
}); gpsLon_e.text((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
});
}
} }
function get_fast_data() { function get_fast_data() {
@ -269,6 +271,10 @@ TABS.setup.initialize3D = function (compatibility) {
scene.add(modelWrapper); scene.add(modelWrapper);
this.render3D = function () { this.render3D = function () {
if (!model) {
return;
}
// compute the changes // compute the changes
model.rotation.x = (SENSOR_DATA.kinematics[1] * -1.0) * 0.017453292519943295; model.rotation.x = (SENSOR_DATA.kinematics[1] * -1.0) * 0.017453292519943295;
modelWrapper.rotation.y = ((SENSOR_DATA.kinematics[2] * -1.0) - self.yaw_fix) * 0.017453292519943295; modelWrapper.rotation.y = ((SENSOR_DATA.kinematics[2] * -1.0) - self.yaw_fix) * 0.017453292519943295;