From 51f0fde162aaebfbc5e61bb26209426e18b23e8e Mon Sep 17 00:00:00 2001 From: druckgott Date: Mon, 18 Nov 2024 17:52:25 +0100 Subject: [PATCH] Update MSPHelper.js add aurora effect switch Update led_strip.js Update MSPHelper.js --- locales/en/messages.json | 4 ++++ src/js/msp/MSPHelper.js | 10 ++++---- src/js/tabs/led_strip.js | 50 ++++++++++++++++++++++++++++------------ src/tabs/led_strip.html | 5 ++++ 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 5436277292..5827fab74e 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -3974,6 +3974,10 @@ "message": "Larson scanner", "description": "Larson effect switch label on LED Strip tab" }, + "ledStripAuroraOverlay": { + "message": "Aurora Effect", + "description": "Aurora effect switch label on LED Strip tab" + }, "ledStripBlinkAlwaysOverlay": { "message": "Blink always" }, diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 73c98d4be3..f565d83cd9 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -21,7 +21,7 @@ import { reinitializeConnection } from "../serial_backend"; // Used for LED_STRIP const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order const ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r', 'p', 'e', 'u']; // in LSB bit -let ledOverlayLetters = ['t', 'y', 'o', 'b', 'v', 'i', 'w']; // in LSB bit +let ledOverlayLetters = ['t', 'y', 'o', 'x', 'b', 'v', 'i', 'w']; // in LSB bit function MspHelper() { const self = this; @@ -1220,7 +1220,7 @@ MspHelper.prototype.process_data = function(dataHandler) { } } - const overlayMask = (mask >> 12) & 0x3FF; + const overlayMask = (mask >> 13) & 0x3FF; for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { if (bit_check(overlayMask, overlayLetterIndex)) { functions.push(ledOverlayLetters[overlayLetterIndex]); @@ -1260,7 +1260,7 @@ MspHelper.prototype.process_data = function(dataHandler) { } } - const overlayMask = (mask >> 12) & 0x3F; + const overlayMask = (mask >> 13) & 0x3F; for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { if (bit_check(overlayMask, overlayLetterIndex)) { functions.push(ledOverlayLetters[overlayLetterIndex]); @@ -2591,7 +2591,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 12); + mask |= bit_set(mask, bitIndex + 13); } } @@ -2609,7 +2609,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 12); + mask |= bit_set(mask, bitIndex + 13); } } diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index f2e9d10c03..a31852fc20 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -20,7 +20,7 @@ led_strip.initialize = function (callback, scrollPosition) { TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l', 'o', 'y']; TABS.led_strip.baseFuncs = ['c', 'f', 'a', 'l', 's', 'g', 'r', 'p', 'e', 'u']; - TABS.led_strip.overlays = ['t', 'y', 'o', 'b', 'v', 'i', 'w']; + TABS.led_strip.overlays = ['t', 'y', 'o', 'x', 'b', 'v', 'i', 'w']; if (semver.lt(FC.CONFIG.apiVersion,API_VERSION_1_46)) { TABS.led_strip.overlays = TABS.led_strip.overlays.filter(x => x !== 'y'); @@ -456,6 +456,7 @@ led_strip.initialize = function (callback, scrollPosition) { case 't': case 'y': case 'o': + case 'x': case 's': if (areModifiersActive(`function-${f}`)) p.addClass(`function-${letter}`); @@ -489,28 +490,46 @@ led_strip.initialize = function (callback, scrollPosition) { return $(that).is(':checked'); } + // Disable all other functions except the one being activated + function disableOtherFunctions(activeFunction) { + const functions = ['.function-o', '.function-b', '.function-x']; + + functions.forEach(func => { + if (!activeFunction.is(func)) { + const checkbox = $(`.checkbox ${func}`); + if (checkbox.is(':checked')) { + checkbox.prop('checked', false); + checkbox.trigger('change'); + toggleSwitch(checkbox, func.slice(-1)); // Pass the last character as the identifier + } + } + }); + } + // UI: check-box toggle $('.checkbox').on('change', function(e) { if (e.originalEvent) { // user-triggered event const that = $(this).find('input'); - //disable Blink always or Larson scanner, both functions are not working properly at the same time - if (that.is('.function-o')) { - const blink = $('.checkbox .function-b'); - if (blink.is(':checked')) { - blink.prop('checked', false); - blink.trigger('change'); - toggleSwitch(blink, 'b'); + // Event handlers for each function + $('.checkbox .function-o').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); + } + }); + + $('.checkbox .function-b').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); } - } else if (that.is('.function-b')) { - const larson = $('.checkbox .function-o'); - if ($('.checkbox .function-o').is(':checked')) { - larson.prop('checked', false); - larson.trigger('change'); - toggleSwitch(larson, 'o'); + }); + + $('.checkbox .function-x').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); } - } + }); //Change Rainbow slider visibility if (that.is('.function-y')) { @@ -827,6 +846,7 @@ led_strip.initialize = function (callback, scrollPosition) { case "function-r": case "function-y": case "function-o": + case "function-x": case "function-b": case "function-g": return true; diff --git a/src/tabs/led_strip.html b/src/tabs/led_strip.html index 0ec77fbaa5..59b8a4cba2 100644 --- a/src/tabs/led_strip.html +++ b/src/tabs/led_strip.html @@ -83,6 +83,11 @@ +
+ + +
+