Allow toggling OSD stats

10.3.x-maintenance
Dan Nixon 2017-05-22 18:10:32 +01:00
parent a5c4afa8a2
commit 75a16aae17
2 changed files with 117 additions and 6 deletions

View File

@ -71,6 +71,16 @@
<div class="alarms"></div>
</div>
</div>
<div class="gui_box grey stats-container requires-osd-feature" style="display:none;">
<div class="gui_box_titlebar">
<div class="spacer_box_title">
Post Flight Status
</div>
</div>
<div class="spacer_box">
<div class="post-flight-stats"></div>
</div>
</div>
<div class="gui_box grey" style="display:none;">
<div class="gui_box_titlebar">
<div class="spacer_box_title">VTX

View File

@ -211,6 +211,7 @@ OSD.initData = function() {
video_system: null,
unit_mode: null,
alarms: [],
stat_items: [],
display_items: [],
last_positions: {},
preview_logo: true,
@ -452,6 +453,39 @@ OSD.constants = {
positionable: true,
preview: FONT.symbol(SYM.FLY_M) + '02:07'
}
},
ALL_STATISTIC_FIELDS: {
MAX_SPEED: {
name: 'MAX_SPEED'
},
MIN_BATTERY: {
name: 'MIN_BATTERY'
},
MIN_RSSI: {
name: 'MIN_RSSI'
},
MAX_CURRENT: {
name: 'MAX_CURRENT'
},
USED_MAH: {
name: 'USED_MAH'
},
MAX_ALTITUDE: {
name: 'MAX_ALTITUDE'
},
BLACKBOX: {
name: 'BLACKBOX'
},
END_BATTERY: {
name: 'END_BATTERY'
},
FLYTIME: {
name: 'FLY_TIME'
},
ARMEDTIME: {
name: 'ARMED_TIME'
}
}
};
@ -533,6 +567,22 @@ OSD.chooseFields = function () {
F.ALTITUDE
];
}
// Choose ststistic fields
// Nothing much to do here, I'm preempting there being new statistics
F = OSD.constants.ALL_STATISTIC_FIELDS;
OSD.constants.STATISTIC_FIELDS = [
F.MAX_SPEED,
F.MIN_BATTERY,
F.MIN_RSSI,
F.MAX_CURRENT,
F.USED_MAH,
F.MAX_ALTITUDE,
F.BLACKBOX,
F.END_BATTERY,
F.FLYTIME,
F.ARMEDTIME
];
};
OSD.updateDisplaySize = function() {
@ -598,12 +648,19 @@ OSD.msp = {
}
return result;
},
encode: function(display_item) {
encodeLayout: function(display_item) {
var buffer = [];
buffer.push8(display_item.index);
buffer.push16(this.helpers.pack.position(display_item));
return buffer;
},
encodeStatistics: function(stat_item) {
var buffer = [];
buffer.push8(stat_item.index);
buffer.push16(stat_item.enabled);
buffer.push8(0);
return buffer;
},
// Currently only parses MSP_MAX_OSD responses, add a switch on payload.code if more codes are handled
decode: function(payload) {
var view = payload.data;
@ -631,8 +688,9 @@ OSD.msp = {
d.state.isOsdSlave = bit_check(d.flags, 1) && semver.gte(CONFIG.apiVersion, "1.34.0");
d.display_items = [];
d.stat_items = [];
// start at the offset from the other fields
// Parse display element positions
while (view.offset < view.byteLength && d.display_items.length < OSD.constants.DISPLAY_FIELDS.length) {
var v = null;
if (semver.gte(CONFIG.apiVersion, "1.21.0")) {
@ -649,6 +707,21 @@ OSD.msp = {
preview: typeof(c.preview) === 'function' ? c.preview(d) : c.preview
}, this.helpers.unpack.position(v, c)));
}
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
// Parse statistics display enable
while (view.offset < view.byteLength && d.stat_items.length < OSD.constants.STATISTIC_FIELDS.length) {
var v = view.readU8();
var j = d.stat_items.length;
var c = OSD.constants.STATISTIC_FIELDS[j];
d.stat_items.push({
name: c.name,
index: j,
enabled: v === 1
});
}
}
OSD.updateDisplaySize();
}
};
@ -807,6 +880,34 @@ TABS.osd.initialize = function (callback) {
var $input = $('<label/>').append(alarmInput);
$alarms.append($input);
}
// Post flight status
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
$('.stats-container').show();
var $statsFields = $('.post-flight-stats').empty();
for (let field of OSD.data.stat_items) {
if (!field.name) { continue; }
var $field = $('<div class="stat-field field-'+field.index+'"/>');
$field.append(
$('<input type="checkbox" name="'+field.name+'" class="togglesmall"></input>')
.data('field', field)
.attr('checked', field.enabled)
.change(function(e) {
var field = $(this).data('field');
field.enabled = !field.enabled;
MSP.promise(MSPCodes.MSP_SET_OSD_CONFIG, OSD.msp.encodeStatistics(field))
.then(function() {
updateOsdView();
});
})
);
$field.append('<label for="'+field.name+'" class="char-label">'+inflection.titleize(field.name)+'</label>');
$statsFields.append($field);
}
}
}
if (!OSD.data.state.haveMax7456Video) {
@ -838,7 +939,7 @@ TABS.osd.initialize = function (callback) {
} else {
$position.hide();
}
MSP.promise(MSPCodes.MSP_SET_OSD_CONFIG, OSD.msp.encode(field))
MSP.promise(MSPCodes.MSP_SET_OSD_CONFIG, OSD.msp.encodeLayout(field))
.then(function() {
updateOsdView();
});
@ -854,7 +955,7 @@ TABS.osd.initialize = function (callback) {
var field = $(this).data('field');
var position = parseInt($(this).val());
field.position = position;
MSP.promise(MSPCodes.MSP_SET_OSD_CONFIG, OSD.msp.encode(field))
MSP.promise(MSPCodes.MSP_SET_OSD_CONFIG, OSD.msp.encodeLayout(field))
.then(function() {
updateOsdView();
});