1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-16 21:05:30 +03:00

added MSP support for sensor orientation, some fixes for 3D backup and restore

This commit is contained in:
NightHawk32 2015-12-14 18:06:25 -05:00
parent 1c671f26bf
commit 067999c5e8
5 changed files with 98 additions and 7 deletions

View file

@ -105,6 +105,9 @@ function configuration_backup(callback) {
if (semver.gte(CONFIG.apiVersion, "1.14.0")) { if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
uniqueData.push(MSP_codes.MSP_3D); uniqueData.push(MSP_codes.MSP_3D);
} }
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
uniqueData.push(MSP_codes.MSP_SENSOR_ALIGNMENT);
}
} }
update_unique_data_list(); update_unique_data_list();
@ -132,6 +135,9 @@ function configuration_backup(callback) {
if (semver.gte(CONFIG.apiVersion, "1.14.0")) { if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
configuration._3D = jQuery.extend(true, {}, _3D); configuration._3D = jQuery.extend(true, {}, _3D);
} }
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
configuration.SENSOR_ALIGNMENT = jQuery.extend(true, {}, SENSOR_ALIGNMENT);
}
save(); save();
} }
@ -513,8 +519,9 @@ function configuration_restore(callback) {
appliedMigrationsCount++; appliedMigrationsCount++;
} }
if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) { if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) {
// api 1.14 exposes deadband and yaw_deadband // api 1.15 exposes RCcontrols and sensor alignment
for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) {
@ -527,6 +534,13 @@ function configuration_restore(callback) {
}; };
} }
} }
if (configuration.SENSOR_ALIGNMENT == undefined) {
configuration.SENSOR_ALIGNMENT = {
align_gyro: 0,
align_acc: 0,
align_mag: 0
};
}
appliedMigrationsCount++; appliedMigrationsCount++;
} }
@ -645,6 +659,9 @@ function configuration_restore(callback) {
if (semver.gte(CONFIG.apiVersion, "1.14.0")) { if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
uniqueData.push(MSP_codes.MSP_SET_3D); uniqueData.push(MSP_codes.MSP_SET_3D);
} }
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
uniqueData.push(MSP_codes.MSP_SET_SENSOR_ALIGNMENT);
}
} }
function load_objects() { function load_objects() {
@ -656,6 +673,7 @@ function configuration_restore(callback) {
ARMING_CONFIG = configuration.ARMING_CONFIG; ARMING_CONFIG = configuration.ARMING_CONFIG;
FC_CONFIG = configuration.FC_CONFIG; FC_CONFIG = configuration.FC_CONFIG;
_3D = configuration._3D; _3D = configuration._3D;
SENSOR_ALIGNMENT = configuration.SENSOR_ALIGNMENT;
} }
function send_unique_data_item() { function send_unique_data_item() {

View file

@ -185,3 +185,9 @@ var RC_controls = {
alt_hold_deadband: 0, alt_hold_deadband: 0,
alt_hold_fast_change: 0 alt_hold_fast_change: 0
}; };
var SENSOR_ALIGNMENT = {
align_gyro: 0,
align_acc: 0,
align_mag: 0
};

View file

@ -54,6 +54,7 @@ var MSP_codes = {
MSP_SERVO_CONFIGURATIONS: 120, MSP_SERVO_CONFIGURATIONS: 120,
MSP_3D: 124, MSP_3D: 124,
MSP_RC_CONTROLS: 125, MSP_RC_CONTROLS: 125,
MSP_SENSOR_ALIGNMENT: 126,
MSP_SET_RAW_RC: 200, MSP_SET_RAW_RC: 200,
MSP_SET_RAW_GPS: 201, MSP_SET_RAW_GPS: 201,
@ -72,6 +73,7 @@ var MSP_codes = {
MSP_SET_3D: 217, MSP_SET_3D: 217,
MSP_SET_RC_CONTROLS: 218, MSP_SET_RC_CONTROLS: 218,
MSP_SET_RESET_CURR_PID: 219, MSP_SET_RESET_CURR_PID: 219,
MSP_SET_SENSOR_ALIGNMENT: 220,
// MSP_BIND: 240, // MSP_BIND: 240,
@ -524,6 +526,12 @@ var MSP = {
RC_controls.alt_hold_deadband = data.getUint8(offset++, 1); RC_controls.alt_hold_deadband = data.getUint8(offset++, 1);
RC_controls.alt_hold_fast_change = data.getUint8(offset++, 1); RC_controls.alt_hold_fast_change = data.getUint8(offset++, 1);
break; break;
case MSP_codes.MSP_SENSOR_ALIGNMENT:
var offset = 0;
SENSOR_ALIGNMENT.align_gyro = data.getUint8(offset++, 1);
SENSOR_ALIGNMENT.align_acc = data.getUint8(offset++, 1);
SENSOR_ALIGNMENT.align_mag = data.getUint8(offset++, 1);
break;
case MSP_codes.MSP_SET_RAW_RC: case MSP_codes.MSP_SET_RAW_RC:
break; break;
case MSP_codes.MSP_SET_RAW_GPS: case MSP_codes.MSP_SET_RAW_GPS:
@ -863,6 +871,12 @@ var MSP = {
case MSP_codes.MSP_SET_RESET_CURR_PID: case MSP_codes.MSP_SET_RESET_CURR_PID:
console.log('Current PID profile reset'); console.log('Current PID profile reset');
break; break;
case MSP_codes.MSP_SET_3D:
console.log('3D settings saved');
break;
case MSP_codes.MSP_SET_SENSOR_ALIGNMENT:
console.log('Sensor alignment saved');
break;
default: default:
console.log('Unknown code detected: ' + code); console.log('Unknown code detected: ' + code);
@ -1175,6 +1189,12 @@ MSP.crunch = function (code) {
buffer.push(RC_controls.alt_hold_fast_change); buffer.push(RC_controls.alt_hold_fast_change);
break; break;
case MSP_codes.MSP_SET_SENSOR_ALIGNMENT:
buffer.push(SENSOR_ALIGNMENT.align_gyro);
buffer.push(SENSOR_ALIGNMENT.align_acc);
buffer.push(SENSOR_ALIGNMENT.align_mag);
break
default: default:
return false; return false;
} }

View file

@ -132,19 +132,19 @@
<div class="sensoralignment" style="width:40%; float:left;"> <div class="sensoralignment" style="width:40%; float:left;">
<div class="number"> <div class="number">
<select class="gyroalign"> <select class="gyroalign">
<option>Gyro Alignment</option> <option value="0">Gyro Alignment</option>
<!-- list generated here --> <!-- list generated here -->
</select> </select>
</div> </div>
<div class="number"> <div class="number">
<select class="accalign"> <select class="accalign">
<option>Acc Alignment</option> <option value="0">Acc Alignment</option>
<!-- list generated here --> <!-- list generated here -->
</select> </select>
</div> </div>
<div class="number"> <div class="number">
<select class="magalign"> <select class="magalign">
<option>Mag Alignment</option> <option value="0">Mag Alignment</option>
<!-- list generated here --> <!-- list generated here -->
</select> </select>
</div> </div>

View file

@ -54,13 +54,22 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
} }
function load_3d() { function load_3d() {
var next_callback = load_html; var next_callback = load_sensor_alignment;
if (semver.lt(CONFIG.apiVersion, "1.14.0")) { if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
MSP.send_message(MSP_codes.MSP_3D, false, false, next_callback); MSP.send_message(MSP_codes.MSP_3D, false, false, next_callback);
} else { } else {
next_callback(); next_callback();
} }
} }
function load_sensor_alignment() {
var next_callback = load_html;
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_ALIGNMENT, false, false, next_callback);
} else {
next_callback();
}
}
function load_html() { function load_html() {
$('#content').load("./tabs/configuration.html", process_html); $('#content').load("./tabs/configuration.html", process_html);
@ -193,6 +202,35 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}); });
} }
var alignments = [
'CW0',
'CW90',
'CW180',
'CW270',
'CW0FLIP',
'CW90FLIP',
'CW180FLIP',
'CW270FLIP'
];
if (semver.lt(CONFIG.apiVersion, "1.15.0")) {
$('.tab-configuration .sensoralignment').hide();
} else {
var orientation_gyro_e = $('select.gyroalign');
var orientation_acc_e = $('select.accalign');
var orientation_mag_e = $('select.magalign');
for (var i = 0; i < alignments.length; i++) {
orientation_gyro_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
orientation_acc_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
orientation_mag_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
}
orientation_gyro_e.val(SENSOR_ALIGNMENT.align_gyro);
orientation_acc_e.val(SENSOR_ALIGNMENT.align_acc);
orientation_mag_e.val(SENSOR_ALIGNMENT.align_mag);
}
// generate GPS // generate GPS
var gpsProtocols = [ var gpsProtocols = [
'NMEA', 'NMEA',
@ -216,6 +254,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
'Indian GAGAN' 'Indian GAGAN'
]; ];
var gps_protocol_e = $('select.gps_protocol'); var gps_protocol_e = $('select.gps_protocol');
for (var i = 0; i < gpsProtocols.length; i++) { for (var i = 0; i < gpsProtocols.length; i++) {
gps_protocol_e.append('<option value="' + i + '">' + gpsProtocols[i] + '</option>'); gps_protocol_e.append('<option value="' + i + '">' + gpsProtocols[i] + '</option>');
@ -422,6 +461,10 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
_3D.neutral3d = parseInt($('input[name="3dneutral"]').val()); _3D.neutral3d = parseInt($('input[name="3dneutral"]').val());
_3D.deadband3d_throttle = ($('input[name="3ddeadbandthrottle"]').val()); _3D.deadband3d_throttle = ($('input[name="3ddeadbandthrottle"]').val());
SENSOR_ALIGNMENT.align_gyro = parseInt(orientation_gyro_e.val());
SENSOR_ALIGNMENT.align_acc = parseInt(orientation_acc_e.val());
SENSOR_ALIGNMENT.align_mag = parseInt(orientation_mag_e.val());
function save_serial_config() { function save_serial_config() {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) { if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc); MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc);
@ -435,7 +478,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
} }
function save_3d() { function save_3d() {
MSP.send_message(MSP_codes.MSP_SET_3D, MSP.crunch(MSP_codes.MSP_SET_3D), false, save_acc_trim); MSP.send_message(MSP_codes.MSP_SET_3D, MSP.crunch(MSP_codes.MSP_SET_3D), false, save_sensor_alignment);
}
function save_sensor_alignment() {
MSP.send_message(MSP_codes.MSP_SET_SENSOR_ALIGNMENT, MSP.crunch(MSP_codes.MSP_SET_SENSOR_ALIGNMENT), false, save_acc_trim);
} }
function save_acc_trim() { function save_acc_trim() {