From 7a86b417c61896a735b171bfa2462ce0df65ec9a Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Mon, 5 Aug 2024 12:20:20 +0300 Subject: [PATCH 1/5] 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 7d7775435..0a79ae5c7 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 abe54465b..4c36142d4 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 e872d571c..5021fd8d2 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 8488bfbd4..4f61797c5 100644 --- a/tabs/osd.html +++ b/tabs/osd.html @@ -301,41 +301,6 @@

-
-
-
-
-
- - - - - - - - -
-
-
diff --git a/tabs/osd.js b/tabs/osd.js index 00d920821..91e491844 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() { From db2fb6706edc845f236ab1b872b3c8b9b3ea4d34 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Mon, 5 Aug 2024 12:41:18 +0300 Subject: [PATCH 2/5] A couple more changes to remove SI and increase OCE - Removed missed switch indicator lines in messages.json - Added group for OSD Custom Elements, and increased total to 8 --- locale/en/messages.json | 36 ++---------------- tabs/osd.js | 83 ++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/locale/en/messages.json b/locale/en/messages.json index bba5c8e2d..5fe477801 100644 --- a/locale/en/messages.json +++ b/locale/en/messages.json @@ -4201,21 +4201,6 @@ "osdElement_ESC_TEMPERATURE_HELP": { "message": "Temperature of the ESC read from DSHOT telemetry" }, - "osdGroupSwitchIndicators": { - "message": "Switch Indicators" - }, - "osdElement_SWITCH_INDICATOR_0": { - "message": "Switch Indicator 1" - }, - "osdElement_SWITCH_INDICATOR_1": { - "message": "Switch Indicator 2" - }, - "osdElement_SWITCH_INDICATOR_2": { - "message": "Switch Indicator 3" - }, - "osdElement_SWITCH_INDICATOR_3": { - "message": "Switch Indicator 4" - }, "osd_pan_servo_settings": { "message": "Pan Servo OSD Settings" }, @@ -4243,6 +4228,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" }, @@ -4330,24 +4318,6 @@ "osd_dji_cn_alternating_duration": { "message": "Craft Name alternating duration (in 1/10 sec)" }, - "osd_switch_indicator_settings": { - "message": "Switch Indicator Settings" - }, - "osd_switch_indicators_align_left": { - "message": "Align switch names to left of switches" - }, - "osdSwitchInd0": { - "message": "Switch 1" - }, - "osdSwitchInd1": { - "message": "Switch 2" - }, - "osdSwitchInd2": { - "message": "Switch 3" - }, - "osdSwitchInd3": { - "message": "Switch 4" - }, "osd_font_default": { "message": "Default" }, diff --git a/tabs/osd.js b/tabs/osd.js index 91e491844..c3ef37bd1 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -554,6 +554,7 @@ OSD.DjiElements = { "Timers", "VTX", "CRSF", + "OSDCustomElements", "GVars", "PIDs", "PIDOutputs", @@ -1848,6 +1849,67 @@ OSD.constants = { }, ] }, + { + name: 'osdGroupOSDCustomElements', + items: [ + { + name: 'CUSTOM ELEMENT 1', + id: 147, + min_version: '7.1.0', + positionable: true, + preview: "CE_1", + }, + { + name: 'CUSTOM ELEMENT 2', + id: 148, + min_version: '7.1.0', + positionable: true, + preview: "CE_2", + }, + { + name: 'CUSTOM ELEMENT 3', + id: 149, + min_version: '7.1.0', + positionable: true, + preview: "CE_3", + }, + { + name: 'CUSTOM ELEMENT 4', + id: 130, + min_version: '8.0.0', + positionable: true, + preview: "CE_4", + }, + { + name: 'CUSTOM ELEMENT 5', + id: 131, + min_version: '8.0.0', + positionable: true, + preview: "CE_5", + }, + { + name: 'CUSTOM ELEMENT 6', + id: 132, + min_version: '8.0.0', + positionable: true, + preview: "CE_6", + }, + { + name: 'CUSTOM ELEMENT 7', + id: 133, + min_version: '8.0.0', + positionable: true, + preview: "CE_7", + }, + { + name: 'CUSTOM ELEMENT 8', + id: 154, + min_version: '8.0.0', + positionable: true, + preview: "CE_8", + }, + ] + }, { name: 'osdGroupGVars', items: [ @@ -1874,27 +1936,6 @@ OSD.constants = { id: 116, positionable: true, preview: 'G3:30126' - }, - { - name: 'CUSTOM ELEMENT 1', - id: 147, - min_version: '7.1.0', - positionable: true, - preview: "CE_1", - }, - { - name: 'CUSTOM ELEMENT 2', - id: 148, - min_version: '7.1.0', - positionable: true, - preview: "CE_2", - }, - { - name: 'CUSTOM ELEMENT 3', - id: 149, - min_version: '7.1.0', - positionable: true, - preview: "CE_3", } ] }, From 4db59ca5353748e4d92d4deaa7e0ab6e3373d1e1 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Tue, 6 Aug 2024 18:30:53 +0300 Subject: [PATCH 3/5] Update - Added help icon with link to OSD icons document - Stopped OSD preview from updating if it has not yet been drawn - Removed some remaining switch indicator parts - Added additional numerical options to OSD custom elements types - Added the option to directly access LC, not just GV, in the OSD custom elements types - Added preview of actual layout of OSD custom element. To make alignment much easier. --- locale/en/messages.json | 3 + tabs/osd.html | 1 + tabs/osd.js | 518 +++++++++++++++++++++++++--------------- 3 files changed, 331 insertions(+), 191 deletions(-) diff --git a/locale/en/messages.json b/locale/en/messages.json index 5fe477801..6cee73902 100644 --- a/locale/en/messages.json +++ b/locale/en/messages.json @@ -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" }, diff --git a/tabs/osd.html b/tabs/osd.html index 4f61797c5..3ec5ea035 100644 --- a/tabs/osd.html +++ b/tabs/osd.html @@ -304,6 +304,7 @@

