From 8e8a15cb5c506fdf518183db551f38d3a6be0b37 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 29 Dec 2020 19:28:49 +0100 Subject: [PATCH] Fix led_strip --- src/js/msp/MSPHelper.js | 24 +++++++++++++----------- src/js/tabs/led_strip.js | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 5095fc57..ab2935c8 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -5,12 +5,7 @@ const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order const ledFunctionLetters = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l']; // in LSB bit order const ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r']; // in LSB bit -let ledOverlayLetters; -if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit -} else { - ledOverlayLetters = ['t', 'o', 'b', 'v', 'i', 'w']; // in LSB bit -} +let ledOverlayLetters = ['t', 'o', 'b', 'v', 'i', 'w']; // in LSB bit function MspHelper() { const self = this; @@ -1211,6 +1206,9 @@ MspHelper.prototype.process_data = function(dataHandler) { if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { ledCount = data.byteLength / 4; } + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { + ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { // According to betaflight/src/main/msp/msp.c // API 1.41 - add indicator for advanced profile support and the current profile selection @@ -2587,9 +2585,13 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { buffer.push(ledIndex); + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { + ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + } + if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { let directionMask = 0; - for (const directionLetterIndex of led.directions) { + for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); if (bitIndex >= 0) { directionMask = bit_set(directionMask, bitIndex); @@ -2598,7 +2600,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { buffer.push16(directionMask); let functionMask = 0; - for (const functionLetterIndex of led.functions) { + for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { const bitIndex = ledFunctionLetters.indexOf(led.functions[functionLetterIndex]); if (bitIndex >= 0) { functionMask = bit_set(functionMask, bitIndex); @@ -2615,7 +2617,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { mask |= (led.y << 0); mask |= (led.x << 4); - for (const functionLetterIndex of led.functions) { + for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]); if (fnIndex >= 0) { mask |= (fnIndex << 8); @@ -2623,7 +2625,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { } } - for (const overlayLetterIndex of led.functions) { + 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); @@ -2632,7 +2634,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { mask |= (led.color << 18); - for (const directionLetterIndex of led.directions) { + for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); if (bitIndex >= 0) { mask |= bit_set(mask, bitIndex + 22); diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index 6d47a993..3d7704e5 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -9,6 +9,7 @@ TABS.led_strip = { TABS.led_strip.initialize = function (callback, scrollPosition) { let selectedColorIndex = null; let selectedModeColor = null; + const functionTag = '.function-'; if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b']; @@ -68,8 +69,6 @@ TABS.led_strip.initialize = function (callback, scrollPosition) { i18n.localizePage(); - const functionTag = '.function-'; - // Build Grid const theHTML = []; let theHTMLlength = 0; @@ -316,6 +315,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) { $('.mainGrid').selectable({ filter: ' > div', stop: function() { + const functionsInSelection = []; const directionsInSelection = []; clearModeColorSelection(); @@ -566,7 +566,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) { $(this).find('.wire').html(ledIndex); for (let modeIndex = 0; modeIndex < led.functions.length; modeIndex++) { - $(this).addClass(`function-'${led.functions[modeIndex]}`); + $(this).addClass(`function-${led.functions[modeIndex]}`); } for (let directionIndex = 0; directionIndex < led.directions.length; directionIndex++) { @@ -1052,7 +1052,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) { const className = 'color-' + colorIndex; if ($(this).is('.' + 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])); } else { if ($(this).find('.overlay-color').is('.' + className)) $(this).find('.overlay-color').removeClass(className);