1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 01:35:35 +03:00

Cleanup status indicator code.

This primarily is to avaoid stalling the main loop when beeping and
flashing.

This is needed because oneshot ESCs do not receive updates when the main
loop is stalled.

Additionally the beeper code for sticks held in disarm position is
changed since it also clashed with profile selection.  Now profile
selections can be seen and heard clearly.

Other subsections of the system that changed the LED0 state while the
main loop is running have been updated to use the status indicator API
instead of blindly hitting the hardware which previously caused lots of
odd LED flashing behaviour - now it is consistent.
This commit is contained in:
Dominic Clifton 2015-05-29 23:37:33 +01:00
parent 22a98af25a
commit e6733b4dfc
8 changed files with 114 additions and 73 deletions

View file

@ -27,44 +27,63 @@
#include "statusindicator.h"
void blinkLedAndSoundBeeper(uint8_t num, uint8_t wait, uint8_t repeat)
{
uint8_t i, r;
for (r = 0; r < repeat; r++) {
for (i = 0; i < num; i++) {
LED0_TOGGLE; // switch LEDPIN state
BEEP_ON;
delay(wait);
BEEP_OFF;
}
delay(60);
}
}
static uint32_t warningLedTimer = 0;
void enableWarningLed(uint32_t currentTime)
typedef enum {
WARNING_LED_OFF = 0,
WARNING_LED_ON,
WARNING_LED_FLASH
} warningLedState_e;
static warningLedState_e warningLedState = WARNING_LED_OFF;
void warningLedResetTimer(void) {
uint32_t now = millis();
warningLedTimer = now + 500000;
}
void warningLedEnable(void)
{
if (warningLedTimer != 0) {
return; // already enabled
warningLedState = WARNING_LED_ON;
}
void warningLedDisable(void)
{
warningLedState = WARNING_LED_OFF;
}
void warningLedFlash(void)
{
warningLedState = WARNING_LED_FLASH;
}
void warningLedRefresh(void)
{
switch (warningLedState) {
case WARNING_LED_OFF:
LED0_OFF;
break;
case WARNING_LED_ON:
LED0_ON;
break;
case WARNING_LED_FLASH:
LED0_TOGGLE;
break;
}
warningLedTimer = currentTime + 500000;
LED0_ON;
uint32_t now = micros();
warningLedTimer = now + 500000;
}
void disableWarningLed(void)
void warningLedUpdate(void)
{
warningLedTimer = 0;
LED0_OFF;
}
uint32_t now = micros();
void updateWarningLed(uint32_t currentTime)
{
if (warningLedTimer && (int32_t)(currentTime - warningLedTimer) >= 0) {
LED0_TOGGLE;
warningLedTimer = warningLedTimer + 500000;
if ((int32_t)(now - warningLedTimer) < 0) {
return;
}
warningLedRefresh();
}