betaflight-configurator/tabs/initial_setup.js

246 lines
11 KiB
JavaScript
Raw Normal View History

2013-04-08 19:10:47 +00:00
function tab_initialize_initial_setup() {
2013-08-26 13:16:49 +00:00
ga_tracker.sendAppView('Initial Setup');
GUI.active_tab = 'initial_setup';
2014-03-08 05:25:15 +00:00
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, function() {
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, function() {
$('#content').load("./tabs/initial_setup.html", function() {
var yaw_fix = 0.0;
2014-03-08 05:25:15 +00:00
// Fill in misc stuff
$('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage);
$('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage);
$('input[name="voltagescale"]').val(MISC.vbatscale);
2014-03-08 05:25:15 +00:00
$('input[name="minthrottle"]').val(MISC.minthrottle);
$('input[name="maxthrottle"]').val(MISC.maxthrottle);
$('input[name="failsafe_throttle"]').val(MISC.failsafe_throttle);
$('input[name="mincommand"]').val(MISC.mincommand);
2014-03-08 05:25:15 +00:00
$('input[name="mag_declination"]').val(MISC.mag_declination / 10);
2014-03-08 05:25:15 +00:00
// Fill in the accel trimms from CONFIG object
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
2014-03-08 05:25:15 +00:00
// Display multiType
var str = '';
switch (CONFIG.multiType) {
case 1: // TRI
str = 'TRI';
break;
case 2: // QUAD +
str = 'Quad +';
break;
case 3: // QUAD X
str = 'Quad X';
break;
case 4: // BI
str = 'BI';
break;
case 5: // GIMBAL
str = 'Gimbal';
break;
case 6: // Y6
str = 'Y6';
break;
case 7: // HEX 6
str = 'HEX 6';
break;
case 8: // FLYING_WING
str = 'Flying Wing';
break;
case 9: // Y4
str = 'Y4';
break;
case 10: // HEX6 X
str = 'HEX6 X';
break;
case 11: // OCTO X8
case 12:
case 13:
str = 'OCTO X8';
break;
case 14: // AIRPLANE
str = 'Airplane';
break;
2014-03-08 05:25:15 +00:00
case 15: // Heli 120
str = 'Heli 120';
break;
2014-03-08 05:25:15 +00:00
case 16: // Heli 90
str = 'Heli 90';
break;
2014-03-08 05:25:15 +00:00
case 17: // Vtail
str = 'Vtail';
break;
case 18: // HEX6 H
str = 'HEX6 H';
break;
case 19: // PPM to SERVO
str = 'PPM to SERVO';
break;
case 20: // Dualcopter
str = 'Dualcopter';
break;
case 21: //
str = 'Singlecopter';
break;
}
2014-03-08 05:25:15 +00:00
$('span.model').html('Model: ' + str);
2014-03-08 05:25:15 +00:00
// UI Hooks
$('a.calibrateAccel').click(function() {
var self = $(this);
2014-03-08 05:25:15 +00:00
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
2014-03-08 05:25:15 +00:00
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
GUI.interval_pause('initial_setup_data_pull');
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION, false, function() {
GUI.log('Accelerometer calibration started');
});
2014-03-08 05:25:15 +00:00
GUI.timeout_add('button_reset', function() {
GUI.interval_resume('initial_setup_data_pull');
2014-03-08 05:25:15 +00:00
GUI.log('Accelerometer calibration finished');
2014-03-08 05:25:15 +00:00
self.removeClass('calibrating');
}, 2000);
}
});
2014-03-08 05:25:15 +00:00
$('a.calibrateMag').click(function() {
var self = $(this);
2014-03-08 05:25:15 +00:00
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
2014-03-08 05:25:15 +00:00
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION, false, function() {
GUI.log('Magnetometer calibration started');
});
2014-03-08 05:25:15 +00:00
GUI.timeout_add('button_reset', function() {
GUI.log('Magnetometer calibration finished');
self.removeClass('calibrating');
}, 30000);
}
});
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF, false, function() {
GUI.log('Settings restored to <strong>default</strong>');
2014-03-08 05:25:15 +00:00
GUI.tab_switch_cleanup(function() {
tab_initialize_initial_setup();
});
});
});
2014-03-08 05:25:15 +00:00
$('a.update').click(function() {
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
2014-03-08 05:25:15 +00:00
var buffer_out = new Array();
buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]);
buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]);
buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]);
2014-03-08 05:25:15 +00:00
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
2014-03-08 05:25:15 +00:00
MISC.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()) * 10;
MISC.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()) * 10;
MISC.vbatscale = parseInt($('input[name="voltagescale"]').val());
2014-03-08 05:25:15 +00:00
MISC.minthrottle = parseInt($('input[name="minthrottle"]').val());
MISC.maxthrottle = parseInt($('input[name="maxthrottle"]').val());
MISC.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val());
MISC.mincommand = parseInt($('input[name="mincommand"]').val());
2014-03-08 05:25:15 +00:00
MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val()) * 10;
2014-03-08 05:25:15 +00:00
// we also have to fill the unsupported bytes
var buffer_out = new Array();
buffer_out[0] = 0; // powerfailmeter
buffer_out[1] = 0;
buffer_out[2] = lowByte(MISC.minthrottle);
buffer_out[3] = highByte(MISC.minthrottle);
buffer_out[4] = lowByte(MISC.maxthrottle);
buffer_out[5] = highByte(MISC.maxthrottle);
buffer_out[6] = lowByte(MISC.mincommand);
buffer_out[7] = highByte(MISC.mincommand);
buffer_out[8] = lowByte(MISC.failsafe_throttle);
buffer_out[9] = highByte(MISC.failsafe_throttle);
buffer_out[10] = 0;
buffer_out[11] = 0;
buffer_out[12] = 0;
buffer_out[13] = 0;
buffer_out[14] = 0;
buffer_out[15] = 0;
buffer_out[16] = lowByte(MISC.mag_declination);
buffer_out[17] = highByte(MISC.mag_declination);
buffer_out[18] = MISC.vbatscale;
buffer_out[19] = MISC.vbatmincellvoltage;
buffer_out[20] = MISC.vbatmaxcellvoltage;
buffer_out[21] = 0; // vbatlevel_crit (unused)
2014-03-08 05:25:15 +00:00
// Send over new misc
send_message(MSP_codes.MSP_SET_MISC, buffer_out);
2014-03-08 05:25:15 +00:00
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE, false, function() {
GUI.log('EEPROM <span style="color: green">saved</span>');
2014-03-08 05:25:15 +00:00
var element = $('a.update');
element.addClass('success');
2014-03-08 05:25:15 +00:00
GUI.timeout_add('success_highlight', function() {
element.removeClass('success');
}, 2000);
});
2014-03-08 05:25:15 +00:00
});
2013-04-11 11:16:51 +00:00
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {
yaw_fix = SENSOR_DATA.kinematicsZ * - 1.0;
console.log("YAW reset to 0");
2014-03-08 05:25:15 +00:00
});
2013-12-15 01:28:12 +00:00
$('#content .backup').click(configuration_backup);
2014-03-08 05:25:15 +00:00
$('#content .restore').click(configuration_restore);
2014-03-08 05:25:15 +00:00
GUI.interval_add('initial_setup_data_pull', function() {
// Update voltage indicator
$('.bat-voltage').html(ANALOG.voltage + ' V');
2014-03-08 05:25:15 +00:00
// Request new data, if transmission fails it doesn't matter as new transmission will be requested after 50ms
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS, false, function() { // cycle time, active sensors, etc...
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG, false, function() { // battery voltage
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE, false, function() { // kinematics
// Update cube
var cube = $('div#cube');
2014-03-08 05:25:15 +00:00
cube.css('-webkit-transform', 'rotateY(' + ((SENSOR_DATA.kinematicsZ * -1.0) - yaw_fix) + 'deg)');
$('#cubePITCH', cube).css('-webkit-transform', 'rotateX(' + SENSOR_DATA.kinematicsY + 'deg)');
2014-03-08 05:25:15 +00:00
$('#cubeROLL', cube).css('-webkit-transform', 'rotateZ(' + SENSOR_DATA.kinematicsX + 'deg)');
/*
// Update Compass
2014-03-08 05:25:15 +00:00
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '&deg;');
*/
});
});
2014-03-08 05:25:15 +00:00
});
}, 50, true);
});
2013-12-15 01:28:12 +00:00
});
});
2013-04-08 19:10:47 +00:00
}