Batt
Source: src/batt.c · 40 lines · 5 functions.
Module entry points
These functions are exposed to the rest of the project. Open one to follow its decisions and the helpers it calls.
How to read these diagrams
Each function has its own expandable diagram using the actual expressions and statements from this file. Decisions split into True and False; loop bodies are indented. Returns end the function immediately; break and continue follow their C meanings. Arrows between statements show their order when execution reaches them.
These are structural source diagrams before preprocessing, not runtime traces. Conditional compilation and macros remain source expressions. Ternary choices remain inside their statement. Calls are linked separately; callback execution and task scheduling are not inferred.
Functions in this file
batt_initialize() · source line 13
bool batt_initialize(void)
Calls into this documentation:
- Execute
has_reading = false; - Execute
const esp_err_t result = controller_input_configure_battery(); - Decision
result != ESP_OKTrue- Execute
ESP_LOGE("battery", "Battery ADC setup failed: %s", esp_err_to_name(result)); - Exit this function
return false;
FalseContinue after this decision.
- Exit this function
return true;
Read original function source
bool batt_initialize(void)
{
has_reading = false;
const esp_err_t result = controller_input_configure_battery();
if (result != ESP_OK) {
ESP_LOGE("battery", "Battery ADC setup failed: %s", esp_err_to_name(result));
return false;
}
return true;
}batt_update() · source line 24
void batt_update(uint32_t now_ms)
Calls into this documentation:
- Decision
has_reading && now_ms - last_update < BATTERY_UPDATE_MSTrue- Exit this function
return;
FalseContinue after this decision.
- Execute
int millivolts = 0; - Execute
const esp_err_t result = controller_input_read_battery_millivolts(&millivolts); - Decision
result != ESP_OKTrue- Execute
ESP_LOGE("battery", "Battery ADC read failed: %s", esp_err_to_name(result)); - Exit this function
return;
FalseContinue after this decision.
- Execute
voltage = (float)millivolts * 2.0f / 1000.0f; - Execute
last_update = now_ms; - Execute
has_reading = true;
Read original function source
void batt_update(uint32_t now_ms)
{
if (has_reading && now_ms - last_update < BATTERY_UPDATE_MS) return;
int millivolts = 0;
const esp_err_t result = controller_input_read_battery_millivolts(&millivolts);
if (result != ESP_OK) {
ESP_LOGE("battery", "Battery ADC read failed: %s", esp_err_to_name(result));
return;
}
voltage = (float)millivolts * 2.0f / 1000.0f;
last_update = now_ms;
has_reading = true;
}batt_has_reading() · source line 38
bool batt_has_reading(void)
- Exit this function
return has_reading;
Read original function source
bool batt_has_reading(void) { return has_reading; }batt_voltage() · source line 39
float batt_voltage(void)
- Exit this function
return voltage;
Read original function source
float batt_voltage(void) { return voltage; }batt_external_power_connected() · source line 40
bool batt_external_power_connected(void)
- Exit this function
return has_reading && voltage >= EXTERNAL_POWER_VOLTAGE;
Read original function source
bool batt_external_power_connected(void) { return has_reading && voltage >= EXTERNAL_POWER_VOLTAGE; }Complete original file, including constants and data
/* Coded By JD(2026) */
#error "Reference listing only — not provided as build-ready source."
#include "batt.h"
#include "controller_input.h"
#include "esp_log.h"
#define BATTERY_UPDATE_MS 15000U
#define EXTERNAL_POWER_VOLTAGE 4.3f
static float voltage;
static uint32_t last_update;
static bool has_reading;
bool batt_initialize(void)
{
has_reading = false;
const esp_err_t result = controller_input_configure_battery();
if (result != ESP_OK) {
ESP_LOGE("battery", "Battery ADC setup failed: %s", esp_err_to_name(result));
return false;
}
return true;
}
void batt_update(uint32_t now_ms)
{
if (has_reading && now_ms - last_update < BATTERY_UPDATE_MS) return;
int millivolts = 0;
const esp_err_t result = controller_input_read_battery_millivolts(&millivolts);
if (result != ESP_OK) {
ESP_LOGE("battery", "Battery ADC read failed: %s", esp_err_to_name(result));
return;
}
voltage = (float)millivolts * 2.0f / 1000.0f;
last_update = now_ms;
has_reading = true;
}
bool batt_has_reading(void) { return has_reading; }
float batt_voltage(void) { return voltage; }
bool batt_external_power_connected(void) { return has_reading && voltage >= EXTERNAL_POWER_VOLTAGE; }