+
diff --git a/tabs/osd.js b/tabs/osd.js index c3ef37bd1..f520db5f6 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -1853,56 +1853,56 @@ OSD.constants = { name: 'osdGroupOSDCustomElements', items: [ { - name: 'CUSTOM ELEMENT 1', + name: 'CUSTOM_ELEMENT_1', id: 147, min_version: '7.1.0', positionable: true, preview: "CE_1", }, { - name: 'CUSTOM ELEMENT 2', + name: 'CUSTOM_ELEMENT_2', id: 148, min_version: '7.1.0', positionable: true, preview: "CE_2", }, { - name: 'CUSTOM ELEMENT 3', + name: 'CUSTOM_ELEMENT_3', id: 149, min_version: '7.1.0', positionable: true, preview: "CE_3", }, { - name: 'CUSTOM ELEMENT 4', + name: 'CUSTOM_ELEMENT_4', id: 130, min_version: '8.0.0', positionable: true, preview: "CE_4", }, { - name: 'CUSTOM ELEMENT 5', + name: 'CUSTOM_ELEMENT_5', id: 131, min_version: '8.0.0', positionable: true, preview: "CE_5", }, { - name: 'CUSTOM ELEMENT 6', + name: 'CUSTOM_ELEMENT_6', id: 132, min_version: '8.0.0', positionable: true, preview: "CE_6", }, { - name: 'CUSTOM ELEMENT 7', + name: 'CUSTOM_ELEMENT_7', id: 133, min_version: '8.0.0', positionable: true, preview: "CE_7", }, { - name: 'CUSTOM ELEMENT 8', + name: 'CUSTOM_ELEMENT_8', id: 154, min_version: '8.0.0', positionable: true, @@ -2964,176 +2964,178 @@ OSD.GUI.updatePreviews = function() { // buffer the preview; OSD.data.preview = []; - // clear the buffer - for (let i = 0; i < OSD.data.display_size.total; i++) { - OSD.data.preview.push([null, ' '.charCodeAt(0)]); - }; + if (OSD.data.display_size != undefined) { + // clear the buffer + for (let i = 0; i < OSD.data.display_size.total; i++) { + OSD.data.preview.push([null, ' '.charCodeAt(0)]); + }; - // draw all the displayed items and the drag and drop preview images - for (var ii = 0; ii < OSD.data.items.length; ii++) { - var item = OSD.get_item(ii); - if (!item || !OSD.is_item_displayed(item, OSD.data.groups[item.id])) { - continue; - } - var itemData = OSD.data.items[ii]; - if (!itemData.isVisible) { - continue; - } + // draw all the displayed items and the drag and drop preview images + for (var ii = 0; ii < OSD.data.items.length; ii++) { + var item = OSD.get_item(ii); + if (!item || !OSD.is_item_displayed(item, OSD.data.groups[item.id])) { + continue; + } + var itemData = OSD.data.items[ii]; + if (!itemData.isVisible) { + continue; + } - if (itemData.x >= OSD.data.display_size.x) - { - continue; - } + if (itemData.x >= OSD.data.display_size.x) + { + continue; + } - // DJI HD FPV: Hide elements that only appear in craft name - if (OSD.DjiElements.craftNameElements.includes(item.name) && - $('#djiUnsupportedElements').find('input').is(':checked')) { - continue; - } - var j = (itemData.position >= 0) ? itemData.position : itemData.position + OSD.data.display_size.total; - // create the preview image - item.preview_img = new Image(); - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext("2d"); - // fill the screen buffer - var preview = OSD.get_item_preview(item); - if (!preview) { - continue; - } - var x = 0; - var y = 0; - for (let i = 0; i < preview.length; i++) { - var charCode = preview.charCodeAt(i); - if (charCode == '\n'.charCodeAt(0)) { - x = 0; - y++; + // DJI HD FPV: Hide elements that only appear in craft name + if (OSD.DjiElements.craftNameElements.includes(item.name) && + $('#djiUnsupportedElements').find('input').is(':checked')) { continue; } - var previewPos = j + x + (y * OSD.data.display_size.x); - if (previewPos >= OSD.data.preview.length) { - // Character is outside the viewport - x++; + var j = (itemData.position >= 0) ? itemData.position : itemData.position + OSD.data.display_size.total; + // create the preview image + item.preview_img = new Image(); + var canvas = document.createElement('canvas'); + var ctx = canvas.getContext("2d"); + // fill the screen buffer + var preview = OSD.get_item_preview(item); + if (!preview) { continue; } - // test if this position already has a character placed - if (OSD.data.preview[previewPos][0] !== null) { - // if so set background color to red to show user double usage of position - OSD.data.preview[previewPos] = [item, charCode, 'red']; - } else { - OSD.data.preview[previewPos] = [item, charCode]; + var x = 0; + var y = 0; + for (let i = 0; i < preview.length; i++) { + var charCode = preview.charCodeAt(i); + if (charCode == '\n'.charCodeAt(0)) { + x = 0; + y++; + continue; + } + var previewPos = j + x + (y * OSD.data.display_size.x); + if (previewPos >= OSD.data.preview.length) { + // Character is outside the viewport + x++; + continue; + } + // test if this position already has a character placed + if (OSD.data.preview[previewPos][0] !== null) { + // if so set background color to red to show user double usage of position + OSD.data.preview[previewPos] = [item, charCode, 'red']; + } else { + OSD.data.preview[previewPos] = [item, charCode]; + } + // draw the preview + var img = new Image(); + img.src = FONT.draw(charCode); + ctx.drawImage(img, x*FONT.constants.SIZES.CHAR_WIDTH, y*FONT.constants.SIZES.CHAR_HEIGHT); + x++; } - // draw the preview - var img = new Image(); - img.src = FONT.draw(charCode); - ctx.drawImage(img, x*FONT.constants.SIZES.CHAR_WIDTH, y*FONT.constants.SIZES.CHAR_HEIGHT); - x++; + item.preview_img.src = canvas.toDataURL('image/png'); + // Required for NW.js - Otherwise the will + // consume drag/drop events. + item.preview_img.style.pointerEvents = 'none'; } - item.preview_img.src = canvas.toDataURL('image/png'); - // Required for NW.js - Otherwise the will - // consume drag/drop events. - item.preview_img.style.pointerEvents = 'none'; - } - - - var centerPosition = (OSD.data.display_size.x * OSD.data.display_size.y / 2); - if (OSD.data.display_size.y % 2 == 0) { - centerPosition += Math.floor(OSD.data.display_size.x / 2); - } - let hudCenterPosition = centerPosition - (OSD.constants.VIDEO_COLS[video_type] * $('#osd_horizon_offset').val()); - // artificial horizon - if ($('input[name="ARTIFICIAL_HORIZON"]').prop('checked')) { - for (let i = 0; i < 9; i++) { - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 4 + i, SYM.AH_BAR9_0 + 4); + var centerPosition = (OSD.data.display_size.x * OSD.data.display_size.y / 2); + if (OSD.data.display_size.y % 2 == 0) { + centerPosition += Math.floor(OSD.data.display_size.x / 2); } - } - // crosshairs - if ($('input[name="CROSSHAIRS"]').prop('checked')) { - let crsHNumber = Settings.getInputValue('osd_crosshairs_style'); - if (crsHNumber == 1) { - // AIRCRAFT style - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 2, SYM.AH_AIRCRAFT0); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_AIRCRAFT1); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_AIRCRAFT2); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_AIRCRAFT3); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 2, SYM.AH_AIRCRAFT4); - } else if ((crsHNumber > 1) && (crsHNumber < 8)) { - // TYPES 3 to 8 (zero indexed) - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_CROSSHAIRS[crsHNumber][0]); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_CROSSHAIRS[crsHNumber][1]); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_CROSSHAIRS[crsHNumber][2]); - } else { - // DEFAULT or unknown style - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_CENTER_LINE); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_CROSSHAIRS[crsHNumber]); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_CENTER_LINE_RIGHT); - } - } + let hudCenterPosition = centerPosition - (OSD.constants.VIDEO_COLS[video_type] * $('#osd_horizon_offset').val()); - // sidebars - if ($('input[name="HORIZON_SIDEBARS"]').prop('checked')) { - var hudwidth = OSD.constants.AHISIDEBARWIDTHPOSITION; - var hudheight = OSD.constants.AHISIDEBARHEIGHTPOSITION; - for (let i = -hudheight; i <= hudheight; i++) { - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - hudwidth + (i * FONT.constants.SIZES.LINE), SYM.AH_DECORATION); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + hudwidth + (i * FONT.constants.SIZES.LINE), SYM.AH_DECORATION); + // artificial horizon + if ($('input[name="ARTIFICIAL_HORIZON"]').prop('checked')) { + for (let i = 0; i < 9; i++) { + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 4 + i, SYM.AH_BAR9_0 + 4); + } } - // AH level indicators - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - hudwidth + 1, SYM.AH_LEFT); - OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + hudwidth - 1, SYM.AH_RIGHT); - } - OSD.GUI.updateMapPreview(centerPosition, 'MAP_NORTH', 'N', SYM.HOME); - OSD.GUI.updateMapPreview(centerPosition, 'MAP_TAKEOFF', 'T', SYM.HOME); - OSD.GUI.updateMapPreview(centerPosition, 'RADAR', null, SYM.DIR_TO_HOME); - - // render - var $preview = $('.display-layout .preview').empty(); - var $row = $('
'); - for (let i = 0; i < OSD.data.display_size.total;) { - var charCode = OSD.data.preview[i]; - var colorStyle = ''; - - if (typeof charCode === 'object') { - var item = OSD.data.preview[i][0]; - charCode = OSD.data.preview[i][1]; - if (OSD.data.preview[i][2] !== undefined) { - // if third field is set it contains a background color - colorStyle = 'style="background-color: ' + OSD.data.preview[i][2] + ';"'; + // crosshairs + if ($('input[name="CROSSHAIRS"]').prop('checked')) { + let crsHNumber = Settings.getInputValue('osd_crosshairs_style'); + if (crsHNumber == 1) { + // AIRCRAFT style + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 2, SYM.AH_AIRCRAFT0); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_AIRCRAFT1); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_AIRCRAFT2); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_AIRCRAFT3); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 2, SYM.AH_AIRCRAFT4); + } else if ((crsHNumber > 1) && (crsHNumber < 8)) { + // TYPES 3 to 8 (zero indexed) + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_CROSSHAIRS[crsHNumber][0]); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_CROSSHAIRS[crsHNumber][1]); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_CROSSHAIRS[crsHNumber][2]); + } else { + // DEFAULT or unknown style + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - 1, SYM.AH_CENTER_LINE); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition, SYM.AH_CROSSHAIRS[crsHNumber]); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + 1, SYM.AH_CENTER_LINE_RIGHT); } } - var $img = $('
') - .on('mouseenter', OSD.GUI.preview.onMouseEnter) - .on('mouseleave', OSD.GUI.preview.onMouseLeave) - .on('dragover', OSD.GUI.preview.onDragOver) - .on('dragleave', OSD.GUI.preview.onDragLeave) - .on('drop', OSD.GUI.preview.onDrop) - .data('item', item) - .data('position', i); - // Required for NW.js - Otherwise the will - // consume drag/drop events. - $img.find('img').css('pointer-events', 'none'); - if (item && item.positionable !== false) { - var nameKey = 'osdElement_' + item.name; - var nameMessage = i18n.getMessage(nameKey); - if (!nameMessage) { - nameMessage = inflection.titleize(item.name); + // sidebars + if ($('input[name="HORIZON_SIDEBARS"]').prop('checked')) { + var hudwidth = OSD.constants.AHISIDEBARWIDTHPOSITION; + var hudheight = OSD.constants.AHISIDEBARHEIGHTPOSITION; + for (let i = -hudheight; i <= hudheight; i++) { + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - hudwidth + (i * FONT.constants.SIZES.LINE), SYM.AH_DECORATION); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + hudwidth + (i * FONT.constants.SIZES.LINE), SYM.AH_DECORATION); } + // AH level indicators + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition - hudwidth + 1, SYM.AH_LEFT); + OSD.GUI.checkAndProcessSymbolPosition(hudCenterPosition + hudwidth - 1, SYM.AH_RIGHT); + } - $img.addClass('field-' + item.id) + OSD.GUI.updateMapPreview(centerPosition, 'MAP_NORTH', 'N', SYM.HOME); + OSD.GUI.updateMapPreview(centerPosition, 'MAP_TAKEOFF', 'T', SYM.HOME); + OSD.GUI.updateMapPreview(centerPosition, 'RADAR', null, SYM.DIR_TO_HOME); + + // render + var $preview = $('.display-layout .preview').empty(); + var $row = $('
'); + for (let i = 0; i < OSD.data.display_size.total;) { + var charCode = OSD.data.preview[i]; + var colorStyle = ''; + + if (typeof charCode === 'object') { + var item = OSD.data.preview[i][0]; + charCode = OSD.data.preview[i][1]; + if (OSD.data.preview[i][2] !== undefined) { + // if third field is set it contains a background color + colorStyle = 'style="background-color: ' + OSD.data.preview[i][2] + ';"'; + } + } + var $img = $('
') + .on('mouseenter', OSD.GUI.preview.onMouseEnter) + .on('mouseleave', OSD.GUI.preview.onMouseLeave) + .on('dragover', OSD.GUI.preview.onDragOver) + .on('dragleave', OSD.GUI.preview.onDragLeave) + .on('drop', OSD.GUI.preview.onDrop) .data('item', item) - .prop('draggable', true) - .on('dragstart', OSD.GUI.preview.onDragStart) - .prop('title', nameMessage); - } + .data('position', i); + // Required for NW.js - Otherwise the will + // consume drag/drop events. + $img.find('img').css('pointer-events', 'none'); + if (item && item.positionable !== false) { + var nameKey = 'osdElement_' + item.name; + var nameMessage = i18n.getMessage(nameKey); + + if (!nameMessage) { + nameMessage = inflection.titleize(item.name); + } + + $img.addClass('field-' + item.id) + .data('item', item) + .prop('draggable', true) + .on('dragstart', OSD.GUI.preview.onDragStart) + .prop('title', nameMessage); + } - $row.append($img); - if (++i % OSD.data.display_size.x == 0) { - $preview.append($row); - $row = $('
'); + $row.append($img); + if (++i % OSD.data.display_size.x == 0) { + $preview.append($row); + $row = $('
'); + } } } }; @@ -3338,25 +3340,6 @@ TABS.osd.initialize = function (callback) { // Initialise guides checkbox isGuidesChecked = store.get('showOSDGuides', false); - - // Setup switch indicators - $(".osdSwitchInd_channel option").each(function() { - $(this).text("Ch " + $(this).text()); - }); - - // Function when text for switch indicators change - $('.osdSwitchIndName').on('keyup', function() { - // Make sure that the switch hint only contains A to Z - let testExp = new RegExp('^[A-Za-z0-9]'); - let testText = $(this).val(); - if (testExp.test(testText.slice(-1))) { - $(this).val(testText.toUpperCase()); - } else { - $(this).val(testText.slice(0, -1)); - } - - // Update the OSD preview - }); // Functions for when pan servo settings change $('#osdPanServoIndicatorShowDegrees').on('change', function() { @@ -3501,19 +3484,38 @@ function createCustomElements(){ var customElementTable = $('').addClass('osdCustomElement_main_table'); var customElementRowType = $('').data('row', i); var customElementRowValue = $('').data('row', i); + var customElementLabel = $(''); + customElementLabel.append($('
').attr('colspan', 2).append($('').html(i18n.getMessage("custom_element") + ' ' + (i + 1)))); - for(var ii = 0; ii < 3; ii++){ - + for(var ii = 0; ii < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; ii++){ var select = $('').append(select)); @@ -3525,6 +3527,8 @@ function createCustomElements(){ $('').addClass('value').addClass('gv').html(getGVoptions()).hide() + ).append( + $('').attr('colspan', 2).append($('').html(i18n.getMessage("custom_element") + ' ' + (i + 1)))); - - customElementTable.append(customElementRowType).append(customElementRowValue).append(customElementLabel); + customElementTable.append(customElementLabel).append(customElementRowType).append(customElementRowValue); label.append(customElementTable); customElementsContainer.append(label); } @@ -3565,27 +3568,139 @@ function createCustomElements(){ customElementsInitCallback(); } +function updateOSDCustomElementsDisplay() { + let foundOSDCustomElements = 0; + let generalGroup = OSD.constants.ALL_DISPLAY_GROUPS.filter(function(e) { + return e.name == "osdGroupOSDCustomElements"; + })[0]; + + for (var i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementsCount; i++) { + if ($('.osdCustomElement-' + i + '-part-0-type').val() != undefined) { + for (let si = 0; si < generalGroup.items.length; si++) { + if (generalGroup.items[si].name == "CUSTOM_ELEMENT_" + (i + 1)) { + let preview = ""; + foundOSDCustomElements++; + + for (let ii = 0; ii < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; ii++) { + var typeCell = $('.osdCustomElement-' + i + '-part-' + ii + '-type'); + var valueCell = $('.osdCustomElement-' + i + '-part-' + ii + '-value'); + + switch (parseInt(typeCell.val())) { + case 1: + preview += valueCell.find('.text').val(); + break; + case 2: + preview += FONT.symbol("0x" + parseInt(valueCell.find('.ico').val()).toString(16).toUpperCase()); + break; + case 3: + preview += FONT.symbol(SYM.HOME); + break; + case 4: + case 15: + preview += " 2"; + break; + case 5: + case 16: + preview += " 57"; + break; + case 6: + case 17: + preview += " 316"; + break; + case 7: + case 18: + preview += " 6926"; + break; + case 8: + case 19: + preview += " 36520"; + break; + case 9: + case 20: + preview += " " + FONT.embed_dot("1.6"); + break; + case 10: + case 21: + preview += " " + FONT.embed_dot("21.4"); + break; + case 11: + case 22: + preview += " " + FONT.embed_dot("34.26"); + break; + case 12: + case 23: + preview += " " + FONT.embed_dot("315.7"); + break; + case 13: + case 24: + preview += " " + FONT.embed_dot("562.46"); + break; + case 14: + case 25: + preview += " " + FONT.embed_dot("4629.1"); + break; + } + } + + preview = preview.trim(); + + if (preview == "") { + preview = "CE_" + (i + 1); + } + + generalGroup.items[si].preview = preview; + } + } + } + + if (foundOSDCustomElements >= FC.OSD_CUSTOM_ELEMENTS.settings.customElementsCount) { + break; + } + } + OSD.GUI.updatePreviews(); +} + function fillCustomElementsValues() { for (var i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementsCount; i++) { - for (var ii = 0; ii < 3; ii++) { + for (var ii = 0; ii < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; ii++) { $('.osdCustomElement-' + i + '-part-' + ii + '-type').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].type).trigger('change'); var valueCell = $('.osdCustomElement-' + i + '-part-' + ii + '-value'); - switch (FC.OSD_CUSTOM_ELEMENTS .items[i].customElementItems[ii].type){ + switch (FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].type){ case 1: valueCell.find('.text').val(FC.OSD_CUSTOM_ELEMENTS .items[i].customElementText).trigger('change'); break; case 2: - valueCell.find('.ico').val(FC.OSD_CUSTOM_ELEMENTS .items[i].customElementItems[ii].value).trigger('change'); + valueCell.find('.ico').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; case 3: - valueCell.find('.ico_gv').val(FC.OSD_CUSTOM_ELEMENTS .items[i].customElementItems[ii].value).trigger('change'); + valueCell.find('.ico_gv').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; case 4: case 5: case 6: case 7: - valueCell.find('.gv').val(FC.OSD_CUSTOM_ELEMENTS .items[i].customElementItems[ii].value).trigger('change'); + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + valueCell.find('.gv').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); + break; + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + valueCell.find('.lc').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; } } @@ -3623,7 +3738,7 @@ function customElementsInitCallback() { } function customElementNormaliseRow(row){ - for(var i = 0; i < 3; i++){ + for(var i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; i++){ var elementType = $('.osdCustomElement-' + row + '-part-' + i + '-type'); var valueCell = $('.' + elementType.data('valueCellClass')); @@ -3634,14 +3749,15 @@ function customElementNormaliseRow(row){ break; case 2: valueCell.find('.ico').val(valueCell.find('.ico').val() > 255 ? 255 : valueCell.find('.ico').val()); - valueCell.find('.ico').val(valueCell.find('.ico').val() < 1 ? 1 : valueCell.find('.ico').val()); + valueCell.find('.ico').val((valueCell.find('.ico').val() != '' && valueCell.find('.ico').val() < 1 )? 1 : valueCell.find('.ico').val()); } } + updateOSDCustomElementsDisplay(); } function customElementDisableNonValidOptionsRow(row) { var selectedTextIndex = false; - for(let i = 0; i < 3; i++){ + for(let i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; i++){ let elementType = $('.osdCustomElement-' + row + '-part-' + i + '-type'); if(parseInt(elementType.val()) === 1) @@ -3651,7 +3767,7 @@ function customElementDisableNonValidOptionsRow(row) { } } - for(let i = 0; i < 3; i++){ + for(let i = 0; i < FC.OSD_CUSTOM_ELEMENTS.settings.customElementParts; i++){ let elementType = $('.osdCustomElement-' + row + '-part-' + i + '-type'); if(i !== selectedTextIndex && selectedTextIndex !== false){ elementType.find('option[value="1"]').attr('disabled', 'disabled'); @@ -3686,8 +3802,28 @@ function customElementGetDataForRow(row){ case 5: case 6: case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: partValue = parseInt(valueCell.find('.gv').find(':selected').val()); break; + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + partValue = parseInt(valueCell.find('.lc').find(':selected').val()); + break; } data.push8(parseInt(elementType.val())); From c678871a5b502b958d006fe9cedfebbb92c83eb9 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Wed, 7 Aug 2024 23:15:55 +0300 Subject: [PATCH 4/5] Added icon from logic condition --- tabs/osd.js | 95 ++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/tabs/osd.js b/tabs/osd.js index f520db5f6..2a4b0b02c 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -3493,41 +3493,39 @@ function createCustomElements(){ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + `); customElementRowType.append($('').append(select)); customElementRowValue.append($('').addClass('osdCustomElement-' + i + '-part-' + ii + '-value').append( - $('').addClass('value').addClass('text').attr('type', 'text').attr('maxlength', FC.OSD_CUSTOM_ELEMENTS.settings.customElementTextSize).hide() - ).append( - $('').addClass('value').addClass('ico').attr('min', 1).attr('max', 255).hide() - ).append( - $('').addClass('value').addClass('gv').html(getGVoptions()).hide() - ).append( + $('').addClass('value').addClass('text').attr('type', 'text').attr('maxlength', FC.OSD_CUSTOM_ELEMENTS.settings.customElementTextSize).hide()).append( + $('').addClass('value').addClass('ico').attr('min', 1).attr('max', 255).hide()).append( + $('').addClass('value').addClass('ico_lc').html(getLCoptions()).hide()).append( + $('').addClass('value').addClass('lc').html(getLCoptions()).hide() )); @@ -3596,47 +3594,50 @@ function updateOSDCustomElementsDisplay() { preview += FONT.symbol(SYM.HOME); break; case 4: - case 15: - preview += " 2"; + preview += FONT.symbol(SYM.HOME); break; case 5: case 16: - preview += " 57"; + preview += " 2"; break; case 6: case 17: - preview += " 316"; + preview += " 57"; break; case 7: case 18: - preview += " 6926"; + preview += " 316"; break; case 8: case 19: - preview += " 36520"; + preview += " 6926"; break; case 9: case 20: - preview += " " + FONT.embed_dot("1.6"); + preview += " 36520"; break; case 10: case 21: - preview += " " + FONT.embed_dot("21.4"); + preview += " " + FONT.embed_dot("1.6"); break; case 11: case 22: - preview += " " + FONT.embed_dot("34.26"); + preview += " " + FONT.embed_dot("21.4"); break; case 12: case 23: - preview += " " + FONT.embed_dot("315.7"); + preview += " " + FONT.embed_dot("34.26"); break; case 13: case 24: - preview += " " + FONT.embed_dot("562.46"); + preview += " " + FONT.embed_dot("315.7"); break; case 14: case 25: + preview += " " + FONT.embed_dot("562.46"); + break; + case 15: + case 26: preview += " " + FONT.embed_dot("4629.1"); break; } @@ -3677,6 +3678,8 @@ function fillCustomElementsValues() { valueCell.find('.ico_gv').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; case 4: + valueCell.find('.ico_lc').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); + break; case 5: case 6: case 7: @@ -3687,9 +3690,9 @@ function fillCustomElementsValues() { case 12: case 13: case 14: + case 15: valueCell.find('.gv').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; - case 15: case 16: case 17: case 18: @@ -3700,6 +3703,7 @@ function fillCustomElementsValues() { case 23: case 24: case 25: + case 26: valueCell.find('.lc').val(FC.OSD_CUSTOM_ELEMENTS.items[i].customElementItems[ii].value).trigger('change'); break; } @@ -3799,6 +3803,8 @@ function customElementGetDataForRow(row){ partValue = parseInt(valueCell.find('.ico_gv').find(':selected').val()); break; case 4: + partValue = parseInt(valueCell.find('.ico_lc').find(':selected').val()); + break; case 5: case 6: case 7: @@ -3809,9 +3815,9 @@ function customElementGetDataForRow(row){ case 12: case 13: case 14: + case 15: partValue = parseInt(valueCell.find('.gv').find(':selected').val()); break; - case 15: case 16: case 17: case 18: @@ -3822,6 +3828,7 @@ function customElementGetDataForRow(row){ case 23: case 24: case 25: + case 26: partValue = parseInt(valueCell.find('.lc').find(':selected').val()); break; } From 41e9d8330304522a39d07abb244f893a9f0c0299 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Wed, 11 Sep 2024 20:51:38 +0100 Subject: [PATCH 5/5] Added switch indicators back in --- locale/en/messages.json | 36 +++++++++++++++++ tabs/osd.html | 36 +++++++++++++++++ tabs/osd.js | 89 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 156 insertions(+), 5 deletions(-) diff --git a/locale/en/messages.json b/locale/en/messages.json index 6cee73902..1bb95fd38 100644 --- a/locale/en/messages.json +++ b/locale/en/messages.json @@ -4204,6 +4204,21 @@ "osdElement_ESC_TEMPERATURE_HELP": { "message": "Temperature of the ESC read from DSHOT telemetry" }, + "osdGroupSwitchIndicators": { + "message": "Switch Indicators" + }, + "osdElement_SWITCH_INDICATOR_0": { + "message": "Switch Indicator 1" + }, + "osdElement_SWITCH_INDICATOR_1": { + "message": "Switch Indicator 2" + }, + "osdElement_SWITCH_INDICATOR_2": { + "message": "Switch Indicator 3" + }, + "osdElement_SWITCH_INDICATOR_3": { + "message": "Switch Indicator 4" + }, "osd_pan_servo_settings": { "message": "Pan Servo OSD Settings" }, @@ -4321,6 +4336,27 @@ "osd_dji_cn_alternating_duration": { "message": "Craft Name alternating duration (in 1/10 sec)" }, + "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" + }, + "osdSwitchInd0": { + "message": "Switch 1" + }, + "osdSwitchInd1": { + "message": "Switch 2" + }, + "osdSwitchInd2": { + "message": "Switch 3" + }, + "osdSwitchInd3": { + "message": "Switch 4" + }, "osd_font_default": { "message": "Default" }, diff --git a/tabs/osd.html b/tabs/osd.html index 3ec5ea035..dbf20bdef 100644 --- a/tabs/osd.html +++ b/tabs/osd.html @@ -302,6 +302,42 @@

+
+
+
+
+
+
+ + + + + + + + +
+
+
diff --git a/tabs/osd.js b/tabs/osd.js index 2a4b0b02c..bfc8ce39b 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -554,6 +554,7 @@ OSD.DjiElements = { "Timers", "VTX", "CRSF", + "SwitchIndicators", "OSDCustomElements", "GVars", "PIDs", @@ -1849,6 +1850,35 @@ 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: 'osdGroupOSDCustomElements', items: [ @@ -1875,35 +1905,35 @@ OSD.constants = { }, { name: 'CUSTOM_ELEMENT_4', - id: 130, + id: 154, min_version: '8.0.0', positionable: true, preview: "CE_4", }, { name: 'CUSTOM_ELEMENT_5', - id: 131, + id: 155, min_version: '8.0.0', positionable: true, preview: "CE_5", }, { name: 'CUSTOM_ELEMENT_6', - id: 132, + id: 156, min_version: '8.0.0', positionable: true, preview: "CE_6", }, { name: 'CUSTOM_ELEMENT_7', - id: 133, + id: 157, min_version: '8.0.0', positionable: true, preview: "CE_7", }, { name: 'CUSTOM_ELEMENT_8', - id: 154, + id: 158, min_version: '8.0.0', positionable: true, preview: "CE_8", @@ -2824,6 +2854,7 @@ OSD.GUI.updateFields = function() { GUI.switchery(); // Update the OSD preview + refreshOSDSwitchIndicators(); updatePilotAndCraftNames(); updatePanServoPreview(); }; @@ -3340,6 +3371,31 @@ TABS.osd.initialize = function (callback) { // Initialise guides checkbox isGuidesChecked = store.get('showOSDGuides', false); + + // Setup switch indicators + $(".osdSwitchInd_channel option").each(function() { + $(this).text("Ch " + $(this).text()); + }); + + // Function when text for switch indicators change + $('.osdSwitchIndName').on('keyup', function() { + // Make sure that the switch hint only contains A to Z + let testExp = new RegExp('^[A-Za-z0-9]'); + let testText = $(this).val(); + if (testExp.test(testText.slice(-1))) { + $(this).val(testText.toUpperCase().slice(0, 4)); + } else { + $(this).val(testText.slice(0, -1)); + } + + // 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 $('#osdPanServoIndicatorShowDegrees').on('change', function() { @@ -3883,6 +3939,29 @@ function getLCoptions(){ 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; + } + } + } + } + + OSD.GUI.updatePreviews(); +} + function updatePilotAndCraftNames() { let foundPilotName = ($('#pilot_name').val() == undefined); let foundCraftName = ($('#craft_name').val() == undefined);