Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aurora effect switch #4253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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