2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup = {
|
2014-07-10 17:23:16 +00:00
|
|
|
yaw_fix: 0.0
|
|
|
|
};
|
2014-08-12 14:05:22 +00:00
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.initialize = function (callback) {
|
2014-07-10 17:23:16 +00:00
|
|
|
var self = this;
|
2014-10-01 10:58:09 +00:00
|
|
|
|
2014-10-01 11:16:22 +00:00
|
|
|
if (GUI.active_tab != 'setup') {
|
|
|
|
GUI.active_tab = 'setup';
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-12-21 23:17:41 +00:00
|
|
|
function load_status() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, load_ident);
|
|
|
|
}
|
|
|
|
|
2014-05-07 01:01:59 +00:00
|
|
|
function load_ident() {
|
2014-12-21 23:17:41 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_config);
|
2014-09-16 17:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_config() {
|
2015-01-02 19:27:43 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_BF_CONFIG, false, false, load_misc_data);
|
2014-05-07 01:01:59 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function load_misc_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
2014-09-20 11:51:23 +00:00
|
|
|
$('#content').load("./tabs/setup.html", process_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 23:17:41 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ACC_TRIM, false, false, load_status);
|
2014-08-14 14:48:16 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, CONFIGURATOR.backupRestoreMinApiVersionAccepted)) {
|
2015-01-26 21:37:31 +00:00
|
|
|
$('#content .backup').addClass('disabled');
|
|
|
|
$('#content .restore').addClass('disabled');
|
2015-02-19 20:39:57 +00:00
|
|
|
|
2015-01-26 21:37:31 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupBackupAndRestoreApiVersion', [CONFIG.apiVersion, CONFIGURATOR.backupRestoreMinApiVersionAccepted]));
|
|
|
|
}
|
2016-06-28 18:20:41 +00:00
|
|
|
|
|
|
|
// initialize 3D Model
|
|
|
|
self.initModel();
|
2014-09-16 17:27:30 +00:00
|
|
|
|
2015-09-30 04:38:23 +00:00
|
|
|
// set roll in interactive block
|
|
|
|
$('span.roll').text(chrome.i18n.getMessage('initialSetupAttitude', [0]));
|
|
|
|
// set pitch in interactive block
|
|
|
|
$('span.pitch').text(chrome.i18n.getMessage('initialSetupAttitude', [0]));
|
2014-10-12 16:38:04 +00:00
|
|
|
// set heading in interactive block
|
2015-09-30 04:38:23 +00:00
|
|
|
$('span.heading').text(chrome.i18n.getMessage('initialSetupAttitude', [0]));
|
|
|
|
|
2016-07-22 11:12:37 +00:00
|
|
|
// check if we have accelerometer and magnetometer
|
2016-07-22 08:59:43 +00:00
|
|
|
if (!have_sensor(CONFIG.activeSensors, 'acc')) {
|
|
|
|
$('a.calibrateAccel').addClass('disabled');
|
|
|
|
$('default_btn').addClass('disabled');
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-07-22 11:12:37 +00:00
|
|
|
if (!have_sensor(CONFIG.activeSensors, 'mag')) {
|
2014-09-17 08:51:54 +00:00
|
|
|
$('a.calibrateMag').addClass('disabled');
|
2016-06-12 15:41:14 +00:00
|
|
|
$('default_btn').addClass('disabled');
|
2014-09-17 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 20:39:57 +00:00
|
|
|
self.initializeInstruments();
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI Hooks
|
2014-08-12 14:05:22 +00:00
|
|
|
$('a.calibrateAccel').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var self = $(this);
|
|
|
|
|
|
|
|
if (!self.hasClass('calibrating')) {
|
|
|
|
self.addClass('calibrating');
|
|
|
|
|
|
|
|
// 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
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.interval_pause('setup_data_pull');
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ACC_CALIBRATION, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupAccelCalibStarted'));
|
2016-04-19 23:38:23 +00:00
|
|
|
$('#accel_calib_running').show();
|
|
|
|
$('#accel_calib_rest').hide();
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
GUI.timeout_add('button_reset', function () {
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.interval_resume('setup_data_pull');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupAccelCalibEnded'));
|
2014-03-22 23:28:41 +00:00
|
|
|
self.removeClass('calibrating');
|
2016-04-19 23:38:23 +00:00
|
|
|
$('#accel_calib_running').hide();
|
|
|
|
$('#accel_calib_rest').show();
|
2014-03-22 23:28:41 +00:00
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
$('a.calibrateMag').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var self = $(this);
|
2014-01-13 16:43:22 +00:00
|
|
|
|
2014-09-17 08:51:54 +00:00
|
|
|
if (!self.hasClass('calibrating') && !self.hasClass('disabled')) {
|
2014-03-22 23:28:41 +00:00
|
|
|
self.addClass('calibrating');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MAG_CALIBRATION, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupMagCalibStarted'));
|
2016-04-19 23:38:23 +00:00
|
|
|
$('#mag_calib_running').show();
|
|
|
|
$('#mag_calib_rest').hide();
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2013-06-17 21:36:19 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
GUI.timeout_add('button_reset', function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupMagCalibEnded'));
|
2014-03-22 23:28:41 +00:00
|
|
|
self.removeClass('calibrating');
|
2016-04-19 23:38:23 +00:00
|
|
|
$('#mag_calib_running').hide();
|
|
|
|
$('#mag_calib_rest').show();
|
2014-03-22 23:28:41 +00:00
|
|
|
}, 30000);
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-10-06 14:07:47 +00:00
|
|
|
$('a.resetSettings').click(function () {
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RESET_CONF, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupSettingsRestored'));
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-10-06 14:07:47 +00:00
|
|
|
GUI.tab_switch_cleanup(function () {
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.initialize();
|
2014-03-08 05:25:15 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-10 17:23:16 +00:00
|
|
|
// display current yaw fix value (important during tab re-initialization)
|
|
|
|
$('div#interactive_block > a.reset').text(chrome.i18n.getMessage('initialSetupButtonResetZaxisValue', [self.yaw_fix]));
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// reset yaw button hook
|
2014-08-12 14:05:22 +00:00
|
|
|
$('div#interactive_block > a.reset').click(function () {
|
2014-07-10 17:23:16 +00:00
|
|
|
self.yaw_fix = SENSOR_DATA.kinematics[2] * - 1.0;
|
|
|
|
$(this).text(chrome.i18n.getMessage('initialSetupButtonResetZaxisValue', [self.yaw_fix]));
|
2014-07-06 09:24:18 +00:00
|
|
|
|
2014-07-10 17:23:16 +00:00
|
|
|
console.log('YAW reset to 0 deg, fix: ' + self.yaw_fix + ' deg');
|
2013-12-15 01:28:12 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-10-06 14:07:47 +00:00
|
|
|
$('#content .backup').click(function () {
|
2015-01-26 21:37:31 +00:00
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-06 14:07:47 +00:00
|
|
|
configuration_backup(function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupBackupSuccess'));
|
|
|
|
});
|
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-10-06 14:07:47 +00:00
|
|
|
$('#content .restore').click(function () {
|
2015-01-26 21:37:31 +00:00
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-06 14:07:47 +00:00
|
|
|
configuration_restore(function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupRestoreSuccess'));
|
|
|
|
|
|
|
|
// get latest settings
|
2014-10-12 16:00:44 +00:00
|
|
|
TABS.setup.initialize();
|
2014-10-06 14:07:47 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-10-19 13:29:55 +00:00
|
|
|
// cached elements
|
|
|
|
var bat_voltage_e = $('.bat-voltage'),
|
|
|
|
bat_mah_drawn_e = $('.bat-mah-drawn'),
|
|
|
|
bat_mah_drawing_e = $('.bat-mah-drawing'),
|
|
|
|
rssi_e = $('.rssi'),
|
|
|
|
gpsFix_e = $('.gpsFix'),
|
|
|
|
gpsSats_e = $('.gpsSats'),
|
|
|
|
gpsLat_e = $('.gpsLat'),
|
|
|
|
gpsLon_e = $('.gpsLon'),
|
2015-09-30 04:38:23 +00:00
|
|
|
roll_e = $('dd.roll'),
|
|
|
|
pitch_e = $('dd.pitch'),
|
|
|
|
heading_e = $('dd.heading');
|
2014-10-19 13:29:55 +00:00
|
|
|
|
|
|
|
function get_slow_data() {
|
2014-12-21 23:17:41 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS);
|
2015-02-19 20:39:57 +00:00
|
|
|
|
2014-10-19 13:29:55 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ANALOG, false, false, function () {
|
|
|
|
bat_voltage_e.text(chrome.i18n.getMessage('initialSetupBatteryValue', [ANALOG.voltage]));
|
|
|
|
bat_mah_drawn_e.text(chrome.i18n.getMessage('initialSetupBatteryMahValue', [ANALOG.mAhdrawn]));
|
|
|
|
bat_mah_drawing_e.text(chrome.i18n.getMessage('initialSetupBatteryAValue', [ANALOG.amperage.toFixed(2)]));
|
|
|
|
rssi_e.text(chrome.i18n.getMessage('initialSetupRSSIValue', [((ANALOG.rssi / 1023) * 100).toFixed(0)]));
|
|
|
|
});
|
2014-09-18 10:54:59 +00:00
|
|
|
|
2015-02-23 21:27:55 +00:00
|
|
|
if (have_sensor(CONFIG.activeSensors, 'gps')) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, function () {
|
|
|
|
gpsFix_e.html((GPS_DATA.fix) ? chrome.i18n.getMessage('gpsFixTrue') : chrome.i18n.getMessage('gpsFixFalse'));
|
|
|
|
gpsSats_e.text(GPS_DATA.numSat);
|
|
|
|
gpsLat_e.text((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
|
|
|
|
gpsLon_e.text((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
|
|
|
|
});
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 13:29:55 +00:00
|
|
|
function get_fast_data() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_ATTITUDE, false, false, function () {
|
2015-09-30 04:38:23 +00:00
|
|
|
roll_e.text(chrome.i18n.getMessage('initialSetupAttitude', [SENSOR_DATA.kinematics[0]]));
|
|
|
|
pitch_e.text(chrome.i18n.getMessage('initialSetupAttitude', [SENSOR_DATA.kinematics[1]]));
|
|
|
|
heading_e.text(chrome.i18n.getMessage('initialSetupAttitude', [SENSOR_DATA.kinematics[2]]));
|
2016-06-28 18:20:41 +00:00
|
|
|
|
|
|
|
self.renderModel();
|
2015-02-20 01:52:09 +00:00
|
|
|
self.updateInstruments();
|
2014-10-19 13:29:55 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 13:29:55 +00:00
|
|
|
GUI.interval_add('setup_data_pull_fast', get_fast_data, 33, true); // 30 fps
|
|
|
|
GUI.interval_add('setup_data_pull_slow', get_slow_data, 250, true); // 4 fps
|
2014-07-10 16:14:26 +00:00
|
|
|
|
2015-11-11 21:01:22 +00:00
|
|
|
GUI.content_ready(callback);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:14:26 +00:00
|
|
|
};
|
|
|
|
|
2015-02-19 20:39:57 +00:00
|
|
|
TABS.setup.initializeInstruments = function() {
|
|
|
|
var options = {size:90, showBox : false, img_directory: 'images/flightindicators/'};
|
|
|
|
var attitude = $.flightIndicator('#attitude', 'attitude', options);
|
|
|
|
var heading = $.flightIndicator('#heading', 'heading', options);
|
|
|
|
|
|
|
|
this.updateInstruments = function() {
|
|
|
|
attitude.setRoll(SENSOR_DATA.kinematics[0]);
|
|
|
|
attitude.setPitch(SENSOR_DATA.kinematics[1]);
|
2015-02-20 01:52:09 +00:00
|
|
|
heading.setHeading(SENSOR_DATA.kinematics[2]);
|
2015-02-19 20:39:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-06-28 18:20:41 +00:00
|
|
|
TABS.setup.initModel = function () {
|
|
|
|
this.model = new Model($('.model-and-info #canvas_wrapper'), $('.model-and-info #canvas'));
|
2014-09-24 11:45:38 +00:00
|
|
|
|
2016-06-28 18:20:41 +00:00
|
|
|
$(window).on('resize', $.proxy(this.model.resize, this.model));
|
|
|
|
};
|
2014-09-13 23:27:50 +00:00
|
|
|
|
2016-06-28 18:20:41 +00:00
|
|
|
TABS.setup.renderModel = function () {
|
|
|
|
var x = (SENSOR_DATA.kinematics[1] * -1.0) * 0.017453292519943295,
|
|
|
|
y = ((SENSOR_DATA.kinematics[2] * -1.0) - this.yaw_fix) * 0.017453292519943295,
|
|
|
|
z = (SENSOR_DATA.kinematics[0] * -1.0) * 0.017453292519943295;
|
2014-10-06 17:16:48 +00:00
|
|
|
|
2016-06-28 18:20:41 +00:00
|
|
|
this.model.rotateTo(x, y, z);
|
2014-09-13 23:27:50 +00:00
|
|
|
};
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.cleanup = function (callback) {
|
2016-07-26 14:46:13 +00:00
|
|
|
if (this.model) {
|
|
|
|
$(window).off('resize', $.proxy(this.model.resize, this.model));
|
|
|
|
}
|
2014-09-13 23:27:50 +00:00
|
|
|
|
2014-07-10 16:14:26 +00:00
|
|
|
if (callback) callback();
|
2014-10-31 12:32:40 +00:00
|
|
|
};
|