diff --git a/conf/modules/bat_checker.xml b/conf/modules/bat_checker.xml index ff8e279f8d..b4daef7206 100644 --- a/conf/modules/bat_checker.xml +++ b/conf/modules/bat_checker.xml @@ -2,9 +2,22 @@ - Battery checker module + + Battery checker module + + When the battery voltage goes below the BAT_LOW level, this will toggle a GPIO/LED. + If the battery voltage is lower than BAT_CRITICAL level, the LED/GPIO stays ON. + The output signal can be connected to an actaul LED or a buzzer to indicated the end of battery to the user. + + When a LED is used, define the LED number in your airframe with BAT_CHECKER_LED. + When a GPIO is used, define the GPIO port and pin in your airframe with BAT_CHECKER_GPIO. + You should at least use one of these two options. + + + +
diff --git a/sw/airborne/modules/energy/bat_checker.c b/sw/airborne/modules/energy/bat_checker.c index 64306bbac4..0a89581c3e 100644 --- a/sw/airborne/modules/energy/bat_checker.c +++ b/sw/airborne/modules/energy/bat_checker.c @@ -31,28 +31,56 @@ #include "generated/airframe.h" #include "generated/modules.h" #include "subsystems/electrical.h" +#include "mcu_periph/gpio.h" #include "led.h" -#ifndef BAT_CHECKER_LED -#error You must define BAT_CHECKER_LED in your airframe file. +#if (!defined BAT_CHECKER_GPIO && !defined BAT_CHECKER_LED) +#error You must define BAT_CHECKER_GPIO or BAT_CHECKER_LED in your airframe file. #endif +// in case GPIO logic is inverted +#ifndef BAT_CHECKER_GPIO_ON +#define BAT_CHECKER_GPIO_ON gpio_set +#endif +#ifndef BAT_CHECKER_GPIO_OFF +#define BAT_CHECKER_GPIO_OFF gpio_clear +#endif void init_bat_checker(void) { +#ifdef BAT_CHECKER_LED LED_INIT(BAT_CHECKER_LED); LED_OFF(BAT_CHECKER_LED); +#endif +#ifdef BAT_CHECKER_GPIO + gpio_setup_output(BAT_CHECKER_GPIO); +#endif } void bat_checker_periodic(void) { if (electrical.bat_critical) { +#ifdef BAT_CHECKER_LED LED_ON(BAT_CHECKER_LED); +#endif +#ifdef BAT_CHECKER_GPIO + BAT_CHECKER_GPIO_ON(BAT_CHECKER_GPIO); +#endif } else if (electrical.bat_low) { +#ifdef BAT_CHECKER_LED LED_TOGGLE(BAT_CHECKER_LED); +#endif +#ifdef BAT_CHECKER_GPIO + gpio_toggle(BAT_CHECKER_GPIO); +#endif } else { +#ifdef BAT_CHECKER_LED LED_OFF(BAT_CHECKER_LED); +#endif +#ifdef BAT_CHECKER_GPIO + BAT_CHECKER_GPIO_OFF(BAT_CHECKER_GPIO); +#endif } }