TB2026-YDS Firmware
Loading...
Searching...
No Matches
Autonomy test service

Self-measured battery autonomy: workload run + discharge-curve logging. More...

Collaboration diagram for Autonomy test service:

Files

file  components/services/autonomy/autonomy.c
 Autonomy test service: run lifecycle, discharge-curve logging, SD export.

Data Structures

struct  autonomy_status_t
 Snapshot of the running test, for the in-progress screen. More...

Enumerations

enum  autonomy_test_t { AUTONOMY_TEST_IDLE = 0 , AUTONOMY_TEST_JACK , AUTONOMY_TEST_BT }
 Which workload the run exercises. More...
enum  autonomy_result_t {
  AUTONOMY_RESULT_NONE = 0 , AUTONOMY_RESULT_CANCELLED , AUTONOMY_RESULT_COMPLETED , AUTONOMY_RESULT_ABORTED ,
  AUTONOMY_RESULT_INTERRUPTED
}
 Outcome of the most recent run, for the UI's "Last run" block. More...

Functions

esp_err_t autonomy_start (autonomy_test_t type)
 Start an autonomy run with the given workload.
void autonomy_cancel (void)
 Cancel the running test, keeping it as the last (cancelled) result. No-op if idle.
bool autonomy_is_running (void)
 Whether a run is currently in progress.
void autonomy_get_status (autonomy_status_t *out)
 Copy the running test's snapshot.
void autonomy_tick (void)
 Periodic hook, called from the maintenance task (after power_tick()).
esp_err_t autonomy_boot_export (void)
 Export a stored (not-yet-exported) run to a CSV on the SD card. Call once at boot.
esp_err_t autonomy_redump (void)
 Re-export the last stored run to a fresh CSV on the SD card (without rebooting).
autonomy_result_t autonomy_get_last_result (void)
 Outcome of the most recent run (AUTONOMY_RESULT_NONE until one happens).
autonomy_test_t autonomy_get_last_type (void)
 Workload of the most recent run (valid when the last result is not NONE).
uint32_t autonomy_get_last_duration_s (void)
 Duration of the most recent run in seconds (0 if none).
bool autonomy_get_last_dump_ok (void)
 Whether the most recent run has been successfully written to the SD card.

Detailed Description

Self-measured battery autonomy: workload run + discharge-curve logging.

Enumeration Type Documentation

◆ autonomy_result_t

Outcome of the most recent run, for the UI's "Last run" block.

Enumerator
AUTONOMY_RESULT_NONE 

No run recorded yet.

AUTONOMY_RESULT_CANCELLED 

The user cancelled the run (B).

AUTONOMY_RESULT_COMPLETED 

The run ran to battery shutdown.

AUTONOMY_RESULT_ABORTED 

USB was plugged mid-run: the measurement is invalid.

AUTONOMY_RESULT_INTERRUPTED 

The run never finished cleanly (crash/reset mid-test); partial data.

◆ autonomy_test_t

Which workload the run exercises.

Enumerator
AUTONOMY_TEST_IDLE 

No playback, standard idle.

AUTONOMY_TEST_JACK 

Looped playback to the wired jack (DAC).

AUTONOMY_TEST_BT 

Looped playback to a connected Bluetooth sink.

Function Documentation

◆ autonomy_boot_export()

esp_err_t autonomy_boot_export ( void )

Export a stored (not-yet-exported) run to a CSV on the SD card. Call once at boot.

Reads the NVS run blob; if one is present and not yet exported, writes it as a CSV to the SD card, marks it exported, and populates the "last run" fields for the UI. Requires the SD card to be mounted. A no-op if there is no stored run. Also loads the last-run summary for the UI even when the run was already exported on an earlier boot.

Returns
ESP_OK if a run was exported (or there was nothing to do); an esp_err_t on SD/NVS error.

◆ autonomy_cancel()

void autonomy_cancel ( void )

Cancel the running test, keeping it as the last (cancelled) result. No-op if idle.

◆ autonomy_get_last_dump_ok()

bool autonomy_get_last_dump_ok ( void )

Whether the most recent run has been successfully written to the SD card.

◆ autonomy_get_last_duration_s()

uint32_t autonomy_get_last_duration_s ( void )

Duration of the most recent run in seconds (0 if none).

◆ autonomy_get_last_result()

autonomy_result_t autonomy_get_last_result ( void )

Outcome of the most recent run (AUTONOMY_RESULT_NONE until one happens).

◆ autonomy_get_last_type()

autonomy_test_t autonomy_get_last_type ( void )

Workload of the most recent run (valid when the last result is not NONE).

◆ autonomy_get_status()

void autonomy_get_status ( autonomy_status_t * out)

Copy the running test's snapshot.

Parameters
[out]outReceives the snapshot; ignored if NULL.

◆ autonomy_is_running()

bool autonomy_is_running ( void )

Whether a run is currently in progress.

◆ autonomy_redump()

esp_err_t autonomy_redump ( void )

Re-export the last stored run to a fresh CSV on the SD card (without rebooting).

Writes the run currently held in RAM (loaded at boot by autonomy_boot_export(), or the one that just ended this session) out to a new uniquely-named CSV, to confirm the SD write path. A no-op while a run is in progress.

Returns
ESP_OK on write; ESP_ERR_INVALID_STATE if a run is in progress; ESP_ERR_NOT_FOUND if no run is stored; otherwise the SD/NVS error from the export.

◆ autonomy_start()

esp_err_t autonomy_start ( autonomy_test_t type)

Start an autonomy run with the given workload.

IDLE stops playback (silence). JACK and BT measure whatever is already playing on the respective output: the caller must have a track playing on the DAC (JACK) or on a connected Bluetooth sink (BT) first. The run pins that stream down for the duration — it forces loop-one (so it never ends early) and a fixed pot-independent volume (JACK 50%, BT a near-silent 1% — BT amplifies in the externally powered speaker, so its level does not affect this board's draw) — and restores both when the run ends.

Parameters
typeWorkload to exercise.
Returns
ESP_OK; ESP_ERR_INVALID_STATE if a run is already in progress, or if nothing is playing (JACK/BT), or if no Bluetooth sink is connected (BT).

◆ autonomy_tick()

void autonomy_tick ( void )

Periodic hook, called from the maintenance task (after power_tick()).

Samples the discharge curve at the current interval and persists it. While a run is in progress it also owns the end: once the cell is near-empty (power_soc_at_shutdown(), on battery, not charging) it writes the final log and calls power_shutdown(). No-op when no run is in progress.