Merge branch 'feature/hfp_hf_vendor_batt_level' into 'master'
components/bt: support for vendor specific battery level and docker status... See merge request espressif/esp-idf!17601
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -14,6 +14,27 @@
|
||||
|
||||
extern esp_bd_addr_t peer_addr;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *tgt;
|
||||
struct arg_str *vol;
|
||||
struct arg_end *end;
|
||||
} vu_args_t;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *btrh;
|
||||
struct arg_end *end;
|
||||
} rh_args_t;
|
||||
|
||||
typedef struct {
|
||||
struct arg_int *bat_level;
|
||||
struct arg_int *docked;
|
||||
struct arg_end *end;
|
||||
} bat_args_t;
|
||||
|
||||
static vu_args_t vu_args;
|
||||
static rh_args_t rh_args;
|
||||
static bat_args_t bat_args;
|
||||
|
||||
void hf_msg_show_usage(void)
|
||||
{
|
||||
printf("########################################################################\n");
|
||||
@@ -45,6 +66,8 @@ void hf_msg_show_usage(void)
|
||||
printf(" 2 -reject the held call\n");
|
||||
printf("hf k <dtmf>; -- send dtmf code.\n");
|
||||
printf(" dtmf: single character in set 0-9, *, #, A-D\n");
|
||||
printf("hf xp; -- Enable Vendor specific feature for battery status\n");
|
||||
printf("hf bat; -- Send battery status\n");
|
||||
printf("hf h; -- show command manual\n");
|
||||
printf("########################################################################\n");
|
||||
}
|
||||
@@ -254,6 +277,35 @@ HF_CMD_HANDLER(dtmf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
HF_CMD_HANDLER(xapl)
|
||||
{
|
||||
printf("send XAPL feature enable command to indicate battery level\n");
|
||||
esp_hf_client_send_xapl("0505-1995-0610", ESP_HF_CLIENT_XAPL_FEAT_BATTERY_REPORT | ESP_HF_CLIENT_XAPL_FEAT_DOCKED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
HF_CMD_HANDLER(iphoneaccev)
|
||||
{
|
||||
int nerrors = arg_parse(argn, argv, (void**) &bat_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, bat_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bat_level = bat_args.bat_level->ival[0];
|
||||
bool docked = bat_args.docked->ival[0] == 0 ? false : true;
|
||||
|
||||
if (bat_level > 9 || bat_level < 0) {
|
||||
printf("Invalid argument for battery level %d\n", bat_level);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("send battery level and docker status\n");
|
||||
esp_hf_client_send_iphoneaccev(bat_level, docked);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static hf_msg_hdl_t hf_cmd_tbl[] = {
|
||||
{0, "h", hf_help_handler},
|
||||
{5, "con", hf_conn_handler},
|
||||
@@ -274,6 +326,8 @@ static hf_msg_hdl_t hf_cmd_tbl[] = {
|
||||
{140, "rv", hf_request_last_voice_tag_handler},
|
||||
{150, "rh", hf_btrh_handler},
|
||||
{160, "k", hf_dtmf_handler},
|
||||
{170, "xp", hf_xapl_handler},
|
||||
{180, "bat", hf_iphoneaccev_handler},
|
||||
};
|
||||
|
||||
hf_msg_hdl_t *hf_get_cmd_tbl(void)
|
||||
@@ -306,7 +360,9 @@ enum hf_cmd_name {
|
||||
rs, /*retrieve subscriber information*/
|
||||
rv, /*retrieve last voice tag number*/
|
||||
rh, /*response and hold*/
|
||||
k /*send dtmf code*/
|
||||
k, /*send dtmf code*/
|
||||
xp, /*send XAPL feature enable command to indicate battery level*/
|
||||
bat, /*send battery level and docker status*/
|
||||
};
|
||||
static char *hf_cmd_explain[] = {
|
||||
"show command manual",
|
||||
@@ -328,20 +384,9 @@ static char *hf_cmd_explain[] = {
|
||||
"retrieve last voice tag number",
|
||||
"response and hold",
|
||||
"send dtmf code.\n <dtmf> single character in set 0-9, *, #, A-D",
|
||||
"send XAPL feature enable command to indicate battery level",
|
||||
"send battery level and docker status.",
|
||||
};
|
||||
typedef struct {
|
||||
struct arg_str *tgt;
|
||||
struct arg_str *vol;
|
||||
struct arg_end *end;
|
||||
} vu_args_t;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *btrh;
|
||||
struct arg_end *end;
|
||||
} rh_args_t;
|
||||
|
||||
static vu_args_t vu_args;
|
||||
static rh_args_t rh_args;
|
||||
|
||||
void register_hfp_hf(void)
|
||||
{
|
||||
@@ -496,4 +541,24 @@ void register_hfp_hf(void)
|
||||
.func = hf_cmd_tbl[k].handler,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&k_cmd));
|
||||
|
||||
const esp_console_cmd_t xp_cmd = {
|
||||
.command = "xp",
|
||||
.help = hf_cmd_explain[xp],
|
||||
.hint = NULL,
|
||||
.func = hf_cmd_tbl[xp].handler,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&xp_cmd));
|
||||
|
||||
bat_args.bat_level = arg_int0(NULL, NULL, "<bat_level>", "battery level ranges from 0 to 9");
|
||||
bat_args.docked = arg_int0(NULL, NULL, "<docked>", "0 - undocked; 1 - docked");
|
||||
bat_args.end = arg_end(1);
|
||||
const esp_console_cmd_t bat_cmd = {
|
||||
.command = "bat",
|
||||
.help = hf_cmd_explain[bat],
|
||||
.hint = "<bat_level> <docked>",
|
||||
.func = hf_cmd_tbl[bat].handler,
|
||||
.argtable = &bat_args,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&bat_cmd));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user