Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
More OSD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra committed Oct 19, 2016
1 parent 6731591 commit aa05ce0
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 43 deletions.
16 changes: 13 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@
"featureTRANSPONDERTip": {
"message": "Configure via the Race Transponder tab after enabling."
},
"featureOSD": {
"message": "On-Screen Display"
},
"featureOSDTip": {
"message": "Only for devices with onboard OSD."
},

"configurationFeatureEnabled": {
"message": "Enabled"
Expand Down Expand Up @@ -1754,9 +1760,6 @@
"message": "No"
},

"osdInfoHead": {
"message": "Info"
},
"osdResetText": {
"message": "Reset OSD to default"
},
Expand All @@ -1781,6 +1784,13 @@
"message": "Callsign"
},

"osdLayoutOSDNotSupported": {
"message": "OSD is not supported on this device."
},
"osdLayoutOSDNotEnabled": {
"message": "OSD is not enabled, enable OSD to configure OSD layout."
},

"osdLayoutElements": {
"message": "OSD Elements"
},
Expand Down
3 changes: 2 additions & 1 deletion tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
{bit: 16, group: 'other', name: 'LED_STRIP'},
{bit: 17, group: 'other', name: 'DISPLAY'},
{bit: 18, group: 'esc', name: 'ONESHOT125', haveTip: true},
{bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}
{bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true},
{bit: 22, group: 'other', name: 'OSD', haveTip: true}
];

if (semver.gte(CONFIG.apiVersion, "1.12.0")) {
Expand Down
34 changes: 33 additions & 1 deletion tabs/osd_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,36 @@
.tab-osd-layout .content_wrapper {
height: calc(100% - 30px);
}
}
}

.tab-osd-layout .require-supported {
display: none;
}

.tab-osd-layout.supported .require-supported {
display: block;
}

.tab-osd-layout .require-not-supported {
display: block;
}

.tab-osd-layout.supported .require-not-supported {
display: none;
}

.tab-osd-layout .require-enabled {
display: none;
}

.tab-osd-layout.enabled .require-enabled {
display: block;
}

.tab-osd-layout .require-not-enabled {
display: block;
}

.tab-osd-layout.enabled .require-not-enabled {
display: none;
}
17 changes: 12 additions & 5 deletions tabs/osd_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
href="https://github.com/cleanflight/cleanflight/releases"
target="_blank"></a>
</div>
<div class="unsupported hide">
<div class="require-not-supported">
<p
class="note"
i18n="tabOSDinfo"></p>
i18n="osdLayoutOSDNotSupported"></p>
</div>
<div class="font-preview"></div>
<div class="supported full">
<div class="require-supported">
<div class="require-not-enabled">
<p
class="note"
i18n="osdLayoutOSDNotEnabled"></p>
</div>
</div>
<div class="font-preview require-enabled"></div>
<div class="require-enabled">
<div class="cf_column third_left elements">
<div class="spacer_right"></div>
<div class="spacer_right">
Expand Down Expand Up @@ -55,7 +62,7 @@
</div>
</div>
<div
class="content_toolbar supported XXXhide"
class="content_toolbar require-supported"
style="left: 0;">
<div class="btn">
<a
Expand Down
123 changes: 90 additions & 33 deletions tabs/osd_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,49 @@ OSD.constants = {
],
};

TABS.osd_layout = {};
TABS.osd_layout = {
osd_supported: false,
osd_enabled: false,
callsign_supported: false,
};

