Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / io / statusindicator.c
blobaa0afda2301e11b40cd319efc3ce37fa452e62b0
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #include "drivers/light_led.h"
27 #include "drivers/time.h"
29 #include "statusindicator.h"
31 static uint32_t warningLedTimer = 0;
33 typedef enum {
34 WARNING_LED_OFF = 0,
35 WARNING_LED_ON,
36 WARNING_LED_FLASH
37 } warningLedState_e;
39 static warningLedState_e warningLedState = WARNING_LED_OFF;
41 void warningLedResetTimer(void) {
42 uint32_t now = millis();
43 warningLedTimer = now + 500000;
46 void warningLedEnable(void)
48 warningLedState = WARNING_LED_ON;
51 void warningLedDisable(void)
53 warningLedState = WARNING_LED_OFF;
56 void warningLedFlash(void)
58 warningLedState = WARNING_LED_FLASH;
61 void warningLedRefresh(void)
63 switch (warningLedState) {
64 case WARNING_LED_OFF:
65 LED0_OFF;
66 break;
67 case WARNING_LED_ON:
68 LED0_ON;
69 break;
70 case WARNING_LED_FLASH:
71 LED0_TOGGLE;
72 break;
75 uint32_t now = micros();
76 warningLedTimer = now + 500000;
79 void warningLedUpdate(void)
81 uint32_t now = micros();
83 if ((int32_t)(now - warningLedTimer) < 0) {
84 return;
87 warningLedRefresh();