Skip to content

Commit

Permalink
Merge pull request #2159 from iNavFlight/MrD_Remove-switch-indicators…
Browse files Browse the repository at this point in the history
…-in-favour-of-custom-OSD-elements

Enhance OSD Custom Elements
  • Loading branch information
MrD-RC authored Sep 17, 2024
2 parents 4dfd16d + 41e9d83 commit 3c6197d
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 246 deletions.
2 changes: 1 addition & 1 deletion js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ var FC = {
this.FW_APPROACH = new FwApproachCollection();

this.OSD_CUSTOM_ELEMENTS = {
settings: {customElementsCount: 0, customElementTextSize: 0},
settings: {customElementsCount: 0, customElementTextSize: 0, customElementParts: 0},
items: [],
};

Expand Down
3 changes: 2 additions & 1 deletion js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ var MSPCodes = {
MSP2_ADSB_VEHICLE_LIST: 0x2090,

MSP2_INAV_CUSTOM_OSD_ELEMENTS: 0x2100,
MSP2_INAV_SET_CUSTOM_OSD_ELEMENTS: 0x2101,
MSP2_INAV_CUSTOM_OSD_ELEMENT: 0x2101,
MSP2_INAV_SET_CUSTOM_OSD_ELEMENTS: 0x2102,

MSP2_INAV_SERVO_CONFIG: 0x2200,
MSP2_INAV_SET_SERVO_CONFIG: 0x2201,
Expand Down
81 changes: 47 additions & 34 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1544,51 +1544,54 @@ var mspHelper = (function () {
break;

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

var index = 0;
let settingsIdx = 0;

if(data.byteLength == 0){
FC.OSD_CUSTOM_ELEMENTS .settings.customElementsCount = 0;
FC.OSD_CUSTOM_ELEMENTS .settings.customElementTextSize = 0;
if(data.byteLength == 0) {
FC.OSD_CUSTOM_ELEMENTS.settings.customElementsCount = 0;
FC.OSD_CUSTOM_ELEMENTS.settings.customElementTextSize = 0;
FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts = 0;
return;
}

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

for (i = 0; i < FC.OSD_CUSTOM_ELEMENTS .settings.customElementsCount; i++){
var customElement = {
customElementItems: [],
customElementVisibility: {type: 0, value: 0},
customElementText: [],
};
FC.OSD_CUSTOM_ELEMENTS.settings.customElementsCount = data.getUint8(settingsIdx++);
FC.OSD_CUSTOM_ELEMENTS.settings.customElementTextSize = data.getUint8(settingsIdx++);
FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts = data.getUint8(settingsIdx++);
break;
case MSPCodes.MSP2_INAV_CUSTOM_OSD_ELEMENT:
var customElement = {
customElementItems: [],
customElementVisibility: {type: 0, value: 0},
customElementText: [],
};

for (let ii = 0; ii < FC.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);
}
let index = 0;

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

for (let ii = 0; ii < FC.OSD_CUSTOM_ELEMENTS .settings.customElementTextSize; ii++){
var char = data.getUint8(index++);
if(char === 0){
index += (FC.OSD_CUSTOM_ELEMENTS .settings.customElementTextSize - 1) - ii;
break;
}
customElement.customElementText[ii] = char;
customElement.customElementVisibility.type = data.getUint8(index++);
customElement.customElementVisibility.value = data.getUint16(index, true);
index += 2;

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

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

FC.OSD_CUSTOM_ELEMENTS .items.push(customElement)
}
FC.OSD_CUSTOM_ELEMENTS.items.push(customElement);
break;
case MSPCodes.MSP2_INAV_GPS_UBLOX_COMMAND:
// Just and ACK from the fc.
Expand Down Expand Up @@ -2475,7 +2478,17 @@ var mspHelper = (function () {
};

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

var cosdeIdx = 0;

function nextCustomOSDElement() {
if (cosdeIdx < FC.OSD_CUSTOM_ELEMENTS .settings.customElementsCount - 1) {
MSP.send_message(MSPCodes.MSP2_INAV_CUSTOM_OSD_ELEMENT, [cosdeIdx++], false, nextCustomOSDElement);
} else {
MSP.send_message(MSPCodes.MSP2_INAV_CUSTOM_OSD_ELEMENT, [cosdeIdx++], false, callback);
}
}
}

self.sendModeRanges = function (onCompleteCallback) {
Expand Down
9 changes: 9 additions & 0 deletions locale/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3628,6 +3628,9 @@
"osd_custom_element_settings": {
"message": "Custom OSD elements"
},
"osd_custom_element_settings_HELP": {
"message": "You can find the icon numbers by clicking this help button."
},
"custom_element": {
"message": "Custom element"
},
Expand Down Expand Up @@ -4243,6 +4246,9 @@
"osdPanServoOffcentreWarning_HELP": {
"message": "Degrees either side of the pan servo centre; where it is assumed camera is wanted to be facing forwards, but isn't at 0. If in this range and not 0 for longer than 10 seconds, the pan servo offset OSD element will blink. 0 means the warning is disabled."
},
"osdGroupOSDCustomElements": {
"message": "OSD Custom Elements"
},
"osdGroupGVars": {
"message": "Global Variables"
},
Expand Down Expand Up @@ -4333,6 +4339,9 @@
"osd_switch_indicator_settings": {
"message": "Switch Indicator Settings"
},
"osd_switch_indicator_settings_HELP": {
"message": "It is recommended to use the Custom OSD Elements as a replacemtent for switch indicators. They are much more powerful. Click to see an example."
},
"osd_switch_indicators_align_left": {
"message": "Align switch names to left of switches"
},
Expand Down
4 changes: 3 additions & 1 deletion tabs/osd.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
</label>
</div>
</div>

<div class="gui_box grey switch-indicator-container">
<div class="gui_box_titlebar">
<a href="https://github.com/iNavFlight/inav/wiki/OSD-custom-messages" target="_blank"></a><div for="osd_switch_indicator_settings" class="helpicon cf_tip" data-i18n_title="osd_switch_indicator_settings_HELP"></div></a>
<div class="spacer_box_title" data-i18n="osd_switch_indicator_settings"></div>
</div>
<div class="spacer_box settings">
Expand Down Expand Up @@ -336,9 +338,9 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
</div>
</div>


<div class="gui_box grey custom-element-container">
<div class="gui_box_titlebar">
<a href="https://github.com/iNavFlight/inav-configurator/resources/osd/INAV%20Character%20Map.md" target="_blank"><div for="osd_custom_element_settings" class="helpicon cf_tip" data-i18n_title="osd_custom_element_settings_HELP"></div></a>
<div class="spacer_box_title" data-i18n="osd_custom_element_settings"></div>
</div>
<div class="spacer_box settings" id="osdCustomElements"></div>
Expand Down
Loading

0 comments on commit 3c6197d

Please sign in to comment.