diff --git a/openrtx/include/battery.h b/openrtx/include/battery.h index 61d51191..aed28038 100644 --- a/openrtx/include/battery.h +++ b/openrtx/include/battery.h @@ -20,10 +20,11 @@ #ifndef BATTERY_H #define BATTERY_H -/* This function uses battery charge tables to convert a battery voltage into a +/** + * This function uses battery charge tables to convert a battery voltage into a * charge percentage. - * @param vbat: the voltage read from the battery in volt - * @return the charge percentage + * @param vbat: the voltage read from the battery in volt. + * @return the charge percentage. */ float battery_getCharge(float vbat); diff --git a/openrtx/src/battery.c b/openrtx/src/battery.c index c7dbaf15..62026f8e 100644 --- a/openrtx/src/battery.c +++ b/openrtx/src/battery.c @@ -42,7 +42,14 @@ float bat_v_max = 0.0; #error Please define a battery type into platform/targets/.../hwconfig.h #endif -float battery_getCharge(float vbat) { - // Perform a linear interpolation between minimum and maximum charge values +float battery_getCharge(float vbat) +{ + #ifndef BAT_NONE + // Perform a linear interpolation between minimum and maximum charge values. return (vbat - bat_v_min) / (bat_v_max - bat_v_min); + #else + // Return full charge if no battery is present. + (void) vbat; + return 1.0f; + #endif }