TB2026-YDS Firmware
Loading...
Searching...
No Matches
settings.h File Reference

Settings service: persistent user-preference store backed by NVS. More...

#include "esp_err.h"
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Functions

esp_err_t settings_init (void)
 Initialise NVS so the settings accessors can be used.
esp_err_t settings_get_u8 (const char *key, uint8_t *out)
 Read a stored uint8 preference.
esp_err_t settings_set_u8 (const char *key, uint8_t val)
 Store a uint8 preference and commit it.
esp_err_t settings_get_u32 (const char *key, uint32_t *out)
 Read a stored uint32 preference.
esp_err_t settings_set_u32 (const char *key, uint32_t val)
 Store a uint32 preference and commit it.
esp_err_t settings_get_str (const char *key, char *out, size_t out_size)
 Read a stored NUL-terminated string preference.
esp_err_t settings_set_str (const char *key, const char *val)
 Store a NUL-terminated string preference and commit it.

Detailed Description

Settings service: persistent user-preference store backed by NVS.

A thin, generic key/value wrapper over a single NVS namespace ("settings"). Other services and screens use it to remember a value across reboots without each one re-implementing its own NVS open/commit dance. The service does not know what any key means: callers own the keys, the types, and the defaults.

Typical use (e.g. OLED brightness, last-played position):

uint8_t brightness;
if (settings_get_u8("oled_bri", &brightness) != ESP_OK)
brightness = OLED_BRIGHTNESS_DEFAULT; // first boot: nothing stored yet
...
settings_set_u8("oled_bri", brightness); // persist a change
esp_err_t settings_get_u8(const char *key, uint8_t *out)
Read a stored uint8 preference.
Definition settings.c:25

This service owns no task. Each accessor opens, reads/writes, commits, and closes the namespace; saves are rare (a user changing a preference), so the per-call handle keeps the implementation simple and stateless.

Bluetooth keeps its own NVS namespace ("bt") for the known-device list; this store is for scalar preferences, not that blob.

Note
Développé avec l'assistance de Claude Opus 4.8 (Anthropic), sous la direction de Y. Dos Santos : spécification, revue et validation sur cible par l'auteur.