19 lines
470 B
C
19 lines
470 B
C
/**
|
|
* @file battery.c
|
|
* @brief Battery monitoring utilities
|
|
*/
|
|
#include "esp_log.h"
|
|
#include "app_main.h"
|
|
|
|
static const char *TAG = "battery";
|
|
|
|
/* Battery percentage lookup table (simple linear for now) */
|
|
uint8_t battery_get_percent(uint16_t mv)
|
|
{
|
|
if (mv >= BAT_FULL_MV) return 100;
|
|
if (mv <= BAT_EMPTY_MV) return 0;
|
|
|
|
/* Linear interpolation between EMPTY and FULL */
|
|
return (uint8_t)((mv - BAT_EMPTY_MV) * 100 / (BAT_FULL_MV - BAT_EMPTY_MV));
|
|
}
|