From 7a86b417c61896a735b171bfa2462ce0df65ec9a Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Mon, 5 Aug 2024 12:20:20 +0300 Subject: [PATCH] Removed Switch Indicators and increase custom to 8 Removed Switch indicators and increased the number of osd custom elements to 8. --- js/fc.js | 2 +- js/msp/MSPCodes.js | 3 +- js/msp/MSPHelper.js | 81 ++++++++++++++++++++++++------------------- tabs/osd.html | 35 ------------------- tabs/osd.js | 83 +++++++-------------------------------------- 5 files changed, 63 insertions(+), 141 deletions(-) diff --git a/js/fc.js b/js/fc.js index 7d777543..0a79ae5c 100644 --- a/js/fc.js +++ b/js/fc.js @@ -597,7 +597,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: [], }; diff --git a/js/msp/MSPCodes.js b/js/msp/MSPCodes.js index abe54465..4c36142d 100644 --- a/js/msp/MSPCodes.js +++ b/js/msp/MSPCodes.js @@ -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, diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index e872d571..5021fd8d 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -1542,51 +1542,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. @@ -2473,7 +2476,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) { diff --git a/tabs/osd.html b/tabs/osd.html index 8488bfbd..4f61797c 100644 --- a/tabs/osd.html +++ b/tabs/osd.html @@ -301,41 +301,6 @@ -
-
-
-
-
- - - - - - - - -
-
-
diff --git a/tabs/osd.js b/tabs/osd.js index 00d92082..91e49184 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -19,6 +19,7 @@ const { globalSettings } = require('./../js/globalSettings'); const { PortHandler } = require('./../js/port_handler'); const i18n = require('./../js/localization'); const jBox = require('./../js/libraries/jBox/jBox.min'); +const { Console } = require('console'); var SYM = SYM || {}; @@ -553,7 +554,6 @@ OSD.DjiElements = { "Timers", "VTX", "CRSF", - "SwitchIndicators", "GVars", "PIDs", "PIDOutputs", @@ -1848,35 +1848,6 @@ OSD.constants = { }, ] }, - { - name: 'osdGroupSwitchIndicators', - items: [ - { - name: 'SWITCH_INDICATOR_0', - id: 130, - positionable: true, - preview: 'SWI1' + FONT.symbol(SYM.SWITCH_INDICATOR_HIGH) - }, - { - name: 'SWITCH_INDICATOR_1', - id: 131, - positionable: true, - preview: 'SWI2' + FONT.symbol(SYM.SWITCH_INDICATOR_HIGH) - }, - { - name: 'SWITCH_INDICATOR_2', - id: 132, - positionable: true, - preview: 'SWI3' + FONT.symbol(SYM.SWITCH_INDICATOR_HIGH) - }, - { - name: 'SWITCH_INDICATOR_3', - id: 133, - positionable: true, - preview: 'SWI4' + FONT.symbol(SYM.SWITCH_INDICATOR_HIGH) - } - ] - }, { name: 'osdGroupGVars', items: [ @@ -2812,7 +2783,6 @@ OSD.GUI.updateFields = function() { GUI.switchery(); // Update the OSD preview - refreshOSDSwitchIndicators(); updatePilotAndCraftNames(); updatePanServoPreview(); }; @@ -3290,6 +3260,7 @@ TABS.osd = {}; TABS.osd.initialize = function (callback) { mspHelper.loadServoMixRules(); + mspHelper.loadLogicConditions(); if (GUI.active_tab != 'osd') { GUI.active_tab = 'osd'; @@ -3344,12 +3315,6 @@ TABS.osd.initialize = function (callback) { } // Update the OSD preview - refreshOSDSwitchIndicators(); - }); - - // Function to update the OSD layout when the switch text alignment changes - $("#switchIndicators_alignLeft").on('change', function() { - refreshOSDSwitchIndicators(); }); // Functions for when pan servo settings change @@ -3633,8 +3598,7 @@ function customElementNormaliseRow(row){ } } -function customElementDisableNonValidOptionsRow(row){ - +function customElementDisableNonValidOptionsRow(row) { var selectedTextIndex = false; for(let i = 0; i < 3; i++){ let elementType = $('.osdCustomElement-' + row + '-part-' + i + '-type'); @@ -3657,13 +3621,12 @@ function customElementDisableNonValidOptionsRow(row){ } function customElementGetDataForRow(row){ - var data = []; data.push8(row); var text = ""; - for(var ii = 0; ii < 3; ii++){ + for(var ii = 0; ii < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; ii++){ var elementType = $('.osdCustomElement-' + row + '-part-' + ii + '-type'); var valueCell = $('.' + elementType.data('valueCellClass')); var partValue = 0; @@ -3705,7 +3668,9 @@ function customElementGetDataForRow(row){ data.push8(parseInt(elementVisibilityType.val())); data.push16(visibilityValue); - for(var i = 0; i < FC.OSD_CUSTOM_ELEMENTS .settings.customElementTextSize; i++){ + console.log("Saving osd custom data for number " + row + " | data: " + data); + + for(var i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementTextSize; i++){ if(i < text.length){ data.push8(text.charCodeAt(i)) }else{ @@ -3718,42 +3683,20 @@ function customElementGetDataForRow(row){ function getGVoptions(){ var result = ''; - for(var i = 0; i < 8; i++){ - result += ``; + for(var i = 0; i < 8; i++) { + result += ``; } return result; } function getLCoptions(){ var result = ''; - for(var i = 0; i < 64; i++){ - result += ``; - } - return result; -} - - -function refreshOSDSwitchIndicators() { - let group = OSD.constants.ALL_DISPLAY_GROUPS.filter(function(e) { - return e.name == "osdGroupSwitchIndicators"; - })[0]; - for (let si = 0; si < group.items.length; si++) { - let item = group.items[si]; - if ($("#osdSwitchInd" + si +"_name").val() != undefined) { - let switchIndText = $("#osdSwitchInd" + si +"_name").val(); - if (switchIndText == "") { - item.preview = FONT.symbol(SYM.SWITCH_INDICATOR_HIGH); - } else { - if ($("#switchIndicators_alignLeft").prop('checked')) { - item.preview = switchIndText + FONT.symbol(SYM.SWITCH_INDICATOR_HIGH); - } else { - item.preview = FONT.symbol(SYM.SWITCH_INDICATOR_HIGH) + switchIndText; - } - } + for(var i = 0; i < FC.LOGIC_CONDITIONS.getMaxLogicConditionCount(); i++) { + if (FC.LOGIC_CONDITIONS.isEnabled(i)) { + result += ``; } } - - OSD.GUI.updatePreviews(); + return result; } function updatePilotAndCraftNames() {