Merge remote-tracking branch 'betaflight/master' into bfdev-smartaudio

This commit is contained in:
jflyper 2016-11-23 03:27:37 +09:00
commit 45dd480dfa
2 changed files with 68 additions and 45 deletions

View File

@ -92,7 +92,9 @@ static void ledStripDisable(void);
//#define USE_LED_ANIMATION
#define HZ_TO_MICROS(hz) ((int32_t)((1000 * 1000) / (hz)))
#define HZ_TO_US(hz) ((int32_t)((1000 * 1000) / (hz)))
#define MAX_TIMER_DELAY (5 * 1000 * 1000)
#if LED_MAX_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH
# error "Led strip length must match driver"
@ -535,7 +537,7 @@ static void applyLedWarningLayer(bool updateNow, uint32_t *timer)
if (!ARMING_FLAG(ARMED) && !ARMING_FLAG(OK_TO_ARM))
warningFlags |= 1 << WARNING_ARMING_DISABLED;
}
*timer += HZ_TO_MICROS(10);
*timer += HZ_TO_US(10);
}
if (warningFlags) {
@ -567,27 +569,31 @@ static void applyLedBatteryLayer(bool updateNow, uint32_t *timer)
static bool flash = false;
int state;
int frequency = 1;
int timerDelayUs = HZ_TO_US(1);
if (updateNow) {
state = getBatteryState();
switch (state) {
case BATTERY_OK:
flash = false;
frequency = 1;
break;
case BATTERY_WARNING:
frequency = 2;
break;
default:
frequency = 8;
break;
}
flash = !flash;
switch (state) {
case BATTERY_OK:
flash = true;
timerDelayUs = HZ_TO_US(1);
break;
case BATTERY_WARNING:
flash = !flash;
timerDelayUs = HZ_TO_US(2);
break;
default:
flash = !flash;
timerDelayUs = HZ_TO_US(8);
break;
}
}
*timer += HZ_TO_MICROS(frequency);
*timer += timerDelayUs;
if (!flash) {
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
@ -600,24 +606,24 @@ static void applyLedRssiLayer(bool updateNow, uint32_t *timer)
static bool flash = false;
int state;
int frequency = 1;
int timerDelay = HZ_TO_US(1);
if (updateNow) {
state = (rssi * 100) / 1023;
if (state > 50) {
flash = false;
frequency = 1;
flash = true;
timerDelay = HZ_TO_US(1);
} else if (state > 20) {
frequency = 2;
flash = !flash;
timerDelay = HZ_TO_US(2);
} else {
frequency = 8;
flash = !flash;
timerDelay = HZ_TO_US(8);
}
flash = !flash;
}
*timer += HZ_TO_MICROS(frequency);
*timer += timerDelay;
if (!flash) {
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
@ -642,7 +648,7 @@ static void applyLedGpsLayer(bool updateNow, uint32_t *timer)
gpsFlashCounter++;
gpsPauseCounter = 1;
}
*timer += HZ_TO_MICROS(2.5f);
*timer += HZ_TO_US(2.5f);
}
const hsvColor_t *gpsColor;
@ -674,11 +680,11 @@ static void applyLedIndicatorLayer(bool updateNow, uint32_t *timer)
// calculate update frequency
int scale = MAX(ABS(rcCommand[ROLL]), ABS(rcCommand[PITCH])); // 0 - 500
scale = scale - INDICATOR_DEADBAND; // start increasing frequency right after deadband
*timer += HZ_TO_MICROS(5 + (45 * scale) / (500 - INDICATOR_DEADBAND)); // 5 - 50Hz update, 2.5 - 25Hz blink
*timer += HZ_TO_US(5 + (45 * scale) / (500 - INDICATOR_DEADBAND)); // 5 - 50Hz update, 2.5 - 25Hz blink
flash = !flash;
} else {
*timer += HZ_TO_MICROS(5); // try again soon
*timer += HZ_TO_US(5);
}
}
@ -736,7 +742,7 @@ static void applyLedThrustRingLayer(bool updateNow, uint32_t *timer)
if (updateNow) {
rotationPhase = rotationPhase > 0 ? rotationPhase - 1 : ledCounts.ringSeqLen - 1;
*timer += HZ_TO_MICROS(5 + (45 * scaledThrottle) / 100); // 5 - 50Hz update rate
*timer += HZ_TO_US(5 + (45 * scaledThrottle) / 100); // 5 - 50Hz update rate
}
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
@ -804,7 +810,7 @@ static void applyLarsonScannerLayer(bool updateNow, uint32_t *timer)
if (updateNow) {
larsonScannerNextStep(&larsonParameters, 15);
*timer += HZ_TO_MICROS(60);
*timer += HZ_TO_US(60);
}
int scannerLedIndex = 0;
@ -833,7 +839,7 @@ static void applyLedBlinkLayer(bool updateNow, uint32_t *timer)
if (blinkMask <= 1)
blinkMask = blinkPattern;
*timer += HZ_TO_MICROS(10);
*timer += HZ_TO_US(10);
}
bool ledOn = (blinkMask & 1); // b_b_____...
@ -856,7 +862,7 @@ static void applyLedAnimationLayer(bool updateNow, uint32_t *timer)
const int animationFrames = ledGridHeight;
if(updateNow) {
frameCounter = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
*timer += HZ_TO_MICROS(20);
*timer += HZ_TO_US(20);
}
if (ARMING_FLAG(ARMED))
@ -944,12 +950,12 @@ void ledStripUpdate(uint32_t currentTime)
uint32_t timActive = 0;
for (timId_e timId = 0; timId < timTimerCount; timId++) {
// sanitize timer value, so that it can be safely incremented. Handles inital timerVal value.
// max delay is limited to 5s
int32_t delta = cmp32(now, timerVal[timId]);
if (delta < 0 && delta > -HZ_TO_MICROS(0.2f))
// max delay is limited to 5s
if (delta < 0 && delta > -MAX_TIMER_DELAY)
continue; // not ready yet
timActive |= 1 << timId;
if (delta >= HZ_TO_MICROS(10) || delta < 0) {
if (delta >= 100 * 1000 || delta < 0) {
timerVal[timId] = now;
}
}

View File

@ -999,13 +999,15 @@ static void cliWrite(uint8_t ch);
static bool cliDumpPrintf(uint8_t dumpMask, bool equalsDefault, const char *format, ...);
static bool cliDefaultPrintf(uint8_t dumpMask, bool equalsDefault, const char *format, ...);
static void cliBreak(const char *str, uint8_t len)
#ifndef CLI_MINIMAL_VERBOSITY
static void cliRepeat(const char *str, uint8_t len)
{
for (int i = 0; i < len; i++) {
cliPrint(str);
}
cliPrint("\r\n");
}
#endif
static void cliPrompt(void)
{
@ -3845,21 +3847,31 @@ static void printResource(uint8_t dumpMask, master_t *defaultConfig)
}
#ifndef CLI_MINIMAL_VERBOSITY
static void resourceCheck(uint8_t resourceIndex, uint8_t index, ioTag_t tag)
static bool resourceCheck(uint8_t resourceIndex, uint8_t index, ioTag_t tag)
{
const char * format = "\r\n* %s * %c%d also used by %s";
for (int r = 0; r < (int)ARRAYLEN(resourceTable); r++) {
for (int i = 0; i < (resourceTable[r].maxIndex == 0 ? 1 : resourceTable[r].maxIndex); i++) {
if (*(resourceTable[r].ptr + i) == tag) {
if (r == resourceIndex && i == index) {
continue;
bool error = false;
if (r == resourceIndex) {
if (i == index) {
continue;
}
error = true;
}
cliPrintf("\r\n* WARNING * %c%d also used by %s", DEFIO_TAG_GPIOID(tag) + 'A', DEFIO_TAG_PIN(tag), ownerNames[resourceTable[r].owner]);
cliPrintf(format, error ? "ERROR" : "WARNING", DEFIO_TAG_GPIOID(tag) + 'A', DEFIO_TAG_PIN(tag), ownerNames[resourceTable[r].owner]);
if (resourceTable[r].maxIndex > 0) {
cliPrintf(" %d", RESOURCE_INDEX(i));
}
if (error) {
return false;
}
}
}
}
return true;
}
#endif
@ -3874,7 +3886,7 @@ static void cliResource(char *cmdline)
} else if (strncasecmp(cmdline, "list", len) == 0) {
#ifndef CLI_MINIMAL_VERBOSITY
cliPrintf("Currently active IO resource assignments:\r\n(reboot to update)\r\n");
cliBreak("-", 20);
cliRepeat("-", 20);
#endif
for (int i = 0; i < DEFIO_IO_USED_COUNT; i++) {
const char* owner;
@ -3888,7 +3900,9 @@ static void cliResource(char *cmdline)
}
cliPrintf("\r\n\r\nCurrently active DMA:\r\n");
cliBreak("-", 20);
#ifndef CLI_MINIMAL_VERBOSITY
cliRepeat("-", 20);
#endif
for (int i = 0; i < DMA_MAX_DESCRIPTORS; i++) {
const char* owner;
owner = ownerNames[dmaGetOwner(i)];
@ -3934,10 +3948,11 @@ static void cliResource(char *cmdline)
cliShowArgumentRangeError("index", 1, resourceTable[resourceIndex].maxIndex);
return;
}
index -= 1;
}
pch = strtok_r(NULL, " ", &saveptr);
ioTag_t *tag = (ioTag_t*)(resourceTable[resourceIndex].ptr + (index == 0 ? 0 : index - 1));
ioTag_t *tag = (ioTag_t*)(resourceTable[resourceIndex].ptr + index);
uint8_t pin = 0;
if (strlen(pch) > 0) {
@ -3957,13 +3972,15 @@ static void cliResource(char *cmdline)
if (pin < 16) {
ioRec_t *rec = IO_Rec(IOGetByTag(DEFIO_TAG_MAKE(port, pin)));
if (rec) {
*tag = DEFIO_TAG_MAKE(port, pin);
#ifndef CLI_MINIMAL_VERBOSITY
if (!resourceCheck(resourceIndex, index, DEFIO_TAG_MAKE(port, pin))) {
return;
}
cliPrintf("Resource is set to %c%02d!\r\n", port + 'A', pin);
resourceCheck(resourceIndex, index, DEFIO_TAG_MAKE(port, pin));
#else
cliPrintf("Set to %c%02d!", port + 'A', pin);
#endif
*tag = DEFIO_TAG_MAKE(port, pin);
} else {
cliPrintf("Resource is invalid!\r\n");
}