Battery Service¶
The battery service can monitor and manage battery voltage. You can access battery voltage and the events defined by battery_service_event_t
through callback functions.
Application Example¶
Implementation of this API is demonstrated in the following example:
Header File¶
Functions¶
-
periph_service_handle_t
battery_service_create
(battery_service_config_t *config)¶ Create the battery service instance.
- Return
NULL: Failed
Others: Success
- Parameters
config
: configuration of the battery service
-
esp_err_t
battery_service_vol_report_switch
(periph_service_handle_t handle, bool on_off)¶ Start or stop the battery voltage report.
- Return
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
- Parameters
[in] handle
: pointer to ‘periph_service_handle_t’ structure[in] on_off
: ‘true’ to start, ‘false’ to stop
-
esp_err_t
battery_service_set_vol_report_freq
(periph_service_handle_t handle, int freq)¶ Set voltage report freqency.
- Return
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
- Parameters
[in] handle
: pointer to ‘periph_service_handle_t’ structure[in] freq
: voltage report freqency
Structures¶
-
struct
battery_service_config_t
¶ Battery service configure.
Public Members
-
int
task_stack
¶ >0 Service task stack; =0 with out task created
-
int
task_prio
¶ Service task priority (based on freeRTOS priority)
-
int
task_core
¶ Service task running in core (0 or 1)
-
bool
extern_stack
¶ Task stack allocate on the extern ram
-
periph_service_cb
evt_cb
¶ Service callback function
-
void *
cb_ctx
¶ Callback context
-
vol_monitor_handle_t
vol_monitor
¶ Battery monitor
-
void *
charger_monitor
¶ Charger monitor. Not supported yet
-
int
Macros¶
-
BATTERY_SERVICE_DEFAULT_CONFIG
()¶
Enumerations¶
Header File¶
Functions¶
-
vol_monitor_handle_t
vol_monitor_create
(vol_monitor_param_t *config)¶ Create the voltage monitor instance.
- Return
NULL: Failed
Others: Success
- Parameters
[in] config
: pointer to ‘vol_monitor_param_t’ structure
-
esp_err_t
vol_monitor_destroy
(vol_monitor_handle_t handle)¶ Destroy the voltage monitor.
- Return
ESP_OK: Success
Others: Failed
- Parameters
[in] handle
: pointer to ‘vol_monitor_handle_t’ structure
-
esp_err_t
vol_monitor_set_event_cb
(vol_monitor_handle_t handle, vol_monitor_event_cb event_cb, void *user_ctx)¶ Set the event callback.
- Return
ESP_OK: Success
Others: Failed
- Parameters
[in] handle
: pointer to ‘vol_monitor_handle_t’ structure[in] event_cb
: callback used to handle the events of voltage monitor[in] user_ctx
: user’s data
-
esp_err_t
vol_monitor_start_freq_report
(vol_monitor_handle_t handle)¶ Start the voltage report with the configured frequency.
- Return
ESP_OK: Success
Others: Failed
- Parameters
[in] handle
: pointer to ‘vol_monitor_handle_t’ structure
-
esp_err_t
vol_monitor_stop_freq_report
(vol_monitor_handle_t handle)¶ Stop the voltage frequency report.
- Return
ESP_OK: Success
Others: Failed
- Parameters
[in] handle
: pointer to ‘vol_monitor_handle_t’ structure
-
esp_err_t
vol_monitor_set_report_freq
(vol_monitor_handle_t handle, int freq)¶ Set the voltage report frequency.
- Return
ESP_OK: Success
Others: Failed
- Parameters
[in] handle
: pointer to ‘vol_monitor_handle_t’ structure[in] freq
: voltage report freqency
Structures¶
-
struct
vol_monitor_param_t
¶ Battery adc configure.
Public Members
-
bool (*
init
)(void *)¶ Voltage read init
-
bool (*
deinit
)(void *)¶ Voltage read deinit
-
int (*
vol_get
)(void *)¶ Voltage read interface
-
void *
user_data
¶ Parameters for callbacks
-
int
read_freq
¶ Voltage read frequency, unit: s
-
int
report_freq
¶ Voltage report frequency, voltage will be report with a interval calculate by (
read_freq
*report_freq
)
-
int
vol_full_threshold
¶ Voltage threshold to report, unit: mV
-
int
vol_low_threshold
¶ Voltage threshold to report, unit: mV
-
bool (*
Type Definitions¶
-
typedef void *
vol_monitor_handle_t
¶ voltage monitor handle
-
typedef void (*
vol_monitor_event_cb
)(int msg_id, void *data, void *user_ctx)¶ callback define