Merge pull request #291 from nathantsoi/more-osd-features

More osd features
10.3.x-maintenance
borisbstyle 2016-09-20 15:00:41 +02:00 committed by GitHub
commit 23a7acb0e5
3 changed files with 143 additions and 36 deletions

View File

@ -294,6 +294,10 @@
margin-top: -7px; margin-top: -7px;
} }
.tab-osd .preview .gui_box_titlebar {
position: relative;
}
.tab-osd .preview .char { .tab-osd .preview .char {
display: inline-block; display: inline-block;
padding: 0; padding: 0;
@ -304,6 +308,12 @@
cursor: move; cursor: move;
} }
.tab-osd .preview-logo {
position: absolute;
font-weight: 800;
right: 0;
}
.tab-osd .preview .row { .tab-osd .preview .row {
height: 18px; height: 18px;
} }

View File

@ -17,7 +17,7 @@
<div <div
class="gui_box_titlebar" class="gui_box_titlebar"
style="margin-bottom: 0px;"> style="margin-bottom: 0px;">
<div class="spacer_box_title">OSD <div class="spacer_box_title">
Elements Elements
</div> </div>
</div> </div>
@ -30,7 +30,7 @@
<div class="cf_column twothird"> <div class="cf_column twothird">
<div class="gui_box grey preview" style="float: left;"> <div class="gui_box grey preview" style="float: left;">
<div class="gui_box_titlebar image"> <div class="gui_box_titlebar image">
<div class="spacer_box_title">OSD Preview <span>(drag to change position)</span></div> <div class="spacer_box_title">Preview <span>(drag to change position)</span><span class="preview-logo"></span></div>
</div> </div>
<div class="display-layout"> <div class="display-layout">
<div class="col right"> <div class="col right">
@ -40,15 +40,6 @@
</div> </div>
</div> </div>
<div class="cf_column third_right" style="width: calc(100% - 377px);"> <div class="cf_column third_right" style="width: calc(100% - 377px);">
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title">Preview logo
</div>
</div>
<div class="spacer_box">
<div class="preview-logo"></div>
</div>
</div>
<div class="gui_box grey"> <div class="gui_box grey">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title">Video <div class="spacer_box_title">Video
@ -68,6 +59,16 @@
<div class="units"></div> <div class="units"></div>
</div> </div>
</div> </div>
<div class="gui_box grey alarms-container" style="display:none;">
<div class="gui_box_titlebar">
<div class="spacer_box_title">
Alarms
</div>
</div>
<div class="spacer_box">
<div class="alarms"></div>
</div>
</div>
<div class="gui_box grey" style="display:none;"> <div class="gui_box grey" style="display:none;">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title">VTX <div class="spacer_box_title">VTX

View File

