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

Merge pull request #2362 from haslinghuis/fix-ledstrip

This commit is contained in:
Michael Keller 2021-01-06 03:34:59 +08:00 committed by GitHub
commit f42cefc8f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 15 deletions

View file

@ -5,12 +5,7 @@
const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order 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 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 const ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r']; // in LSB bit
let ledOverlayLetters; let ledOverlayLetters = ['t', 'o', 'b', 'v', 'i', 'w']; // in LSB bit
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
}
function MspHelper() { function MspHelper() {
const self = this; const self = this;
@ -1191,6 +1186,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
ledCount = data.byteLength / 4; 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)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) {
// According to betaflight/src/main/msp/msp.c // According to betaflight/src/main/msp/msp.c
// API 1.41 - add indicator for advanced profile support and the current profile selection // API 1.41 - add indicator for advanced profile support and the current profile selection
@ -2574,9 +2572,13 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) {
buffer.push(ledIndex); 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")) { if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) {
let directionMask = 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]); const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]);
if (bitIndex >= 0) { if (bitIndex >= 0) {
directionMask = bit_set(directionMask, bitIndex); directionMask = bit_set(directionMask, bitIndex);
@ -2585,7 +2587,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) {
buffer.push16(directionMask); buffer.push16(directionMask);
let functionMask = 0; 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]); const bitIndex = ledFunctionLetters.indexOf(led.functions[functionLetterIndex]);
if (bitIndex >= 0) { if (bitIndex >= 0) {
functionMask = bit_set(functionMask, bitIndex); functionMask = bit_set(functionMask, bitIndex);
@ -2602,7 +2604,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) {
mask |= (led.y << 0); mask |= (led.y << 0);
mask |= (led.x << 4); 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]); const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]);
if (fnIndex >= 0) { if (fnIndex >= 0) {
mask |= (fnIndex << 8); mask |= (fnIndex << 8);
@ -2610,7 +2612,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]); const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]);
if (bitIndex >= 0) { if (bitIndex >= 0) {
mask |= bit_set(mask, bitIndex + 12); mask |= bit_set(mask, bitIndex + 12);
@ -2619,7 +2621,7 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) {
mask |= (led.color << 18); 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]); const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]);
if (bitIndex >= 0) { if (bitIndex >= 0) {
mask |= bit_set(mask, bitIndex + 22); mask |= bit_set(mask, bitIndex + 22);

View file

@ -9,6 +9,7 @@ TABS.led_strip = {
TABS.led_strip.initialize = function (callback, scrollPosition) { TABS.led_strip.initialize = function (callback, scrollPosition) {
let selectedColorIndex = null; let selectedColorIndex = null;
let selectedModeColor = null; let selectedModeColor = null;
const functionTag = '.function-';
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'];
@ -68,8 +69,6 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
i18n.localizePage(); i18n.localizePage();
const functionTag = '.function-';
// Build Grid // Build Grid
const theHTML = []; const theHTML = [];
let theHTMLlength = 0; let theHTMLlength = 0;
@ -316,6 +315,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$('.mainGrid').selectable({ $('.mainGrid').selectable({
filter: ' > div', filter: ' > div',
stop: function() { stop: function() {
const functionsInSelection = [];
const directionsInSelection = []; const directionsInSelection = [];
clearModeColorSelection(); clearModeColorSelection();
@ -566,7 +566,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
$(this).find('.wire').html(ledIndex); $(this).find('.wire').html(ledIndex);
for (let 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 (let directionIndex = 0; directionIndex < led.directions.length; directionIndex++) { for (let directionIndex = 0; directionIndex < led.directions.length; directionIndex++) {
@ -1052,7 +1052,7 @@ TABS.led_strip.initialize = function (callback, scrollPosition) {
const 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]));
} else { } else {
if ($(this).find('.overlay-color').is('.' + className)) if ($(this).find('.overlay-color').is('.' + className))
$(this).find('.overlay-color').removeClass(className); $(this).find('.overlay-color').removeClass(className);