Bluetooth: Audio: Shell: CAP change microphone gain command
Adds the change microphone gain command to the CAP commander shell. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
6f405f6b80
commit
164529145b
2 changed files with 140 additions and 1 deletions
|
@ -339,3 +339,37 @@ Setting the volume mute on all connected devices
|
||||||
VCP volume 100, mute 0
|
VCP volume 100, mute 0
|
||||||
VCP unmute done
|
VCP unmute done
|
||||||
Volume mute change completed
|
Volume mute change completed
|
||||||
|
|
||||||
|
Setting the microphone gain on one or more devices
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
The gains are set by connection index, so connection index 0 gets the first offset,
|
||||||
|
and index 1 gets the second offset, etc.:
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
uart:~$ bt connect <device A>
|
||||||
|
Connected: <device A>
|
||||||
|
uart:~$ cap_commander discover
|
||||||
|
discovery completed with CSIS
|
||||||
|
uart:~$ micp_mic_ctlr discover
|
||||||
|
MICP discover done with 1 AICS
|
||||||
|
uart:~$
|
||||||
|
uart:~$ bt connect <device B>
|
||||||
|
Connected: <device B>
|
||||||
|
uart:~$ cap_commander discover
|
||||||
|
discovery completed with CSIS
|
||||||
|
uart:~$ micp_mic_ctlr discover
|
||||||
|
MICP discover done with 1 AICS
|
||||||
|
uart:~$
|
||||||
|
uart:~$ cap_commander change_microphone_gain 10
|
||||||
|
Setting microphone gain on 1 connections
|
||||||
|
AICS inst 0x200140a4 state gain 10, mute 0, mode 0
|
||||||
|
Gain set for inst 0x200140a4
|
||||||
|
Microphone gain change completed
|
||||||
|
uart:~$
|
||||||
|
uart:~$ cap_commander change_microphone_gain 10 15
|
||||||
|
Setting microphone gain on 2 connections
|
||||||
|
Gain set for inst 0x200140a4
|
||||||
|
AICS inst 0x20014188 state gain 15, mute 0, mode 0
|
||||||
|
Gain set for inst 0x20014188
|
||||||
|
Microphone gain change completed
|
||||||
|
|
|
@ -62,6 +62,20 @@ static void cap_volume_offset_changed_cb(struct bt_conn *conn, int err)
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||||
|
static void cap_microphone_gain_changed_cb(struct bt_conn *conn, int err)
|
||||||
|
{
|
||||||
|
if (err != 0) {
|
||||||
|
shell_error(ctx_shell, "Microphone gain change failed (%d)", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell_print(ctx_shell, "Microphone gain change completed");
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||||
|
|
||||||
static struct bt_cap_commander_cb cbs = {
|
static struct bt_cap_commander_cb cbs = {
|
||||||
.discovery_complete = cap_discover_cb,
|
.discovery_complete = cap_discover_cb,
|
||||||
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
||||||
|
@ -71,6 +85,11 @@ static struct bt_cap_commander_cb cbs = {
|
||||||
.volume_offset_changed = cap_volume_offset_changed_cb,
|
.volume_offset_changed = cap_volume_offset_changed_cb,
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||||
|
.microphone_gain_changed = cap_microphone_gain_changed_cb,
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cmd_cap_commander_discover(const struct shell *sh, size_t argc, char *argv[])
|
static int cmd_cap_commander_discover(const struct shell *sh, size_t argc, char *argv[])
|
||||||
|
@ -100,7 +119,7 @@ static int cmd_cap_commander_discover(const struct shell *sh, size_t argc, char
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
#if defined(CONFIG_BT_VCP_VOL_CTLR) || defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||||
static void populate_connected_conns(struct bt_conn *conn, void *data)
|
static void populate_connected_conns(struct bt_conn *conn, void *data)
|
||||||
{
|
{
|
||||||
struct bt_conn **connected_conns = (struct bt_conn **)data;
|
struct bt_conn **connected_conns = (struct bt_conn **)data;
|
||||||
|
@ -112,7 +131,9 @@ static void populate_connected_conns(struct bt_conn *conn, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_BT_VCP_VOL_CTLR || CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
||||||
static int cmd_cap_commander_change_volume(const struct shell *sh, size_t argc, char *argv[])
|
static int cmd_cap_commander_change_volume(const struct shell *sh, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0};
|
struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0};
|
||||||
|
@ -297,6 +318,83 @@ static int cmd_cap_commander_change_volume_offset(const struct shell *sh, size_t
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||||
|
static int cmd_cap_commander_change_microphone_gain(const struct shell *sh, size_t argc,
|
||||||
|
char *argv[])
|
||||||
|
{
|
||||||
|
struct bt_cap_commander_change_microphone_gain_setting_member_param
|
||||||
|
member_params[CONFIG_BT_MAX_CONN];
|
||||||
|
const size_t cap_args = argc - 1; /* First argument is the command itself */
|
||||||
|
struct bt_cap_commander_change_microphone_gain_setting_param param = {
|
||||||
|
.type = BT_CAP_SET_TYPE_AD_HOC,
|
||||||
|
.param = member_params,
|
||||||
|
};
|
||||||
|
struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0};
|
||||||
|
size_t conn_cnt = 0U;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (default_conn == NULL) {
|
||||||
|
shell_error(sh, "Not connected");
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Populate the array of connected connections */
|
||||||
|
bt_conn_foreach(BT_CONN_TYPE_LE, populate_connected_conns, (void *)connected_conns);
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(connected_conns); i++) {
|
||||||
|
struct bt_conn *conn = connected_conns[i];
|
||||||
|
|
||||||
|
if (conn == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap_args > conn_cnt) {
|
||||||
|
shell_error(sh, "Cannot use %zu arguments for %zu connections", argc, conn_cnt);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Add support for coordinated sets */
|
||||||
|
|
||||||
|
for (size_t i = 0U; i < cap_args; i++) {
|
||||||
|
const char *arg = argv[i + 1];
|
||||||
|
long gain;
|
||||||
|
|
||||||
|
gain = shell_strtol(arg, 10, &err);
|
||||||
|
if (err != 0) {
|
||||||
|
shell_error(sh, "Failed to parse volume offset from %s", arg);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IN_RANGE(gain, INT8_MIN, INT8_MAX)) {
|
||||||
|
shell_error(sh, "Invalid gain %lu", gain);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
member_params[i].gain = (int8_t)gain;
|
||||||
|
member_params[i].member.member = connected_conns[i];
|
||||||
|
param.count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell_print(sh, "Setting microphone gain on %zu connections", param.count);
|
||||||
|
|
||||||
|
err = bt_cap_commander_change_microphone_gain_setting(¶m);
|
||||||
|
if (err != 0) {
|
||||||
|
shell_print(sh, "Failed to change microphone gain: %d", err);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||||
|
|
||||||
static int cmd_cap_commander(const struct shell *sh, size_t argc, char **argv)
|
static int cmd_cap_commander(const struct shell *sh, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
@ -323,6 +421,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
|
||||||
cmd_cap_commander_change_volume_offset, 2, CONFIG_BT_MAX_CONN - 1),
|
cmd_cap_commander_change_volume_offset, 2, CONFIG_BT_MAX_CONN - 1),
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
|
||||||
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR)
|
||||||
|
#if defined(CONFIG_BT_MICP_MIC_CTLR_AICS)
|
||||||
|
SHELL_CMD_ARG(change_microphone_gain, NULL,
|
||||||
|
"Change microphone gain per connection <gain [gain [...]]>",
|
||||||
|
cmd_cap_commander_change_microphone_gain, 2, CONFIG_BT_MAX_CONN - 1),
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||||
|
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||||
SHELL_SUBCMD_SET_END);
|
SHELL_SUBCMD_SET_END);
|
||||||
|
|
||||||
SHELL_CMD_ARG_REGISTER(cap_commander, &cap_commander_cmds, "Bluetooth CAP commander shell commands",
|
SHELL_CMD_ARG_REGISTER(cap_commander, &cap_commander_cmds, "Bluetooth CAP commander shell commands",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue