1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Fix LED_STRIP feature // Add DMA drivers // UART fixes

This commit is contained in:
borisbstyle 2016-02-10 22:36:05 +01:00
parent 2af929797d
commit 3a156f98ab
17 changed files with 309 additions and 196 deletions

View file

@ -37,13 +37,12 @@
#include <common/printf.h>
#include "io/rc_controls.h"
#include "sensors/battery.h"
#include "io/rc_controls.h"
#include "io/ledstrip.h"
#include "rx/rx.h"
#include "flight/failsafe.h"
#include "config/runtime_config.h"
@ -382,6 +381,10 @@ void updateLedCount(void)
ledCount = 0;
ledsInRingCount = 0;
if( ledConfigs == 0 ){
return;
}
for (ledIndex = 0; ledIndex < MAX_LED_STRIP_LENGTH; ledIndex++) {
ledConfig = &ledConfigs[ledIndex];
@ -778,13 +781,18 @@ void applyLedThrottleLayer()
#define ROTATION_SEQUENCE_LED_COUNT 6 // 2 on, 4 off
#define ROTATION_SEQUENCE_LED_WIDTH 2
#define RING_PATTERN_NOT_CALCULATED 255
void applyLedThrustRingLayer(void)
{
const ledConfig_t *ledConfig;
hsvColor_t ringColor;
uint8_t ledIndex;
// initialised to special value instead of using more memory for a flag.
static uint8_t rotationSeqLedCount = RING_PATTERN_NOT_CALCULATED;
static uint8_t rotationPhase = ROTATION_SEQUENCE_LED_COUNT;
bool nextLedOn = false;
hsvColor_t ringColor;
const ledConfig_t *ledConfig;
uint8_t ledRingIndex = 0;
for (ledIndex = 0; ledIndex < ledCount; ledIndex++) {
@ -797,7 +805,7 @@ void applyLedThrustRingLayer(void)
bool applyColor = false;
if (ARMING_FLAG(ARMED)) {
if ((ledRingIndex + rotationPhase) % ROTATION_SEQUENCE_LED_COUNT < ROTATION_SEQUENCE_LED_WIDTH) {
if ((ledRingIndex + rotationPhase) % rotationSeqLedCount < ROTATION_SEQUENCE_LED_WIDTH) {
applyColor = true;
}
} else {
@ -818,9 +826,29 @@ void applyLedThrustRingLayer(void)
ledRingIndex++;
}
uint8_t ledRingLedCount = ledRingIndex;
if (rotationSeqLedCount == RING_PATTERN_NOT_CALCULATED) {
// update ring pattern according to total number of ring leds found
rotationSeqLedCount = ledRingLedCount;
// try to split in segments/rings of exactly ROTATION_SEQUENCE_LED_COUNT leds
if ((ledRingLedCount % ROTATION_SEQUENCE_LED_COUNT) == 0) {
rotationSeqLedCount = ROTATION_SEQUENCE_LED_COUNT;
} else {
// else split up in equal segments/rings of at most ROTATION_SEQUENCE_LED_COUNT leds
while ((rotationSeqLedCount > ROTATION_SEQUENCE_LED_COUNT) && ((rotationSeqLedCount % 2) == 0)) {
rotationSeqLedCount >>= 1;
}
}
// trigger start over
rotationPhase = 1;
}
rotationPhase--;
if (rotationPhase == 0) {
rotationPhase = ROTATION_SEQUENCE_LED_COUNT;
rotationPhase = rotationSeqLedCount;
}
}
@ -1017,7 +1045,7 @@ bool parseColor(uint8_t index, const char *colorConfig)
void applyDefaultColors(hsvColor_t *colors, uint8_t colorCount)
{
memset(colors, 0, colorCount * sizeof(colors));
memset(colors, 0, colorCount * sizeof(hsvColor_t));
for (uint8_t colorIndex = 0; colorIndex < colorCount && colorIndex < (sizeof(defaultColors) / sizeof(defaultColors[0])); colorIndex++) {
*colors++ = *defaultColors[colorIndex];
}