Skip to content

Commit

Permalink
Update MSPHelper.js
Browse files Browse the repository at this point in the history
add aurora effect switch

Update led_strip.js

Update MSPHelper.js
  • Loading branch information
druckgott committed Nov 18, 2024
1 parent 82021fd commit 51f0fde
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
4 changes: 4 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 5 additions & 5 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
50 changes: 35 additions & 15 deletions src/js/tabs/led_strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/tabs/led_strip.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<label> <span i18n="ledStripLarsonOverlay"></span></label>
</div>

<div class="checkbox">
<input type="checkbox" name="Aurora" class="toggle function-x" />
<label> <span i18n="ledStripAuroraOverlay"></span></label>
</div>

<div class="checkbox">
<input type="checkbox" name="blink" class="toggle function-b" />
<label> <span i18n="ledStripBlinkAlwaysOverlay"></span></label>
Expand Down

0 comments on commit 51f0fde

Please sign in to comment.