TABS.osd_layout.initialize = function (callback) {
var self = this;
var ui_fields = [];
var video_mode = 0;

var callsign_supported = semver.gte(CONFIG.apiVersion, "1.22.0");
self.callsign_supported = semver.gte(CONFIG.apiVersion, "1.22.0");
self.osd_supported = semver.gte(CONFIG.apiVersion, "1.22.0") && (CONFIG.boardType == 1 || CONFIG.boardType == 2);

var is_dedicated_osd = CONFIG.boardType == 1; // always enabled on an OSD board.

if (GUI.active_tab != 'osd_layout') {
GUI.active_tab = 'osd_layout';
googleAnalytics.sendAppView('OSD');
}

MSP.send_message(MSP_codes.MSP_OSD_VIDEO_STATUS, false, false, load_pilot);
if (!self.osd_supported) {
load_html();
} else {
load_features();
}

function load_features() {
var next_callback = load_video_status;
if (!is_dedicated_osd) {
MSP.send_message(MSP_codes.MSP_FEATURE, false, false, next_callback);
} else {
next_callback();
}
}

function load_video_status() {
MSP.send_message(MSP_codes.MSP_OSD_VIDEO_STATUS, false, false, load_pilot);
}

function load_pilot() {
var next_callback = load_element_summary;
if (callsign_supported) {
if (self.callsign_supported) {
MSP.send_message(MSP_codes.MSP_PILOT, false, false, next_callback);
} else {
next_callback();
Expand All @@ -373,49 +398,72 @@ TABS.osd_layout.initialize = function (callback) {
$('#content').load("./tabs/osd_layout.html", process_html);
}

function process_html() {

function update_ui() {
// translate to user-selected language
localize();

if (is_dedicated_osd) {
self.osd_enabled = true;
} else {
self.osd_enabled = bit_check(FEATURE.enabled, 22);
}

if (!self.osd_supported) {
$(".tab-osd-layout").removeClass("supported");
} else {
$(".tab-osd-layout").addClass("supported");
}

if (!self.osd_enabled) {
$(".tab-osd-layout").removeClass("enabled");
} else {
$(".tab-osd-layout").addClass("enabled");
}

if (!self.osd_supported || !self.osd_enabled) {
return;
}

if (!callsign_supported) {
if (!self.callsign_supported) {
$('.callsign_wrapper').hide();
} else {
$(".callsign").val(PILOT_CONFIG.callsign);
}

function on_save_handler() {
var elements = [];

var $ui_fields = $('.tab-osd-layout .display-fields .checkbox input');

$ui_fields.each( function(index, $ui_field) {
var ui_field = $($ui_field).data('field');
function save_elements() {
var elements = [];

var yy = ui_field.vertical_alignment == 'top' ? ui_field.position_y : 0 - (OSD_VIDEO_STATE.text_height - ui_field.position_y);
var flag_mask = ui_field.element.initial_flag_mask;
// unset the bits we might allow changes to.
flag_mask = bit_clear(flag_mask, 0); // clear enabled;
var $ui_fields = $('.tab-osd-layout .display-fields .checkbox input');

// update the bits as the user requires.
if (ui_field.enabled) {
flag_mask = bit_set(flag_mask, 0);
}
$ui_fields.each( function(index, $ui_field) {
var ui_field = $($ui_field).data('field');

var yy = ui_field.vertical_alignment == 'top' ? ui_field.position_y : 0 - (OSD_VIDEO_STATE.text_height - ui_field.position_y);
var flag_mask = ui_field.element.initial_flag_mask;
// unset the bits we might allow changes to.
flag_mask = bit_clear(flag_mask, 0); // clear enabled;

// update the bits as the user requires.
if (ui_field.enabled) {
flag_mask = bit_set(flag_mask, 0);
}

var element = {
id: ui_field.element.id,
flag_mask: flag_mask,
x: ui_field.position_x,
y: yy,
};
elements.push(element);
});

var element = {
id: ui_field.element.id,
flag_mask: flag_mask,
x: ui_field.position_x,
y: yy,
};
elements.push(element);
});

MSP.sendOsdLayout(elements, save_pilot);
MSP.sendOsdLayout(elements, save_pilot);
}

function save_pilot() {
var next_callback = save_to_eeprom;
if (callsign_supported) {
if (self.callsign_supported) {
var callsign = $(".callsign").val();

var buffer = [];
Expand All @@ -436,6 +484,12 @@ TABS.osd_layout.initialize = function (callback) {
GUI.log(chrome.i18n.getMessage('osdLayoutEepromSaved'));
});
}

if (self.osd_enabled) {
save_elements();
} else {
save_pilot();
}
}

// init structs once, also clears current font
Expand All @@ -458,7 +512,10 @@ TABS.osd_layout.initialize = function (callback) {
}, 250, true);

load_elements();

}

function process_html() {
update_ui();
GUI.content_ready(callback);
}

Expand Down

0 comments on commit aa05ce0

Please sign in to comment.