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.
Example for airframe file
Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!
<module name="bat_checker">
b'<define name="BAT_CHECKER_DELAY" value="delay" />\n '
b'<define name="BAT_CHECKER_LED" value="X" />\n '
b'<define name="BAT_CHECKER_GPIO" value="GPIOX,GPIOY" />\n '
b'<define name="BAT_CHECKER_GPIO_ON" value="gpio_set" />\n '
b'<define name="BAT_CHECKER_GPIO_OFF" value="gpio_clear" />\n '
</module>
Module configuration options
Define Options
- name:
BAT_CHECKER_DELAY
value: delay
Description: number of seconds the battery voltage has to below LOW_BAT_LEVEL before warning signal is activated
- name:
BAT_CHECKER_LED
value: X
Description: led number to use for the warning signal
- name:
BAT_CHECKER_GPIO
value: GPIOX,GPIOY
Description: alternatively, a GPIO can be set instead of a LED (ex: GPIOA,GPIO5)
- name:
BAT_CHECKER_GPIO_ON
value: gpio_set
Description: tells if output signal is ON when GPIO is high or low
- name:
BAT_CHECKER_GPIO_OFF
value: gpio_clear
Description: tells if output signal is OFF when GPIO is high or low
Module functions
Init Functions
These initialization functions are called once on startup.
Periodic Functions
These functions are called periodically at the specified frequency from the module periodic loop.
Files
Header Files
The following headers are automatically included in modules.h
Source Files
Raw bat_checker.xml file:
<!DOCTYPE module SYSTEM "module.dtd">
<module name="bat_checker" dir="energy">
<doc>
<description>
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.
</description>
<define name="BAT_CHECKER_DELAY" value="delay" description="number of seconds the battery voltage has to below LOW_BAT_LEVEL before warning signal is activated"/>
<define name="BAT_CHECKER_LED" value="X" description="led number to use for the warning signal"/>
<define name="BAT_CHECKER_GPIO" value="GPIOX,GPIOY" description="alternatively, a GPIO can be set instead of a LED (ex: GPIOA,GPIO5)"/>
<define name="BAT_CHECKER_GPIO_ON" value="gpio_set" description="tells if output signal is ON when GPIO is high or low"/>
<define name="BAT_CHECKER_GPIO_OFF" value="gpio_clear" description="tells if output signal is OFF when GPIO is high or low"/>
</doc>
<header>
<file name="bat_checker.h"/>
</header>
<init fun="init_bat_checker()"/>
<periodic fun="bat_checker_periodic()" freq="2" autorun="TRUE"/>
<makefile target="ap">
<file name="bat_checker.c"/>
</makefile>
</module>