1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-19 14:25:14 +03:00

Merge branch 'master' into chore/add-prettier

This commit is contained in:
Tomas Chmelevskij 2020-12-27 09:23:52 +04:00 committed by GitHub
commit e9a57f279b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 134 additions and 124 deletions

View file

@ -30,13 +30,14 @@ trigger:
branches: branches:
include: include:
- master - master
- "*-maintenance"
pr: pr:
drafts: false drafts: false
branches: branches:
include: include:
- master - master
- "*-maintenance" - "*-maintenance"
stages: stages:
- stage: Build - stage: Build

View file

@ -51,7 +51,7 @@ const NODE_ENV = process.env.NODE_ENV || 'production';
let gitChangeSetId; let gitChangeSetId;
const nwBuilderOptions = { const nwBuilderOptions = {
version: '0.47.0', version: '0.50.2',
files: `${DIST_DIR}**/*`, files: `${DIST_DIR}**/*`,
macIcns: './src/images/bf_icon.icns', macIcns: './src/images/bf_icon.icns',
macPlist: { 'CFBundleDisplayName': 'Betaflight Configurator'}, macPlist: { 'CFBundleDisplayName': 'Betaflight Configurator'},

View file

@ -682,12 +682,12 @@ function update_live_status() {
$(".armedicon").removeClass('active'); $(".armedicon").removeClass('active');
} }
} }
} if (FC.AUX_CONFIG[i] === 'FAILSAFE') {
if (FC.AUX_CONFIG[index] === 'FAILSAFE') { if (bit_check(FC.CONFIG.mode, i)) {
if (bit_check(FC.CONFIG.mode, i)) { $(".failsafeicon").addClass('active');
$(".failsafeicon").addClass('active'); } else {
} else { $(".failsafeicon").removeClass('active');
$(".failsafeicon").removeClass('active'); }
} }
} }

View file

