2016-07-23 14:46:47 +00:00
|
|
|
'use strict;'
|
|
|
|
|
|
|
|
var Features = function (config) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-07-23 14:46:47 +00:00
|
|
|
var features = [
|
|
|
|
{bit: 0, group: 'rxMode', mode: 'group', name: 'RX_PPM'},
|
|
|
|
{bit: 1, group: 'batteryVoltage', name: 'VBAT'},
|
|
|
|
{bit: 2, group: 'other', name: 'INFLIGHT_ACC_CAL'},
|
|
|
|
{bit: 3, group: 'rxMode', mode: 'group', name: 'RX_SERIAL'},
|
|
|
|
{bit: 4, group: 'esc', name: 'MOTOR_STOP'},
|
|
|
|
{bit: 5, group: 'other', name: 'SERVO_TILT'},
|
|
|
|
{bit: 6, group: 'other', name: 'SOFTSERIAL', haveTip: true},
|
|
|
|
{bit: 7, group: 'gps', name: 'GPS', haveTip: true},
|
|
|
|
{bit: 9, group: 'other', name: 'SONAR'},
|
|
|
|
{bit: 10, group: 'other', name: 'TELEMETRY'},
|
|
|
|
{bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'},
|
|
|
|
{bit: 12, group: 'other', name: '3D'},
|
|
|
|
{bit: 13, group: 'rxMode', mode: 'group', name: 'RX_PARALLEL_PWM'},
|
|
|
|
{bit: 14, group: 'rxMode', mode: 'group', name: 'RX_MSP'},
|
|
|
|
{bit: 15, group: 'rssi', name: 'RSSI_ADC'},
|
|
|
|
{bit: 16, group: 'other', name: 'LED_STRIP'},
|
|
|
|
{bit: 17, group: 'other', name: 'DISPLAY'},
|
|
|
|
{bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (semver.gte(config.apiVersion, "1.12.0")) {
|
|
|
|
features.push(
|
|
|
|
{bit: 20, group: 'other', name: 'CHANNEL_FORWARDING'}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-23 12:34:51 +00:00
|
|
|
if (semver.gte(config.apiVersion, "1.15.0")) {
|
|
|
|
features.push(
|
|
|
|
{bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
features.push(
|
|
|
|
{bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-23 14:46:47 +00:00
|
|
|
if (semver.gte(config.apiVersion, "1.16.0")) {
|
|
|
|
features.push(
|
|
|
|
{bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-04 09:57:39 +00:00
|
|
|
if (config.flightControllerVersion !== '' && semver.gte(config.flightControllerVersion, "3.0.0")) {
|
|
|
|
features.push(
|
|
|
|
{bit: 18, group: 'other', name: 'OSD', haveTip: true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-24 11:09:51 +00:00
|
|
|
if (config.flightControllerVersion !== '' && semver.gte(config.flightControllerVersion, "2.8.0")) {
|
2016-07-23 14:46:47 +00:00
|
|
|
features.push(
|
|
|
|
{bit: 22, group: 'other', name: 'AIRMODE'},
|
2016-08-04 12:00:41 +00:00
|
|
|
{bit: 23, group: 'pidTuning', name: 'SUPEREXPO_RATES'}
|
2016-07-23 14:46:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
self._features = features;
|
|
|
|
self._featureMask = 0;
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-24 11:09:51 +00:00
|
|
|
Features.prototype.getMask = function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
return self._featureMask;
|
2016-07-24 11:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Features.prototype.setMask = function (featureMask) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self._featureMask = featureMask;
|
2016-07-24 11:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Features.prototype.isEnabled = function (featureName) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
2016-07-24 11:09:51 +00:00
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
for (var i = 0; i < self._features.length; i++) {
|
|
|
|
if (self._features[i].name === featureName && bit_check(self._featureMask, self._features[i].bit)) {
|
2016-07-23 14:46:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-24 11:09:51 +00:00
|
|
|
Features.prototype.generateElements = function (featuresElements) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-07-24 11:09:51 +00:00
|
|
|
var radioGroups = [];
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
for (var i = 0; i < self._features.length; i++) {
|
2016-07-23 14:46:47 +00:00
|
|
|
var row_e;
|
|
|
|
|
|
|
|
var feature_tip_html = '';
|
2016-07-27 13:24:16 +00:00
|
|
|
if (self._features[i].haveTip) {
|
|
|
|
feature_tip_html = '<div class="helpicon cf_tip" i18n_title="feature' + self._features[i].name + 'Tip"></div>';
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
if (self._features[i].mode === 'group') {
|
2016-07-23 14:46:47 +00:00
|
|
|
row_e = $('<tr><td style="width: 15px;"><input style="width: 13px;" class="feature" id="feature-'
|
|
|
|
+ i
|
|
|
|
+ '" value="'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].bit
|
2016-07-23 14:46:47 +00:00
|
|
|
+ '" title="'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].name
|
2016-07-23 14:46:47 +00:00
|
|
|
+ '" type="radio" name="'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].group
|
2016-07-23 14:46:47 +00:00
|
|
|
+ '" /></td><td><label for="feature-'
|
|
|
|
+ i
|
|
|
|
+ '">'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].name
|
|
|
|
+ '</label></td><td><span i18n="feature' + self._features[i].name + '"></span>'
|
2016-07-23 14:46:47 +00:00
|
|
|
+ feature_tip_html + '</td></tr>');
|
2016-07-27 13:24:16 +00:00
|
|
|
radioGroups.push(self._features[i].group);
|
2016-07-23 14:46:47 +00:00
|
|
|
} else {
|
2016-07-24 11:09:51 +00:00
|
|
|
row_e = $('<tr><td><input class="feature toggle" id="feature-'
|
2016-07-23 14:46:47 +00:00
|
|
|
+ i
|
|
|
|
+ '" name="'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].name
|
2016-07-23 14:46:47 +00:00
|
|
|
+ '" title="'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].name
|
2016-07-23 14:46:47 +00:00
|
|
|
+ '" type="checkbox"/></td><td><label for="feature-'
|
|
|
|
+ i
|
|
|
|
+ '">'
|
2016-07-27 13:24:16 +00:00
|
|
|
+ self._features[i].name
|
|
|
|
+ '</label></td><td><span i18n="feature' + self._features[i].name + '"></span>'
|
2016-07-23 14:46:47 +00:00
|
|
|
+ feature_tip_html + '</td></tr>');
|
|
|
|
|
|
|
|
var feature_e = row_e.find('input.feature');
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
feature_e.prop('checked', bit_check(self._featureMask, self._features[i].bit));
|
|
|
|
feature_e.data('bit', self._features[i].bit);
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
featuresElements.each(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
if ($(this).hasClass(self._features[i].group)) {
|
2016-07-23 14:46:47 +00:00
|
|
|
$(this).append(row_e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-24 11:09:51 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < radioGroups.length; i++) {
|
|
|
|
var group = radioGroups[i];
|
|
|
|
var controlElements = $('input[name="' + group + '"].feature');
|
|
|
|
|
|
|
|
controlElements.each(function() {
|
|
|
|
var bit = parseInt($(this).attr('value'));
|
2016-07-27 13:24:16 +00:00
|
|
|
var state = bit_check(self._featureMask, bit);
|
2016-07-24 11:09:51 +00:00
|
|
|
|
|
|
|
$(this).prop('checked', state);
|
|
|
|
});
|
|
|
|
}
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-24 11:09:51 +00:00
|
|
|
Features.prototype.updateData = function (featureElement) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-07-23 14:46:47 +00:00
|
|
|
switch (featureElement.attr('type')) {
|
|
|
|
case 'checkbox':
|
|
|
|
var bit = featureElement.data('bit');
|
|
|
|
|
|
|
|
if (featureElement.is(':checked')) {
|
2016-07-27 13:24:16 +00:00
|
|
|
self._featureMask = bit_set(self._featureMask, bit);
|
2016-07-23 14:46:47 +00:00
|
|
|
} else {
|
2016-07-27 13:24:16 +00:00
|
|
|
self._featureMask = bit_clear(self._featureMask, bit);
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'radio':
|
|
|
|
var group = featureElement.attr('name');
|
|
|
|
var controlElements = $('input[name="' + group + '"]');
|
|
|
|
var selectedBit = controlElements.filter(':checked').val();
|
|
|
|
controlElements.each(function() {
|
|
|
|
var bit = $(this).val();
|
|
|
|
if (selectedBit === bit) {
|
2016-07-27 13:24:16 +00:00
|
|
|
self._featureMask = bit_set(self._featureMask, bit);
|
2016-07-23 14:46:47 +00:00
|
|
|
} else {
|
2016-07-27 13:24:16 +00:00
|
|
|
self._featureMask = bit_clear(self._featureMask, bit);
|
2016-07-23 14:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|