Skip to content

Commit

Permalink
OSD custom elements
Browse files Browse the repository at this point in the history
  • Loading branch information
error414 committed Dec 29, 2023
1 parent 1c48adc commit 0579e61
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 20 deletions.
6 changes: 6 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,12 @@
"osd_hud_settings": {
"message": "Heads up Display settings"
},
"osd_custom_element_settings": {
"message": "Custom OSD elements"
},
"custom_element": {
"message": "Custom element"
},
"osd_hud_settings_HELP": {
"message": "This section allows tweaking the behavior of HUD elements."
},
Expand Down
9 changes: 8 additions & 1 deletion js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ var CONFIG,
BOARD_ALIGNMENT,
CURRENT_METER_CONFIG,
FEATURES,
RATE_DYNAMICS;
RATE_DYNAMICS,
OSD_CUSTOM_ELEMENTS
;

var FC = {
restartRequired: false,
Expand Down Expand Up @@ -564,6 +566,11 @@ var FC = {
rate: null,
expo: null
};

OSD_CUSTOM_ELEMENTS = {
settings: {customElementsCount: 0, customElementTextSize: 0},
items: [],
};
},
getOutputUsages: function() {
return {
Expand Down
5 changes: 4 additions & 1 deletion js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,8 @@ var MSPCodes = {
MSP2_INAV_EZ_TUNE: 0x2070,
MSP2_INAV_EZ_TUNE_SET: 0x2071,

MSP2_INAV_SELECT_MIXER_PROFILE: 0x2080
MSP2_INAV_SELECT_MIXER_PROFILE: 0x2080,

MSP2_INAV_CUSTOM_OSD_ELEMENTS: 0x2090,
MSP2_INAV_SET_CUSTOM_OSD_ELEMENTS: 0x2091,
};
67 changes: 53 additions & 14 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var mspHelper = (function (gui) {

CONFIG.armingFlags = data.getUint32(offset, true);
offset += 4;

//As there are 8 bytes for mspBoxModeFlags (number of bytes is actually variable)
//read mixer profile as the last byte in the the message
profile_byte = data.getUint8(dataHandler.message_length_expected - 1);
Expand Down Expand Up @@ -1500,6 +1500,9 @@ var mspHelper = (function (gui) {
case MSPCodes.MSP2_INAV_SELECT_BATTERY_PROFILE:
console.log('Battery profile selected');
break;
case MSPCodes.MSP2_INAV_SET_CUSTOM_OSD_ELEMENTS:
console.log('OSD custom elements preferences saved');
break;
case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING:
OUTPUT_MAPPING.flush();
for (i = 0; i < data.byteLength; ++i)
Expand Down Expand Up @@ -1607,6 +1610,48 @@ var mspHelper = (function (gui) {
console.log('EzTune settings saved');
break;

case MSPCodes.MSP2_INAV_CUSTOM_OSD_ELEMENTS:
OSD_CUSTOM_ELEMENTS.items = [];

var index = 0;

OSD_CUSTOM_ELEMENTS.settings.customElementsCount = data.getUint8(index++);
OSD_CUSTOM_ELEMENTS.settings.customElementTextSize = data.getUint8(index++);

for (i = 0; i < OSD_CUSTOM_ELEMENTS.settings.customElementsCount; i++){
var customElement = {
customElementItems: [],
customElementVisibility: {type: 0, value: 0},
customElementText: [],
};

for (let ii = 0; ii < OSD_CUSTOM_ELEMENTS.settings.customElementsCount; ii++){
var customElementPart = {type: 0, value: 0,};
customElementPart.type = data.getUint8(index++);
customElementPart.value = data.getUint16(index, true);
index += 2;
customElement.customElementItems.push(customElementPart);
}

customElement.customElementVisibility.type = data.getUint8(index++);
customElement.customElementVisibility.value = data.getUint16(index, true);
index += 2;

for (let ii = 0; ii < OSD_CUSTOM_ELEMENTS.settings.customElementTextSize; ii++){
var char = data.getUint8(index++);
if(char === 0){
index += (OSD_CUSTOM_ELEMENTS.settings.customElementTextSize - 1) - ii;
break;
}
customElement.customElementText[ii] = char;
}

customElement.customElementText = String.fromCharCode(...customElement.customElementText);

OSD_CUSTOM_ELEMENTS.items.push(customElement)
}
break;

default:
console.log('Unknown code detected: ' + dataHandler.code);
} else {
Expand Down Expand Up @@ -2551,6 +2596,10 @@ var mspHelper = (function (gui) {
}
};

self.loadOsdCustomElements = function (callback) {
MSP.send_message(MSPCodes.MSP2_INAV_CUSTOM_OSD_ELEMENTS, false, false, callback);
}

self.sendModeRanges = function (onCompleteCallback) {
var nextFunction = send_next_mode_range;

Expand Down Expand Up @@ -2928,7 +2977,7 @@ var mspHelper = (function (gui) {
MSP.send_message(MSPCodes.MSP2_INAV_TIMER_OUTPUT_MODE, false, false, callback);
}

self.sendTimerOutputModes = function(onCompleteCallback) {
self.sendTimerOutputModes = function(callback) {
var nextFunction = send_next_output_mode;
var idIndex = 0;

Expand All @@ -2953,7 +3002,7 @@ var mspHelper = (function (gui) {
// prepare for next iteration
idIndex++;
if (idIndex == overrideIds.length) {
nextFunction = onCompleteCallback;
nextFunction = callback;

}
MSP.send_message(MSPCodes.MSP2_INAV_SET_TIMER_OUTPUT_MODE, buffer, false, nextFunction);
Expand Down Expand Up @@ -3315,12 +3364,6 @@ var mspHelper = (function (gui) {

self.encodeSetting = function (name, value) {
return this._getSetting(name).then(function (setting) {

if (!setting) {
console.log("Setting invalid: " + name);
return null;
}

if (setting.table && !Number.isInteger(value)) {
var found = false;
for (var ii = 0; ii < setting.table.values.length; ii++) {
Expand Down Expand Up @@ -3368,11 +3411,7 @@ var mspHelper = (function (gui) {

self.setSetting = function (name, value, callback) {
this.encodeSetting(name, value).then(function (data) {
if (data) {
return MSP.promise(MSPCodes.MSPV2_SET_SETTING, data).then(callback);
} else {
return Promise.resolve().then(callback);
}
return MSP.promise(MSPCodes.MSPV2_SET_SETTING, data).then(callback);
});
};

Expand Down
18 changes: 17 additions & 1 deletion tabs/osd.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,17 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
</label>
</div>
</div>
<div class="gui_box grey pan-servo-container">


<div class="gui_box grey custom-element-container">
<div class="gui_box_titlebar">
<div class="spacer_box_title" data-i18n="osd_custom_element_settings"></div>
</div>
<div class="spacer_box settings" id="osdCustomElements"></div>
</div>


<div class="gui_box grey pan-servo-container">
<div class="gui_box_titlebar">
<div for="osd_pan_servo_settings" class="helpicon cf_tip" data-i18n_title="osd_pan_servo_settings_HELP"></div>
<div class="spacer_box_title" data-i18n="osd_pan_servo_settings"></div>
Expand Down Expand Up @@ -425,6 +435,12 @@ <h1 class="tab_title">Font:</h1>
<a class="flash_font active" data-i18n="osd_font_upload"></a>
</div>
</div>
<div id="fonttypeselectorcontent" style="display:none; width:712px;">
<div class="font-picker" style="margin-bottom: 10px;">
<h1 class="tab_title">Font:</h1>
<div class="content_wrapper font-preview"></div>
</div>
</div>
<div class="clear-both"></div>
</div>
</div>
Expand Down
Loading

0 comments on commit 0579e61

Please sign in to comment.