@ -414,7 +414,7 @@ TABS.auxiliary.initialize = function (callback) {
const percentage = (channelPosition - 900) / (2100-900) * 100; const percentage = (channelPosition - 900) / (2100-900) * 100;
$('.modes .ranges .range').each( function () { $('.modes .ranges .range').each( function () {
const auxChannelCandidateIndex = $(this).find('.channel').val(); const auxChannelCandidateIndex = parseInt($(this).find('.channel').val());
if (auxChannelCandidateIndex !== auxChannelIndex) { if (auxChannelCandidateIndex !== auxChannelIndex) {
return; return;
} }

View file

@ -7,9 +7,8 @@ TABS.led_strip = {
TABS.led_strip.initialize = function (callback, scrollPosition) { TABS.led_strip.initialize = function (callback, scrollPosition) {
var self = this; let selectedColorIndex = null;
var selectedColorIndex = null; let selectedModeColor = null;
var selectedModeColor = null;
if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) {
TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b']; TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b'];
@ -54,9 +53,9 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
load_led_config(); load_led_config();
function buildUsedWireNumbers() { function buildUsedWireNumbers() {
var usedWireNumbers = []; const usedWireNumbers = [];
$('.mainGrid .gPoint .wire').each(function () { $('.mainGrid .gPoint .wire').each(function () {
var wireNumber = parseInt($(this).html()); const wireNumber = parseInt($(this).html());
if (wireNumber >= 0) { if (wireNumber >= 0) {
usedWireNumbers.push(wireNumber); usedWireNumbers.push(wireNumber);
} }
@ -69,10 +68,12 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
i18n.localizePage(); i18n.localizePage();
const functionTag = '.function-';
// Build Grid // Build Grid
var theHTML = []; const theHTML = [];
var theHTMLlength = 0; let theHTMLlength = 0;
for (var i = 0; i < 256; i++) { for (let i = 0; i < 256; i++) {
if (semver.lte(FC.CONFIG.apiVersion, "1.19.0")) { if (semver.lte(FC.CONFIG.apiVersion, "1.19.0")) {
theHTML[theHTMLlength++] = ('<div class="gPoint"><div class="indicators"><span class="north"></span><span class="south"></span><span class="west"></span><span class="east"></span><span class="up">U</span><span class="down">D</span></div><span class="wire"></span><span class="overlay-t"> </span><span class="overlay-s"> </span><span class="overlay-w"> </span><span class="overlay-i"> </span><span class="overlay-color"> </span></div>'); theHTML[theHTMLlength++] = ('<div class="gPoint"><div class="indicators"><span class="north"></span><span class="south"></span><span class="west"></span><span class="east"></span><span class="up">U</span><span class="down">D</span></div><span class="wire"></span><span class="overlay-t"> </span><span class="overlay-s"> </span><span class="overlay-w"> </span><span class="overlay-i"> </span><span class="overlay-color"> </span></div>');
} else if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { } else if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
@ -95,8 +96,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.auxSelect').show(); $('.auxSelect').show();
$('.labelSelect').hide(); $('.labelSelect').hide();
var AuxMode = 7; const AuxMode = 7;
var AuxDir = 0; const AuxDir = 0;
$('.auxSelect').val(getModeColor(AuxMode, AuxDir)); $('.auxSelect').val(getModeColor(AuxMode, AuxDir));
@ -140,7 +141,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
}); });
function removeFunctionsAndDirections(element) { function removeFunctionsAndDirections(element) {
var classesToRemove = []; const classesToRemove = [];
TABS.led_strip.baseFuncs.forEach(function(letter) { TABS.led_strip.baseFuncs.forEach(function(letter) {
classesToRemove.push('function-' + letter); classesToRemove.push('function-' + letter);
@ -156,7 +157,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// Directional Buttons // Directional Buttons
$('.directions').on('click', 'button', function() { $('.directions').on('click', 'button', function() {
var that = this; const that = this;
if ($('.ui-selected').length > 0) { if ($('.ui-selected').length > 0) {
TABS.led_strip.directions.forEach(function(letter) { TABS.led_strip.directions.forEach(function(letter) {
if ($(that).is('.dir-' + letter)) { if ($(that).is('.dir-' + letter)) {
@ -177,7 +178,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// Mode Color Buttons // Mode Color Buttons
$('.mode_colors').on('click', 'button', function() { $('.mode_colors').on('click', 'button', function() {
var that = this; const that = this;
FC.LED_MODE_COLORS.forEach(function(mc) { FC.LED_MODE_COLORS.forEach(function(mc) {
if ($(that).is('.mode_color-' + mc.mode + '-' + mc.direction)) { if ($(that).is('.mode_color-' + mc.mode + '-' + mc.direction)) {
if ($(that).is('.btnOn')) { if ($(that).is('.btnOn')) {
@ -189,8 +190,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
selectedModeColor = { mode: mc.mode, direction: mc.direction }; selectedModeColor = { mode: mc.mode, direction: mc.direction };
// select the color button // select the color button
for (var colorIndex = 0; colorIndex < 16; colorIndex++) { for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
var className = '.color-' + colorIndex; const className = '.color-' + colorIndex;
if (colorIndex == getModeColor(mc.mode, mc.direction)) { if (colorIndex == getModeColor(mc.mode, mc.direction)) {
$(className).addClass('btnOn'); $(className).addClass('btnOn');
selectedColorIndex = colorIndex; selectedColorIndex = colorIndex;
@ -219,11 +220,11 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
}); });
// Color sliders // Color sliders
var ip = $('div.colorDefineSliders input'); const ip = $('div.colorDefineSliders input');
ip.eq(0).on("input change", function() { updateColors($(this).val(), 0); }); ip.eq(0).on("input change", function() { updateColors($(this).val(), 0); });
ip.eq(1).on("input change", function() { updateColors($(this).val(), 1); }); ip.eq(1).on("input change", function() { updateColors($(this).val(), 1); });
ip.eq(2).on("input change", function() { updateColors($(this).val(), 2); }); ip.eq(2).on("input change", function() { updateColors($(this).val(), 2); });
for (var i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
updateColors(ip.eq(i).val(), i); updateColors(ip.eq(i).val(), i);
} }
@ -231,10 +232,10 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// Color Buttons // Color Buttons
$('.colors').on('click', 'button', function(e) { $('.colors').on('click', 'button', function(e) {
var that = this; const that = this;
var colorButtons = $(this).parent().find('button'); const colorButtons = $(this).parent().find('button');
for (var colorIndex = 0; colorIndex < 16; colorIndex++) { for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
colorButtons.removeClass('btnOn'); colorButtons.removeClass('btnOn');
if (selectedModeColor == undefined) if (selectedModeColor == undefined)
$('.ui-selected').removeClass('color-' + colorIndex); $('.ui-selected').removeClass('color-' + colorIndex);
@ -299,8 +300,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.funcWireClearSelect').click(function() { $('.funcWireClearSelect').click(function() {
$('.ui-selected').each(function() { $('.ui-selected').each(function() {
var thisWire = $(this).find('.wire'); const thisWire = $(this).find('.wire');
if (thisWire.html() != '') { if (thisWire.html() !== '') {
thisWire.html(''); thisWire.html('');
} }
updateBulkCmd(); updateBulkCmd();
@ -315,18 +316,17 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.mainGrid').selectable({ $('.mainGrid').selectable({
filter: ' > div', filter: ' > div',
stop: function() { stop: function() {
var functionsInSelection = []; const directionsInSelection = [];
var directionsInSelection = [];
clearModeColorSelection(); clearModeColorSelection();
var that; let that;
$('.ui-selected').each(function() { $('.ui-selected').each(function() {
var usedWireNumbers = buildUsedWireNumbers(); const usedWireNumbers = buildUsedWireNumbers();
var nextWireNumber = 0; let nextWireNumber = 0;
for (var nextWireNumber = 0; nextWireNumber < usedWireNumbers.length; nextWireNumber++) { for (; nextWireNumber < usedWireNumbers.length; nextWireNumber++) {
if (usedWireNumbers[nextWireNumber] != nextWireNumber) { if (usedWireNumbers[nextWireNumber] != nextWireNumber) {
break; break;
} }
@ -344,21 +344,21 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// Get function & overlays or current cell // Get function & overlays or current cell
TABS.led_strip.directions.forEach(function(letter) { TABS.led_strip.directions.forEach(function(letter) {
var className = '.dir-' + letter; const className = '.dir-' + letter;
if ($(that).is(className)) { if ($(that).is(className)) {
directionsInSelection.push(className); directionsInSelection.push(className);
} }
}); });
TABS.led_strip.baseFuncs.forEach(function(letter) { TABS.led_strip.baseFuncs.forEach(function(letter) {
var className = '.function-' + letter; const className = '.function-' + letter;
if ($(that).is(className)) { if ($(that).is(className)) {
functionsInSelection.push(className); functionsInSelection.push(className);
} }
}); });
TABS.led_strip.overlays.forEach(function(letter) { TABS.led_strip.overlays.forEach(function(letter) {
var className = '.function-' + letter; const className = '.function-' + letter;
if ($(that).is(className)) { if ($(that).is(className)) {
functionsInSelection.push(className); functionsInSelection.push(className);
} }
@ -366,11 +366,11 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
} }
}); });
var uiSelectedLast = that; const uiSelectedLast = that;
$('select.functionSelect').val(""); $('select.functionSelect').val("");
TABS.led_strip.baseFuncs.forEach(function(letter) { TABS.led_strip.baseFuncs.forEach(function(letter) {
var className = 'function-' + letter; const className = 'function-' + letter;
if ($('select.functionSelect').is("." + className)) { if ($('select.functionSelect').is("." + className)) {
$('select.functionSelect').removeClass(className); $('select.functionSelect').removeClass(className);
} }
@ -381,8 +381,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
if (uiSelectedLast) { if (uiSelectedLast) {
// set active color // set active color
for (var colorIndex = 0; colorIndex < 16; colorIndex++) { for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
var className = '.color-' + colorIndex; const className = '.color-' + colorIndex;
if ($(uiSelectedLast).is(className)) { if ($(uiSelectedLast).is(className)) {
$(className).addClass('btnOn'); $(className).addClass('btnOn');
selectedColorIndex = colorIndex; selectedColorIndex = colorIndex;
@ -394,11 +394,11 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// set checkbox values // set checkbox values
TABS.led_strip.overlays.forEach(function(letter) { TABS.led_strip.overlays.forEach(function(letter) {
var feature_o = $('.checkbox').find('input.function-' + letter); const feature_o = $('.checkbox').find(`input.function-${letter}`);
var newVal = ($(uiSelectedLast).is('.function-' + letter)); const newVal = ($(uiSelectedLast).is(functionTag + letter));
if (feature_o.is(':checked') != newVal) { if (feature_o.is(':checked') !== newVal) {
feature_o.prop('checked', newVal); feature_o.prop('checked', newVal);
feature_o.change(); feature_o.change();
} }
@ -406,7 +406,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// Update active function in combobox // Update active function in combobox
TABS.led_strip.baseFuncs.forEach(function(letter) { TABS.led_strip.baseFuncs.forEach(function(letter) {
if ($(uiSelectedLast).is('.function-' + letter)) { if ($(uiSelectedLast).is(functionTag + letter)) {
$('select.functionSelect').val("function-" + letter); $('select.functionSelect').val("function-" + letter);
$('select.functionSelect').addClass("function-" + letter); $('select.functionSelect').addClass("function-" + letter);
} }
@ -437,16 +437,18 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
// UI: select mode from drop-down // UI: select mode from drop-down
$('.modeSelect').on('change', function() { $('.modeSelect').on('change', function() {
var that = this; const that = this;
var mode = Number($(that).val()); const mode = Number($(that).val());
$('.mode_colors').find('button').each(function() { $('.mode_colors').find('button').each(function() {
for (var i = 0; i < 6; i++) for (let i = 0; i < 6; i++) {
for (var j = 0; j < 6; j++) for (let j = 0; j < 6; j++) {
if ($(this).hasClass('mode_color-' + i + '-' + j)) { if ($(this).hasClass('mode_color-' + i + '-' + j)) {
$(this).removeClass('mode_color-' + i + '-' + j); $(this).removeClass('mode_color-' + i + '-' + j);
$(this).addClass('mode_color-' + mode + '-' + j); $(this).addClass('mode_color-' + mode + '-' + j);
} }
}
}
}); });
$('.mode_colors').each(function() { setModeBackgroundColor($(this)); }); $('.mode_colors').each(function() { setModeBackgroundColor($(this)); });
@ -458,10 +460,10 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.ui-selected').find('.wire').each(function() { $('.ui-selected').find('.wire').each(function() {
if ($(this).text() != "") { if ($(this).text() != "") {
var p = $(this).parent(); const p = $(this).parent();
TABS.led_strip.functions.forEach(function(f) { TABS.led_strip.functions.forEach(function(f) {
if (p.is('.function-' + f)) { if (p.is(functionTag + f)) {
switch (letter) { switch (letter) {
case 't': case 't':
@ -504,15 +506,15 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.checkbox').change(function(e) { $('.checkbox').change(function(e) {
if (e.originalEvent) { if (e.originalEvent) {
// user-triggered event // user-triggered event
var that = $(this).find('input'); const that = $(this).find('input');
if ($('.ui-selected').length > 0) { if ($('.ui-selected').length > 0) {
TABS.led_strip.overlays.forEach(function(letter) { TABS.led_strip.overlays.forEach(function(letter) {
if ($(that).is('.function-' + letter)) { if ($(that).is(functionTag + letter)) {
var ret = toggleSwitch(that, letter); const ret = toggleSwitch(that, letter);
var cbn = $('.checkbox .function-n'); // blink on landing const cbn = $('.checkbox .function-n'); // blink on landing
var cbb = $('.checkbox .function-b'); // blink const cbb = $('.checkbox .function-b'); // blink
if (ret) { if (ret) {
if (letter == 'b' && cbn.is(':checked')) { if (letter == 'b' && cbn.is(':checked')) {
@ -542,20 +544,20 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.mainGrid').disableSelection(); $('.mainGrid').disableSelection();
$('.gPoint').each(function(){ $('.gPoint').each(function(){
var gridNumber = ($(this).index() + 1); const gridNumber = ($(this).index() + 1);
var row = Math.ceil(gridNumber / 16) - 1; const row = Math.ceil(gridNumber / 16) - 1;
var col = gridNumber / 16 % 1 * 16 - 1; let col = gridNumber / 16 % 1 * 16 - 1;
if (col < 0) { if (col < 0) {
col = 15; col = 15;
} }
var ledResult = findLed(col, row); const ledResult = findLed(col, row);
if (!ledResult) { if (!ledResult) {
return; return;
} }
var ledIndex = ledResult.index; const ledIndex = ledResult.index;
var led = ledResult.led; const led = ledResult.led;
if (led.functions[0] == 'c' && led.functions.length == 1 && led.directions.length == 0 && led.color == 0 && led.x == 0 && led.y == 0) { if (led.functions[0] == 'c' && led.functions.length == 1 && led.directions.length == 0 && led.color == 0 && led.x == 0 && led.y == 0) {
return; return;
@ -563,15 +565,15 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$(this).find('.wire').html(ledIndex); $(this).find('.wire').html(ledIndex);
for (var modeIndex = 0; modeIndex < led.functions.length; modeIndex++) { for (let modeIndex = 0; modeIndex < led.functions.length; modeIndex++) {
$(this).addClass('function-' + led.functions[modeIndex]); $(this).addClass(`function-'${led.functions[modeIndex]}`);
} }
for (var directionIndex = 0; directionIndex < led.directions.length; directionIndex++) { for (let directionIndex = 0; directionIndex < led.directions.length; directionIndex++) {
$(this).addClass('dir-' + led.directions[directionIndex]); $(this).addClass(`dir-${led.directions[directionIndex]}`);
} }
$(this).addClass('color-' + led.color); $(this).addClass(`color-${led.color}`);
}); });
@ -621,8 +623,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function findLed(x, y) { function findLed(x, y) {
for (var ledIndex = 0; ledIndex < FC.LED_STRIP.length; ledIndex++) { for (let ledIndex = 0; ledIndex < FC.LED_STRIP.length; ledIndex++) {
var led = FC.LED_STRIP[ledIndex]; const led = FC.LED_STRIP[ledIndex];
if (led.x == x && led.y == y) { if (led.x == x && led.y == y) {
return { index: ledIndex, led: led }; return { index: ledIndex, led: led };
} }
@ -632,35 +634,35 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function updateBulkCmd() { function updateBulkCmd() {
var ledStripLength = FC.LED_STRIP.length; const ledStripLength = FC.LED_STRIP.length;
FC.LED_STRIP = []; FC.LED_STRIP = [];
$('.gPoint').each(function(){ $('.gPoint').each(function(){
if ($(this).is('[class*="function"]')) { if ($(this).is('[class*="function"]')) {
var gridNumber = ($(this).index() + 1); const gridNumber = ($(this).index() + 1);
var row = Math.ceil(gridNumber / 16) - 1; const row = Math.ceil(gridNumber / 16) - 1;
var col = gridNumber/16 % 1 * 16 - 1; let col = gridNumber/16 % 1 * 16 - 1;
if (col < 0) {col = 15;} if (col < 0) {col = 15;}
var wireNumber = $(this).find('.wire').html(); const wireNumber = $(this).find('.wire').html();
var functions = ''; let functions = '';
var directions = ''; let directions = '';
var colorIndex = 0; let colorIndex = 0;
var that = this; const that = this;
var match = $(this).attr("class").match(/(^|\s)color-([0-9]+)(\s|$)/); const match = $(this).attr("class").match(/(^|\s)color-([0-9]+)(\s|$)/);
if (match) { if (match) {
colorIndex = match[2]; colorIndex = match[2];
} }
TABS.led_strip.baseFuncs.forEach(function(letter){ TABS.led_strip.baseFuncs.forEach(function(letter){
if ($(that).is('.function-' + letter)) { if ($(that).is(functionTag + letter)) {
functions += letter; functions += letter;
} }
}); });
TABS.led_strip.overlays.forEach(function(letter){ TABS.led_strip.overlays.forEach(function(letter){
if ($(that).is('.function-' + letter)) { if ($(that).is(functionTag + letter)) {
functions += letter; functions += letter;
} }
}); });
@ -672,36 +674,36 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
}); });
if (wireNumber != '') { if (wireNumber != '') {
var led = { const led = {
x: col, x: col,
y: row, y: row,
directions: directions, directions: directions,
functions: functions, functions: functions,
color: colorIndex color: colorIndex,
} };
FC.LED_STRIP[wireNumber] = led; FC.LED_STRIP[wireNumber] = led;
} }
} }
}); });
var defaultLed = { const defaultLed = {
x: 0, x: 0,
y: 0, y: 0,
directions: '', directions: '',
functions: '' functions: ''
}; };
for (var i = 0; i < ledStripLength; i++) { for (let i = 0; i < ledStripLength; i++) {
if (FC.LED_STRIP[i]) { if (FC.LED_STRIP[i]) {
continue; continue;
} }
FC.LED_STRIP[i] = defaultLed; FC.LED_STRIP[i] = defaultLed;
} }
var usedWireNumbers = buildUsedWireNumbers(); const usedWireNumbers = buildUsedWireNumbers();
var remaining = FC.LED_STRIP.length - usedWireNumbers.length; const remaining = FC.LED_STRIP.length - usedWireNumbers.length;
$('.wires-remaining div').html(remaining); $('.wires-remaining div').html(remaining);
} }
@ -710,10 +712,10 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function setModeBackgroundColor(element) { function setModeBackgroundColor(element) {
if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) {
element.find('[class*="mode_color"]').each(function() { element.find('[class*="mode_color"]').each(function() {
var m = 0; let m = 0;
var d = 0; let d = 0;
var match = $(this).attr("class").match(/(^|\s)mode_color-([0-9]+)-([0-9]+)(\s|$)/); const match = $(this).attr("class").match(/(^|\s)mode_color-([0-9]+)-([0-9]+)(\s|$)/);
if (match) { if (match) {
m = Number(match[2]); m = Number(match[2]);
d = Number(match[3]); d = Number(match[3]);
@ -725,9 +727,9 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function setBackgroundColor(element) { function setBackgroundColor(element) {
if (element.is('[class*="color"]')) { if (element.is('[class*="color"]')) {
var colorIndex = 0; let colorIndex = 0;
var match = element.attr("class").match(/(^|\s)color-([0-9]+)(\s|$)/); const match = element.attr("class").match(/(^|\s)color-([0-9]+)(\s|$)/);
if (match) { if (match) {
colorIndex = match[2]; colorIndex = match[2];
element.css('background-color', HsvToColor(FC.LED_COLORS[colorIndex])); element.css('background-color', HsvToColor(FC.LED_COLORS[colorIndex]));
@ -741,6 +743,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
case "function-a": case "function-a":
case "function-f": case "function-f":
return true; return true;
default:
break;
} }
return false; return false;
} }
@ -753,6 +757,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
case "function-f": case "function-f":
case "function-g": case "function-g":
return true; return true;
default:
break;
} }
} else { } else {
switch (activeFunction) { switch (activeFunction) {
@ -766,6 +772,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
case "function-o": case "function-o":
case "function-g": case "function-g":
return true; return true;
default:
break;
} }
} }
return false; return false;
@ -778,6 +786,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
case "function-a": case "function-a":
case "function-f": case "function-f":
return true; return true;
default:
break;
} }
} }
return false; return false;
@ -791,9 +801,10 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
return false; return false;
case "function-r": case "function-r":
case "function-b": case "function-b":
if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) {
return false; return false;
break; }
break;
default: default:
return true; return true;
} }
@ -815,7 +826,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function setOptionalGroupsVisibility() { function setOptionalGroupsVisibility() {
var activeFunction = $('select.functionSelect').val(); const activeFunction = $('select.functionSelect').val();
$('select.functionSelect').addClass(activeFunction); $('select.functionSelect').addClass(activeFunction);
@ -858,19 +869,17 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
if (isVtxActive(activeFunction)) if (isVtxActive(activeFunction))
$('.vtxOverlay').show(); $('.vtxOverlay').show();
// set directions visibility // set directions visibility
if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) {
switch (activeFunction) { switch (activeFunction) {
case "function-r": case "function-r":
$('.indicatorOverlay').hide(); $('.indicatorOverlay').hide();
$('.directions').hide(); $('.directions').hide();
break; break;
default: default:
$('.indicatorOverlay').show(); $('.indicatorOverlay').show();
$('.directions').show(); $('.directions').show();
break; break;
} }
} }
@ -878,9 +887,11 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) {
// set mode colors visibility // set mode colors visibility
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
if (activeFunction == "function-f") if (activeFunction === "function-f") {
$('.mode_colors').show(); $('.mode_colors').show();
}
}
// set special colors visibility // set special colors visibility
$('.special_colors').show(); $('.special_colors').show();
@ -923,7 +934,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
} }
function applyFunctionToSelectedLeds() { function applyFunctionToSelectedLeds() {
var activeFunction = $('select.functionSelect').val(); const activeFunction = $('select.functionSelect').val();
TABS.led_strip.baseFuncs.forEach(function(letter) { TABS.led_strip.baseFuncs.forEach(function(letter) {
if (activeFunction == 'function-' + letter) { if (activeFunction == 'function-' + letter) {
@ -982,18 +993,18 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('input.function-' + overlay).prop('checked', false); $('input.function-' + overlay).prop('checked', false);
$('input.function-' + overlay).change(); $('input.function-' + overlay).change();
$('.ui-selected').each(function() { $('.ui-selected').each(function() {
if (func == '' || $(this).is('.function-' + func)) { if (func === '' || $(this).is(functionTag + func)) {
$(this).removeClass('function-' + overlay); $(this).removeClass('function-' + overlay);
} }
}); });
} }
function updateColors(value, hsvIndex) { function updateColors(value, hsvIndex) {
var change = false; let change = false;
value = Number(value); value = Number(value);
var className = '.color-' + selectedColorIndex; const className = '.color-' + selectedColorIndex;
if ($(className).hasClass('btnOn')) { if ($(className).hasClass('btnOn')) {
switch (hsvIndex) { switch (hsvIndex) {
case 0: case 0:
@ -1037,8 +1048,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
if ($(this).is('.function-c') || $(this).is('.function-r') || $(this).is('.function-b')) { if ($(this).is('.function-c') || $(this).is('.function-r') || $(this).is('.function-b')) {
$(this).find('.overlay-color').show(); $(this).find('.overlay-color').show();
for (var colorIndex = 0; colorIndex < 16; colorIndex++) { for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
var className = 'color-' + colorIndex; const className = 'color-' + colorIndex;
if ($(this).is('.' + className)) { if ($(this).is('.' + className)) {
$(this).find('.overlay-color').addClass(className); $(this).find('.overlay-color').addClass(className);
$(this).find('.overlay-color').css('background-color', HsvToColor(FC.LED_COLORS[colorIndex])) $(this).find('.overlay-color').css('background-color', HsvToColor(FC.LED_COLORS[colorIndex]))
@ -1055,8 +1066,8 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
function setColorSliders(colorIndex) { function setColorSliders(colorIndex) {
var sliders = $('div.colorDefineSliders input'); const sliders = $('div.colorDefineSliders input');
var change = false; let change = false;
if (!FC.LED_COLORS[colorIndex]) if (!FC.LED_COLORS[colorIndex])
return; return;
@ -1089,35 +1100,33 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
if (input == undefined) if (input == undefined)
return ""; return "";
var HSV = { h:Number(input.h), s:Number(input.s), v:Number(input.v) }; let HSV = { h:Number(input.h), s:Number(input.s), v:Number(input.v) };
if (HSV.s == 0 && HSV.v == 0) if (HSV.s == 0 && HSV.v == 0)
return ""; return "";
HSV = { h:HSV.h, s:1 - HSV.s / 255, v:HSV.v / 255 }; HSV = { h:HSV.h, s:1 - HSV.s / 255, v:HSV.v / 255 };
var HSL = { h:0, s:0, v:0}; const HSL = { h:0, s:0, v:0};
HSL.h = HSV.h; HSL.h = HSV.h;
HSL.l = (2 - HSV.s) * HSV.v / 2; HSL.l = (2 - HSV.s) * HSV.v / 2;
HSL.s = HSL.l && HSL.l < 1 ? HSV.s * HSV.v / (HSL.l < 0.5 ? HSL.l * 2 : 2 - HSL.l * 2) : HSL.s; HSL.s = HSL.l && HSL.l < 1 ? HSV.s * HSV.v / (HSL.l < 0.5 ? HSL.l * 2 : 2 - HSL.l * 2) : HSL.s;
var ret = 'hsl(' + HSL.h + ', ' + HSL.s * 100 + '%, ' + HSL.l * 100 + '%)'; return `hsl(${HSL.h},${HSL.s * 100}%,${HSL.l * 100}%)`;
return ret;
} }
function getModeColor(mode, dir) { function getModeColor(mode, dir) {
for (var i = 0; i < FC.LED_MODE_COLORS.length; i++) { for (const mc of FC.LED_MODE_COLORS) {
var mc = FC.LED_MODE_COLORS[i]; if (mc.mode === mode && mc.direction === dir) {
if (mc.mode == mode && mc.direction == dir)
return mc.color; return mc.color;
}
} }
return ""; return "";
} }
function setModeColor(mode, dir, color) { function setModeColor(mode, dir, color) {
for (var i = 0; i < FC.LED_MODE_COLORS.length; i++) { for (const mc of FC.LED_MODE_COLORS) {
var mc = FC.LED_MODE_COLORS[i]; if (mc.mode === mode && mc.direction === dir) {
if (mc.mode == mode && mc.direction == dir) {
mc.color = color; mc.color = color;
return 1; return 1;
} }