2014-09-17 08:31:36 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
TABS.configuration = {};
|
|
|
|
|
|
|
|
TABS.configuration.initialize = function (callback) {
|
|
|
|
var self = this;
|
|
|
|
GUI.active_tab_ref = this;
|
|
|
|
GUI.active_tab = 'configuration';
|
|
|
|
googleAnalytics.sendAppView('Configuration');
|
|
|
|
|
|
|
|
|
|
|
|
function check_compatibility() {
|
|
|
|
if (bit_check(CONFIG.capability, 30)) {
|
|
|
|
// new stuff supported, continue fetching configuration data
|
|
|
|
load_config();
|
|
|
|
} else {
|
|
|
|
// old version, deny access
|
|
|
|
$('#content').text('We are sorry, but advanced configuration is only available for boards with latest firmware, please update');
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_config() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_CONFIG, false, false, load_rc_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_rc_map() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RCMAP, false, false, load_misc);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_misc() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, load_acc_trim);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_acc_trim() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_ACC_TRIM, false, false, load_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/configuration.html", process_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, check_compatibility);
|
|
|
|
|
|
|
|
function process_html() {
|
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-09-17 12:22:16 +00:00
|
|
|
// generate mixer
|
|
|
|
var mixerList = [
|
|
|
|
{name: 'Tricopter', image: 'tri'},
|
2014-09-19 13:33:41 +00:00
|
|
|
{name: 'Quad +', image: 'quad_p'},
|
|
|
|
{name: 'Quad X', image: 'quad_x'},
|
2014-09-17 12:22:16 +00:00
|
|
|
{name: 'Bicopter', image: 'custom'},
|
|
|
|
{name: 'Gimbal', image: 'custom'},
|
2014-09-19 13:33:41 +00:00
|
|
|
{name: 'Y6', image: 'y6'},
|
|
|
|
{name: 'Hex +', image: 'hex_p'},
|
|
|
|
{name: 'Flying Wing', image: 'flying_wing'},
|
|
|
|
{name: 'Y4', image: 'y4'},
|
|
|
|
{name: 'Hex X', image: 'hex_x'},
|
|
|
|
{name: 'Octo X8', image: 'octo_x8'},
|
|
|
|
{name: 'Octo Flat +', image: 'custom'},
|
|
|
|
{name: 'Octo Flat X', image: 'octo_flat_x'},
|
2014-09-17 12:22:16 +00:00
|
|
|
{name: 'Airplane', image: 'airplane'},
|
|
|
|
{name: 'Heli 120', image: 'custom'},
|
|
|
|
{name: 'Heli 90', image: 'custom'},
|
2014-09-19 13:33:41 +00:00
|
|
|
{name: 'V-tail Quad', image: 'vtail_quad'},
|
|
|
|
{name: 'Hex H', image: 'custom'},
|
2014-09-17 12:22:16 +00:00
|
|
|
{name: 'PPM to SERVO', image: 'custom'},
|
|
|
|
{name: 'Dualcopter', image: 'custom'},
|
|
|
|
{name: 'Singlecopter', image: 'custom'},
|
|
|
|
{name: 'Custom', image: 'custom'}
|
|
|
|
];
|
|
|
|
|
|
|
|
var mixer_list_e = $('select.mixerList');
|
|
|
|
for (var i = 0; i < mixerList.length; i++) {
|
|
|
|
mixer_list_e.append('<option value="' + (i + 1) + '">' + mixerList[i].name + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
mixer_list_e.change(function () {
|
|
|
|
var val = parseInt($(this).val());
|
|
|
|
|
|
|
|
BF_CONFIG.mixerConfiguration = val;
|
|
|
|
|
|
|
|
$('.mixerPreview img').attr('src', './images/motor_order/' + mixerList[val - 1].image + '.svg');
|
|
|
|
});
|
|
|
|
|
2014-09-17 15:02:16 +00:00
|
|
|
// select current mixer configuration
|
2014-09-17 12:22:16 +00:00
|
|
|
mixer_list_e.val(BF_CONFIG.mixerConfiguration).change();
|
|
|
|
|
|
|
|
// generate features
|
2014-09-17 09:23:31 +00:00
|
|
|
var featureNames = [
|
2014-09-19 15:51:55 +00:00
|
|
|
{name: 'PPM', description: 'Enable PPM input (and disable PWM input)'},
|
|
|
|
{name: 'VBAT', description: 'Enable Battery voltage monitoring'},
|
|
|
|
{name: 'INFLIGHT_ACC_CAL', description: 'Enable in-flight level calibration'},
|
|
|
|
{name: 'SERIALRX', description: 'Enable Serial-based receiver (SPEKSAT, SBUS, SUMD)'},
|
|
|
|
{name: 'MOTOR_STOP', description: 'Don\'t spin the motors when armed'},
|
|
|
|
{name: 'SERVO_TILT', description: 'Enable servo gimbal'},
|
|
|
|
{name: 'SOFTSERIAL', description: 'Enable 3rd serial port'},
|
|
|
|
{name: 'LED_RING', description: 'Enable LED ring support'},
|
|
|
|
{name: 'GPS', description: 'Enable GPS (PPM or 3rd serial port required)'},
|
|
|
|
{name: 'FAILSAFE', description: 'Enable failsafe settings on PPM/PWM signal loss'},
|
|
|
|
{name: 'SONAR', description: 'Enable sonar'},
|
|
|
|
{name: 'TELEMETRY', description: 'Enable FrSky- compatible telemetry output'},
|
|
|
|
{name: 'POWERMETER', description: 'Enable battery current monitoring'},
|
|
|
|
{name: 'VARIO', description: 'Enable VARIO'},
|
|
|
|
{name: '3D', description: 'Enable 3D mode (for use with reversible ESCs)'}
|
2014-09-17 09:23:31 +00:00
|
|
|
];
|
|
|
|
|
2014-09-17 11:01:46 +00:00
|
|
|
var features_e = $('.features');
|
|
|
|
for (var i = 0; i < featureNames.length; i++) {
|
2014-09-19 15:51:55 +00:00
|
|
|
var element = $('<dt><input id="feature-' + i + '" title="' + featureNames[i].name + '" type="checkbox" /></dt><dd><label for="feature-' + i + '">' + featureNames[i].description + '</label></dd>');
|
2014-09-17 11:01:46 +00:00
|
|
|
element.find('input').attr('checked', bit_check(BF_CONFIG.features, i));
|
|
|
|
|
|
|
|
features_e.append(element);
|
|
|
|
}
|
|
|
|
|
2014-09-17 15:46:21 +00:00
|
|
|
// generate GPS
|
|
|
|
var gpsTypes = [
|
|
|
|
'NMEA',
|
|
|
|
'UBLOX',
|
|
|
|
'MTK_NMEA',
|
|
|
|
'MTK_BINARY',
|
|
|
|
'MAG_BINARY'
|
|
|
|
];
|
|
|
|
|
|
|
|
var gpsBauds = [
|
|
|
|
'115200',
|
|
|
|
'57600',
|
|
|
|
'38400',
|
|
|
|
'19200',
|
|
|
|
'9600'
|
|
|
|
];
|
|
|
|
|
|
|
|
var gpsSbas = [
|
|
|
|
'Auto-detect',
|
|
|
|
'European EGNOS',
|
|
|
|
'North American WAAS',
|
|
|
|
'Japanese MSAS',
|
|
|
|
'Indian GAGAN'
|
|
|
|
];
|
|
|
|
|
|
|
|
var gps_type_e = $('select.gps_type');
|
|
|
|
for (var i = 0; i < gpsTypes.length; i++) {
|
|
|
|
gps_type_e.append('<option value="' + i + '">' + gpsTypes[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
gps_type_e.change(function () {
|
2014-09-18 10:32:27 +00:00
|
|
|
MISC.gps_type = parseInt($(this).val());
|
2014-09-17 15:46:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var gps_baudrate_e = $('select.gps_baudrate');
|
|
|
|
for (var i = 0; i < gpsBauds.length; i++) {
|
|
|
|
gps_baudrate_e.append('<option value="' + i + '">' + gpsBauds[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
gps_baudrate_e.change(function () {
|
2014-09-18 10:32:27 +00:00
|
|
|
MISC.gps_baudrate = parseInt($(this).val());
|
2014-09-17 15:46:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var gps_ubx_sbas_e = $('select.gps_ubx_sbas');
|
|
|
|
for (var i = 0; i < gpsSbas.length; i++) {
|
|
|
|
gps_ubx_sbas_e.append('<option value="' + i + '">' + gpsSbas[i] + '</option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
gps_ubx_sbas_e.change(function () {
|
2014-09-18 10:32:27 +00:00
|
|
|
MISC.gps_ubx_sbas = parseInt($(this).val());
|
2014-09-17 15:46:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// select current gps configuration
|
|
|
|
gps_type_e.val(MISC.gps_type);
|
|
|
|
gps_baudrate_e.val(MISC.gps_baudrate);
|
|
|
|
gps_ubx_sbas_e.val(MISC.gps_ubx_sbas);
|
|
|
|
|
2014-09-17 15:02:16 +00:00
|
|
|
// generate serial RX
|
|
|
|
var serialRXtypes = [
|
|
|
|
'SPEKTRUM1024',
|
|
|
|
'SPEKTRUM2048',
|
|
|
|
'SBUS',
|
|
|
|
'SUMD'
|
|
|
|
];
|
|
|
|
|
|
|
|
var serialRX_e = $('select.serialRX');
|
|
|
|
for (var i = 0; i < serialRXtypes.length; i++) {
|
2014-09-17 15:46:21 +00:00
|
|
|
serialRX_e.append('<option value="' + i + '">' + serialRXtypes[i] + '</option>');
|
2014-09-17 15:02:16 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 15:46:21 +00:00
|
|
|
serialRX_e.change(function () {
|
2014-09-18 10:32:27 +00:00
|
|
|
BF_CONFIG.serialrx_type = parseInt($(this).val());
|
2014-09-17 15:02:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// select current serial RX type
|
|
|
|
serialRX_e.val(BF_CONFIG.serialrx_type);
|
|
|
|
|
2014-09-17 13:44:28 +00:00
|
|
|
// fill board alignment
|
|
|
|
$('input[name="board_align_roll"]').val(BF_CONFIG.board_align_roll);
|
|
|
|
$('input[name="board_align_pitch"]').val(BF_CONFIG.board_align_pitch);
|
|
|
|
$('input[name="board_align_yaw"]').val(BF_CONFIG.board_align_yaw);
|
|
|
|
|
|
|
|
// fill accel trims
|
|
|
|
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
|
2014-09-17 14:08:40 +00:00
|
|
|
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
|
2014-09-17 13:44:28 +00:00
|
|
|
|
|
|
|
// fill magnetometer
|
|
|
|
$('input[name="mag_declination"]').val(MISC.mag_declination / 10);
|
|
|
|
|
|
|
|
// fill throttle
|
2014-09-17 13:20:21 +00:00
|
|
|
$('input[name="minthrottle"]').val(MISC.minthrottle);
|
2014-09-17 18:13:13 +00:00
|
|
|
$('input[name="midthrottle"]').val(MISC.midrc);
|
2014-09-17 13:20:21 +00:00
|
|
|
$('input[name="maxthrottle"]').val(MISC.maxthrottle);
|
|
|
|
$('input[name="failsafe_throttle"]').val(MISC.failsafe_throttle);
|
|
|
|
$('input[name="mincommand"]').val(MISC.mincommand);
|
|
|
|
|
2014-09-17 13:44:28 +00:00
|
|
|
// fill battery
|
2014-09-17 13:20:21 +00:00
|
|
|
$('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage);
|
|
|
|
$('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage);
|
|
|
|
$('input[name="voltagescale"]').val(MISC.vbatscale);
|
2014-09-18 11:21:48 +00:00
|
|
|
|
|
|
|
// fill current
|
|
|
|
$('input[name="currentscale"]').val(BF_CONFIG.currentscale);
|
|
|
|
$('input[name="currentoffset"]').val(BF_CONFIG.currentoffset);
|
2014-09-18 10:24:38 +00:00
|
|
|
$('input[name="multiwiicurrentoutput"]').prop('checked', MISC.multiwiicurrentoutput);
|
2014-09-17 13:20:21 +00:00
|
|
|
|
2014-09-17 11:01:46 +00:00
|
|
|
|
|
|
|
// UI hooks
|
|
|
|
$('input', features_e).change(function () {
|
|
|
|
var element = $(this),
|
|
|
|
index = $('input', features_e).index(element),
|
|
|
|
state = element.is(':checked');
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
BF_CONFIG.features = bit_set(BF_CONFIG.features, index);
|
|
|
|
} else {
|
|
|
|
BF_CONFIG.features = bit_clear(BF_CONFIG.features, index);
|
|
|
|
}
|
|
|
|
});
|
2014-09-17 09:23:31 +00:00
|
|
|
|
2014-09-17 11:01:46 +00:00
|
|
|
$('a.save').click(function () {
|
2014-09-17 13:20:21 +00:00
|
|
|
// gather data that doesn't have automatic change event bound
|
2014-09-17 13:44:28 +00:00
|
|
|
BF_CONFIG.board_align_roll = parseInt($('input[name="board_align_roll"]').val());
|
|
|
|
BF_CONFIG.board_align_pitch = parseInt($('input[name="board_align_pitch"]').val());
|
|
|
|
BF_CONFIG.board_align_yaw = parseInt($('input[name="board_align_yaw"]').val());
|
|
|
|
|
|
|
|
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
|
2014-09-17 14:08:40 +00:00
|
|
|
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
|
2014-09-17 13:44:28 +00:00
|
|
|
MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val()) * 10;
|
2014-09-17 13:20:21 +00:00
|
|
|
|
|
|
|
MISC.minthrottle = parseInt($('input[name="minthrottle"]').val());
|
2014-09-17 18:13:13 +00:00
|
|
|
MISC.midrc = parseInt($('input[name="midthrottle"]').val());
|
2014-09-17 13:20:21 +00:00
|
|
|
MISC.maxthrottle = parseInt($('input[name="maxthrottle"]').val());
|
|
|
|
MISC.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val());
|
|
|
|
MISC.mincommand = parseInt($('input[name="mincommand"]').val());
|
|
|
|
|
2014-09-17 13:44:28 +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-09-18 11:21:48 +00:00
|
|
|
|
|
|
|
BF_CONFIG.currentscale = parseInt($('input[name="currentscale"]').val());
|
|
|
|
BF_CONFIG.currentoffset = parseInt($('input[name="currentoffset"]').val());
|
2014-09-18 10:24:38 +00:00
|
|
|
MISC.multiwiicurrentoutput = ~~$('input[name="multiwiicurrentoutput"]').is(':checked'); // ~~ boolean to decimal conversion
|
2014-09-17 13:44:28 +00:00
|
|
|
|
2014-09-17 13:20:21 +00:00
|
|
|
function save_misc() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_MISC, MSP.crunch(MSP_codes.MSP_SET_MISC), false, save_acc_trim);
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_acc_trim() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch(MSP_codes.MSP_SET_ACC_TRIM), false, save_to_eeprom);
|
|
|
|
}
|
|
|
|
|
2014-09-17 11:01:46 +00:00
|
|
|
function save_to_eeprom() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, reboot);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reboot() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
|
|
|
|
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_REBOOT, false, false, reinitialize);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reinitialize() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
|
|
|
|
|
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('deviceReady'));
|
|
|
|
TABS.configuration.initialize();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:20:21 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CONFIG), false, save_misc);
|
2014-09-17 11:01:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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-09-17 08:31:36 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TABS.configuration.cleanup = function (callback) {
|
|
|
|
if (callback) callback();
|
|
|
|
};
|