Made 'battery_getCharge' return full charge when 'BAT_NONE' is defined

This commit is contained in:
Silvano Seva 2021-04-10 12:45:02 +02:00
parent cdaf3f38dd
commit d70e0bc60a
2 changed files with 13 additions and 5 deletions

View File

@ -20,10 +20,11 @@
#ifndef BATTERY_H #ifndef BATTERY_H
#define 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. * charge percentage.
* @param vbat: the voltage read from the battery in volt * @param vbat: the voltage read from the battery in volt.
* @return the charge percentage * @return the charge percentage.
*/ */
float battery_getCharge(float vbat); float battery_getCharge(float vbat);

View File

@ -42,7 +42,14 @@ float bat_v_max = 0.0;
#error Please define a battery type into platform/targets/.../hwconfig.h #error Please define a battery type into platform/targets/.../hwconfig.h
#endif #endif
float battery_getCharge(float vbat) { float battery_getCharge(float vbat)
// Perform a linear interpolation between minimum and maximum charge values {
#ifndef BAT_NONE
// Perform a linear interpolation between minimum and maximum charge values.
return (vbat - bat_v_min) / (bat_v_max - bat_v_min); 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
} }