1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Allow saving of LED Strip configuratiion via MSP. Requires firmware

with new MSP_SET_LED_STRIP_CONFIG.

Remove some .toUpperCase() duplication since it was only needed for the
CLI commands panel.
Minor CSS cleanups.
Some variable and class renaming to align with firmware code.
This commit is contained in:
Dominic Clifton 2015-01-16 00:15:41 +00:00
parent db68d567d3
commit 519de30f6e
9 changed files with 192 additions and 93 deletions

View file

@ -93,6 +93,9 @@ var MSP = {
callbacks: [],
packet_error: 0,
ledDirectionLetters: ['n', 'e', 's', 'w', 'u', 'd'], // in LSB bit order
ledFunctionLetters: ['i', 'w', 'f', 'a', 't'], // in LSB bit order
read: function (readInfo) {
var data = new Uint8Array(readInfo.data);
@ -626,10 +629,9 @@ var MSP = {
offset += 2;
var directions = [];
var directionLetters = ['n', 'e', 's', 'w', 'u', 'd'];
for (var directionLetterIndex = 0; directionLetterIndex < directionLetters.length; directionLetterIndex++) {
for (var directionLetterIndex = 0; directionLetterIndex < MSP.ledDirectionLetters.length; directionLetterIndex++) {
if (bit_check(directionMask, directionLetterIndex)) {
directions.push(directionLetters[directionLetterIndex]);
directions.push(MSP.ledDirectionLetters[directionLetterIndex]);
}
}
@ -637,10 +639,9 @@ var MSP = {
offset += 2;
var functions = [];
var functionLetters = ['i', 'w', 'f', 'a', 't'];
for (var functionLetterIndex = 0; functionLetterIndex < functionLetters.length; functionLetterIndex++) {
for (var functionLetterIndex = 0; functionLetterIndex < MSP.ledFunctionLetters.length; functionLetterIndex++) {
if (bit_check(functionMask, functionLetterIndex)) {
functions.push(functionLetters[functionLetterIndex]);
functions.push(MSP.ledFunctionLetters[functionLetterIndex]);
}
}
@ -655,6 +656,10 @@ var MSP = {
}
break;
case MSP_codes.MSP_SET_LED_STRIP_CONFIG:
console.log('Led strip config saved');
break;
case MSP_codes.MSP_SET_MODE_RANGE:
console.log('Mode range saved');
@ -920,7 +925,7 @@ MSP.crunch = function (code) {
buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 2));
buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 3));
break;
default:
return false;
}
@ -989,3 +994,53 @@ MSP.sendAdjustmentRanges = function(onCompleteCallback) {
}
};
MSP.sendLedStripConfig = function(onCompleteCallback) {
var nextFunction = send_next_led_strip_config;
var ledIndex = 0;
send_next_led_strip_config();
function send_next_led_strip_config() {
var led = LED_STRIP[ledIndex];
var buffer = [];
buffer.push(ledIndex);
var directionMask = 0;
for (var directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) {
var bitIndex = MSP.ledDirectionLetters.indexOf(led.directions[directionLetterIndex]);
if (bitIndex >= 0) {
directionMask = bit_set(directionMask, bitIndex);
}
}
buffer.push(specificByte(directionMask, 0));
buffer.push(specificByte(directionMask, 1));
var functionMask = 0;
for (var functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) {
var bitIndex = MSP.ledFunctionLetters.indexOf(led.functions[functionLetterIndex]);
if (bitIndex >= 0) {
functionMask = bit_set(functionMask, bitIndex);
}
}
buffer.push(specificByte(functionMask, 0));
buffer.push(specificByte(functionMask, 1));
buffer.push(led.x);
buffer.push(led.y);
// prepare for next iteration
ledIndex++;
if (ledIndex == LED_STRIP.length) {
nextFunction = onCompleteCallback;
}
MSP.send_message(MSP_codes.MSP_SET_LED_STRIP_CONFIG, buffer, false, nextFunction);
}
}