@ -19,6 +19,7 @@ SYM.AMP = 0x9A;
SYM.MAH = 0x07; SYM.MAH = 0x07;
SYM.METRE = 0xC; SYM.METRE = 0xC;
SYM.FEET = 0xF; SYM.FEET = 0xF;
SYM.GPS_SAT = 0x1F;
var FONT = FONT || {}; var FONT = FONT || {};
@ -203,6 +204,7 @@ OSD.initData = function() {
OSD.data = { OSD.data = {
video_system: null, video_system: null,
unit_mode: null, unit_mode: null,
alarms: [],
display_items: [], display_items: [],
last_positions: {}, last_positions: {},
preview_logo: true, preview_logo: true,
@ -231,99 +233,174 @@ OSD.constants = {
], ],
AHISIDEBARWIDTHPOSITION: 7, AHISIDEBARWIDTHPOSITION: 7,
AHISIDEBARHEIGHTPOSITION: 3, AHISIDEBARHEIGHTPOSITION: 3,
// order matters, so these are going in an array... pry could iterate the example map instead
DISPLAY_FIELDS: [ // All display fields, from every version, do not remove elements, only add!
{ ALL_DISPLAY_FIELDS: {
MAIN_BATT_VOLTAGE: {
name: 'MAIN_BATT_VOLTAGE', name: 'MAIN_BATT_VOLTAGE',
default_position: -29, default_position: -29,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.VOLT) + '16.8' preview: FONT.symbol(SYM.VOLT) + '16.8'
}, },
{ RSSI_VALUE: {
name: 'RSSI_VALUE', name: 'RSSI_VALUE',
default_position: -59, default_position: -59,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.RSSI) + '99' preview: FONT.symbol(SYM.RSSI) + '99'
}, },
{ TIMER: {
name: 'TIMER', name: 'TIMER',
default_position: -39, default_position: -39,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.ON_M) + ' 11:11' preview: FONT.symbol(SYM.ON_M) + ' 11:11'
}, },
{ THROTTLE_POSITION: {
name: 'THROTTLE_POSITION', name: 'THROTTLE_POSITION',
default_position: -9, default_position: -9,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.THR) + FONT.symbol(SYM.THR1) + ' 69' preview: FONT.symbol(SYM.THR) + FONT.symbol(SYM.THR1) + ' 69'
}, },
{ CPU_LOAD: {
name: 'CPU_LOAD', name: 'CPU_LOAD',
default_position: 26, default_position: 26,
positionable: true, positionable: true,
preview: '15' preview: '15'
}, },
{ VTX_CHANNEL: {
name: 'VTX_CHANNEL', name: 'VTX_CHANNEL',
default_position: 1, default_position: 1,
positionable: true, positionable: true,
preview: 'CH:1' preview: 'CH:1'
}, },
{ VOLTAGE_WARNING: {
name: 'VOLTAGE_WARNING', name: 'VOLTAGE_WARNING',
default_position: -80, default_position: -80,
positionable: true, positionable: true,
preview: 'LOW VOLTAGE' preview: 'LOW VOLTAGE'
}, },
{ ARMED: {
name: 'ARMED', name: 'ARMED',
default_position: -107, default_position: -107,
positionable: true, positionable: true,
preview: 'ARMED' preview: 'ARMED'
}, },
{ DIASRMED: {
name: 'DIASRMED', name: 'DIASRMED',
default_position: -109, default_position: -109,
positionable: true, positionable: true,
preview: 'DISARMED' preview: 'DISARMED'
}, },
{ ARTIFICIAL_HORIZON: {
name: 'ARTIFICIAL_HORIZON', name: 'ARTIFICIAL_HORIZON',
default_position: -1, default_position: -1,
positionable: false positionable: false
}, },
{ HORIZON_SIDEBARS: {
name: 'HORIZON_SIDEBARS', name: 'HORIZON_SIDEBARS',
default_position: -1, default_position: -1,
positionable: false positionable: false
}, },
{ CURRENT_DRAW: {
name: 'CURRENT_DRAW', name: 'CURRENT_DRAW',
default_position: -23, default_position: -23,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.AMP) + '42.0' preview: FONT.symbol(SYM.AMP) + '42.0'
}, },
{ MAH_DRAWN: {
name: 'MAH_DRAWN', name: 'MAH_DRAWN',
default_position: -18, default_position: -18,
positionable: true, positionable: true,
preview: FONT.symbol(SYM.MAH) + '690' preview: FONT.symbol(SYM.MAH) + '690'
}, },
{ CRAFT_NAME: {
name: 'CRAFT_NAME', name: 'CRAFT_NAME',
default_position: -77, default_position: -77,
positionable: true, positionable: true,
preview: '[CRAFT_NAME]' preview: '[CRAFT_NAME]'
}, },
{ ALTITUDE: {
name: 'ALTITUDE', name: 'ALTITUDE',
default_position: 62, default_position: 62,
positionable: true, positionable: true,
preview: function(osd_data) { preview: function(osd_data) {
return '13.7' + FONT.symbol(osd_data.unit_mode === 0 ? SYM.FEET : SYM.METRE) return '13.7' + FONT.symbol(osd_data.unit_mode === 0 ? SYM.FEET : SYM.METRE)
} }
},
ONTIME: {
name: 'ONTIME',
default_position: -1,
positionable: true,
preview: FONT.symbol(SYM.ON_M) + ' 4:11'
},
FLYTIME: {
name: 'FLYTIME',
default_position: -1,
positionable: true,
preview: FONT.symbol(SYM.FLY_M) + ' 4:11'
},
FLYMODE: {
name: 'FLYMODE',
default_position: -1,
positionable: true,
preview: 'AIR'
},
GPS_SPEED: {
name: 'GPS_SPEED',
default_position: -1,
positionable: true,
preview: '40'
},
GPS_SATS: {
name: 'GPS_SATS',
default_position: -1,
positionable: true,
preview: FONT.symbol(SYM.GPS_SAT) + '3'
} }
], }
};
// Pick display fields by version, order matters, so these are going in an array... pry could iterate the example map instead
OSD.chooseFields = function () {
var F = OSD.constants.ALL_DISPLAY_FIELDS;
if (semver.gte(CONFIG.flightControllerVersion, "3.0.1")) {
OSD.constants.DISPLAY_FIELDS = [
F.RSSI_VALUE,
F.MAIN_BATT_VOLTAGE,
F.ARTIFICIAL_HORIZON,
F.HORIZON_SIDEBARS,
F.ONTIME,
F.FLYTIME,
F.FLYMODE,
F.CRAFT_NAME,
F.THROTTLE_POSITION,
F.VTX_CHANNEL,
F.CURRENT_DRAW,
F.MAH_DRAWN,
F.GPS_SPEED,
F.GPS_SATS,
F.ALTITUDE
]
}
// version 3.0.0
else {
OSD.constants.DISPLAY_FIELDS = [
F.MAIN_BATT_VOLTAGE,
F.RSSI_VALUE,
F.TIMER,
F.THROTTLE_POSITION,
F.CPU_LOAD,
F.VTX_CHANNEL,
F.VOLTAGE_WARNING,
F.ARMED,
F.DIASRMED,
F.ARTIFICIAL_HORIZON,
F.HORIZON_SIDEBARS,
F.CURRENT_DRAW,
F.MAH_DRAWN,
F.CRAFT_NAME,
F.ALTITUDE
]
}
}; };
OSD.updateDisplaySize = function() { OSD.updateDisplaySize = function() {
@ -359,16 +436,21 @@ OSD.msp = {
var view = payload.data; var view = payload.data;
var d = OSD.data; var d = OSD.data;
var i = 2; var i = 2;
d.compiled_in = view.getUint8(0, 1); d.compiled_in = view.readU8();
d.video_system = view.getUint8(1, 1); d.video_system = view.readU8();
if (semver.gte(CONFIG.flightControllerVersion, "3.0.1")) { if (semver.gte(CONFIG.flightControllerVersion, "3.0.1")) {
d.unit_mode = view.getUint8(2, 1); d.unit_mode = view.readU8();
i += 1; d.alarms = [];
d.alarms.push({name: 'rssi', display_name: 'Rssi', value: view.readU8()});
d.alarms.push({name: 'cap', display_name: 'Capacity', value: view.readU16()});
d.alarms.push({name: 'time', display_name: 'Minutes', value: view.readU16()});
i += 6;
} }
d.display_items = []; d.display_items = [];
// start at the offset from the other fields // start at the offset from the other fields
for (; i < view.byteLength; i = i + 2) { for (; i < view.byteLength; i = i + 2) {
var v = view.getInt16(i, 1) var v = view.readU16()
var j = d.display_items.length; var j = d.display_items.length;
var c = OSD.constants.DISPLAY_FIELDS[j]; var c = OSD.constants.DISPLAY_FIELDS[j];
d.display_items.push({ d.display_items.push({
@ -447,6 +529,9 @@ TABS.osd.initialize = function (callback) {
// ask for the OSD config data // ask for the OSD config data
MSP.promise(MSPCodes.MSP_OSD_CONFIG) MSP.promise(MSPCodes.MSP_OSD_CONFIG)
.then(function(info) { .then(function(info) {
if (!('DISPLAY_FIELDS' in OSD.constants)) {
OSD.chooseFields();
}
if (!info.length) { if (!info.length) {
$('.unsupported').fadeIn(); $('.unsupported').fadeIn();
return; return;
@ -457,7 +542,7 @@ TABS.osd.initialize = function (callback) {
// show Betaflight logo in preview // show Betaflight logo in preview
var $previewLogo = $('.preview-logo').empty(); var $previewLogo = $('.preview-logo').empty();
$previewLogo.append( $previewLogo.append(
$('<input type="checkbox" name="preview-logo" class="togglesmall"></input>') $('<label for="preview-logo">Logo:</label><input type="checkbox" name="preview-logo" class="togglesmall"></input>')
.attr('checked', OSD.data.preview_logo) .attr('checked', OSD.data.preview_logo)
.change(function(e) { .change(function(e) {
OSD.data.preview_logo = $(this).attr('checked') == undefined; OSD.data.preview_logo = $(this).attr('checked') == undefined;
@ -484,8 +569,8 @@ TABS.osd.initialize = function (callback) {
}); });
}); });
// units
if (semver.gte(CONFIG.flightControllerVersion, "3.0.1")) { if (semver.gte(CONFIG.flightControllerVersion, "3.0.1")) {
// units
$('.units-container').show(); $('.units-container').show();
var $unitMode = $('.units').empty(); var $unitMode = $('.units').empty();
for (var i = 0; i < OSD.constants.UNIT_TYPES.length; i++) { for (var i = 0; i < OSD.constants.UNIT_TYPES.length; i++) {
@ -504,6 +589,17 @@ TABS.osd.initialize = function (callback) {
updateOsdView(); updateOsdView();
}); });
}); });
// alarms
$('.alarms-container').show();
var $alarms = $('.alarms').empty();
for (var i = 0; i < OSD.data.alarms.length; i++) {
var alarm = OSD.data.alarms[i];
var $input = $('<label/>').append(
$('<input name="alarm" type="number"/>'+alarm.display_name+'</label>')
.val(alarm.value)
);
$alarms.append($input);
}
} }
// display fields on/off and position // display fields on/off and position