电池服务
电池服务 (battery service) 提供了监测和管理电池电压的功能。电池电压和 battery_service_event_t
定义的事件可以通过回调函数与用户进行交互。
应用示例
以下示例展示了该 API 的实现方式。
Header File
Functions
-
periph_service_handle_t battery_service_create(battery_service_config_t *config)
Create the battery service instance.
- 参数
config – configuration of the battery service
- 返回
NULL: Failed
Others: Success
-
esp_err_t battery_service_vol_report_switch(periph_service_handle_t handle, bool on_off)
Start or stop the battery voltage report.
- 参数
handle – [in] pointer to ‘periph_service_handle_t’ structure
on_off – [in] ‘true’ to start, ‘false’ to stop
- 返回
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
-
esp_err_t battery_service_set_vol_report_freq(periph_service_handle_t handle, int freq)
Set voltage report freqency.
- 参数
handle – [in] pointer to ‘periph_service_handle_t’ structure
freq – [in] voltage report freqency
- 返回
ESP_OK: Success
ESP_ERR_INVALID_ARG: handle is NULL
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 task_stack
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.
- 参数
config – [in] pointer to ‘vol_monitor_param_t’ structure
- 返回
NULL: Failed
Others: Success
-
esp_err_t vol_monitor_destroy(vol_monitor_handle_t handle)
Destroy the voltage monitor.
- 参数
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- 返回
ESP_OK: Success
Others: Failed
-
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.
- 参数
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
event_cb – [in] callback used to handle the events of voltage monitor
user_ctx – [in] user’s data
- 返回
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_start_freq_report(vol_monitor_handle_t handle)
Start the voltage report with the configured frequency.
- 参数
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- 返回
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_stop_freq_report(vol_monitor_handle_t handle)
Stop the voltage frequency report.
- 参数
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
- 返回
ESP_OK: Success
Others: Failed
-
esp_err_t vol_monitor_set_report_freq(vol_monitor_handle_t handle, int freq)
Set the voltage report frequency.
- 参数
handle – [in] pointer to ‘vol_monitor_handle_t’ structure
freq – [in] voltage report freqency
- 返回
ESP_OK: Success
Others: Failed
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 (*init)(void*)
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