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:

  1. Executehas_reading = false;
  2. Executeconst esp_err_t result = controller_input_configure_battery();
  3. Decisionresult != ESP_OK
    True
      1. ExecuteESP_LOGE("battery", "Battery ADC setup failed: %s", esp_err_to_name(result));
      2. Exit this functionreturn false;
    False

    Continue after this decision.

  4. Exit this functionreturn 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:

  1. Decisionhas_reading && now_ms - last_update < BATTERY_UPDATE_MS
    True
    1. Exit this functionreturn;
    False

    Continue after this decision.

  2. Executeint millivolts = 0;
  3. Executeconst esp_err_t result = controller_input_read_battery_millivolts(&millivolts);
  4. Decisionresult != ESP_OK
    True
      1. ExecuteESP_LOGE("battery", "Battery ADC read failed: %s", esp_err_to_name(result));
      2. Exit this functionreturn;
    False

    Continue after this decision.

  5. Executevoltage = (float)millivolts * 2.0f / 1000.0f;
  6. Executelast_update = now_ms;
  7. Executehas_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)
  1. Exit this functionreturn has_reading;
Read original function source
bool batt_has_reading(void) { return has_reading; }
batt_voltage() · source line 39
float batt_voltage(void)
  1. Exit this functionreturn voltage;
Read original function source
float batt_voltage(void) { return voltage; }
batt_external_power_connected() · source line 40
bool batt_external_power_connected(void)
  1. Exit this functionreturn 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; }