Bluetooth: Audio: Shell: CAP change volume command
Add sthe change volume command to the CAP commander shell. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
6e52f384c8
commit
490c5e3b20
3 changed files with 114 additions and 2 deletions
|
@ -159,7 +159,9 @@ the optionally included CSIS instance by calling (:code:`cap_commander discover`
|
||||||
cap_commander --help
|
cap_commander --help
|
||||||
cap_commander - Bluetooth CAP commander shell commands
|
cap_commander - Bluetooth CAP commander shell commands
|
||||||
Subcommands:
|
Subcommands:
|
||||||
discover :Discover CAS
|
discover :Discover CAS
|
||||||
|
change_volume :Change volume on all connections <volume>
|
||||||
|
|
||||||
|
|
||||||
Before being able to perform any stream operation, the device must also perform the
|
Before being able to perform any stream operation, the device must also perform the
|
||||||
:code:`bap discover` operation to discover the ASEs and PAC records. The :code:`bap init`
|
:code:`bap discover` operation to discover the ASEs and PAC records. The :code:`bap init`
|
||||||
|
@ -174,3 +176,20 @@ Discovering CAS and CSIS on a device:
|
||||||
|
|
||||||
uart:~$ cap_commander discover
|
uart:~$ cap_commander discover
|
||||||
discovery completed with CSIS
|
discovery completed with CSIS
|
||||||
|
|
||||||
|
|
||||||
|
Setting the volume on all connected devices:
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
uart:~$ vcp_vol_ctlr discover
|
||||||
|
VCP discover done with 1 VOCS and 1 AICS
|
||||||
|
uart:~$ cap_commander change_volume 15
|
||||||
|
uart:~$ cap_commander change_volume 15
|
||||||
|
Setting volume to 15 on 2 connections
|
||||||
|
VCP volume 15, mute 0
|
||||||
|
VCP vol_set done
|
||||||
|
VCP volume 15, mute 0
|
||||||
|
VCP flags 0x01
|
||||||
|
VCP vol_set done
|
||||||
|
Volume change completed
|
||||||
|
|
|
@ -27,8 +27,23 @@ static void cap_discover_cb(struct bt_conn *conn, int err,
|
||||||
shell_print(ctx_shell, "discovery completed%s", csis_inst == NULL ? "" : " with CSIS");
|
shell_print(ctx_shell, "discovery completed%s", csis_inst == NULL ? "" : " with CSIS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
||||||
|
static void cap_volume_changed_cb(struct bt_conn *conn, int err)
|
||||||
|
{
|
||||||
|
if (err != 0) {
|
||||||
|
shell_error(ctx_shell, "Volume change failed (%d)", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell_print(ctx_shell, "Volume change completed");
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_VCP_VOL_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)
|
||||||
|
.volume_changed = cap_volume_changed_cb,
|
||||||
|
#endif /* CONFIG_BT_VCP_VOL_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[])
|
||||||
|
@ -58,6 +73,80 @@ 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)
|
||||||
|
static void populate_connected_conns(struct bt_conn *conn, void *data)
|
||||||
|
{
|
||||||
|
struct bt_conn **connected_conns = (struct bt_conn **)data;
|
||||||
|
|
||||||
|
for (int i = 0; i < CONFIG_BT_MAX_CONN; i++) {
|
||||||
|
if (connected_conns[i] == NULL) {
|
||||||
|
connected_conns[i] = conn;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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};
|
||||||
|
union bt_cap_set_member members[CONFIG_BT_MAX_CONN] = {0};
|
||||||
|
struct bt_cap_commander_change_volume_param param = {
|
||||||
|
.members = members,
|
||||||
|
};
|
||||||
|
unsigned long volume;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (default_conn == NULL) {
|
||||||
|
shell_error(sh, "Not connected");
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
volume = shell_strtoul(argv[1], 10, &err);
|
||||||
|
if (err != 0) {
|
||||||
|
shell_error(sh, "Failed to parse volume from %s", argv[1]);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volume > UINT8_MAX) {
|
||||||
|
shell_error(sh, "Invalid volume %lu", volume);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
param.volume = (uint8_t)volume;
|
||||||
|
|
||||||
|
param.type = BT_CAP_SET_TYPE_AD_HOC;
|
||||||
|
/* TODO: Add support for coordinated sets */
|
||||||
|
|
||||||
|
/* Populate the array of connected connections */
|
||||||
|
bt_conn_foreach(BT_CONN_TYPE_LE, populate_connected_conns, (void *)connected_conns);
|
||||||
|
|
||||||
|
param.count = 0U;
|
||||||
|
param.members = members;
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(connected_conns); i++) {
|
||||||
|
struct bt_conn *conn = connected_conns[i];
|
||||||
|
|
||||||
|
if (conn == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.members[i].member = conn;
|
||||||
|
param.count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell_print(sh, "Setting volume to %u on %zu connections", param.volume, param.count);
|
||||||
|
|
||||||
|
err = bt_cap_commander_change_volume(¶m);
|
||||||
|
if (err != 0) {
|
||||||
|
shell_print(sh, "Failed to change volume: %d", err);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_VCP_VOL_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) {
|
||||||
|
@ -72,6 +161,10 @@ static int cmd_cap_commander(const struct shell *sh, size_t argc, char **argv)
|
||||||
SHELL_STATIC_SUBCMD_SET_CREATE(
|
SHELL_STATIC_SUBCMD_SET_CREATE(
|
||||||
cap_commander_cmds,
|
cap_commander_cmds,
|
||||||
SHELL_CMD_ARG(discover, NULL, "Discover CAS", cmd_cap_commander_discover, 1, 0),
|
SHELL_CMD_ARG(discover, NULL, "Discover CAS", cmd_cap_commander_discover, 1, 0),
|
||||||
|
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
||||||
|
SHELL_CMD_ARG(change_volume, NULL, "Change volume on all connections <volume>",
|
||||||
|
cmd_cap_commander_change_volume, 2, 0),
|
||||||
|
#endif /* CONFIG_BT_VCP_VOL_CTLR */
|
||||||
SHELL_SUBCMD_SET_END
|
SHELL_SUBCMD_SET_END
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ static void vcs_discover_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err,
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
shell_error(ctx_shell, "VCP discover failed (%d)", err);
|
shell_error(ctx_shell, "VCP discover failed (%d)", err);
|
||||||
} else {
|
} else {
|
||||||
shell_print(ctx_shell, "VCP discover done with %u AICS",
|
shell_print(ctx_shell, "VCP discover done with %u VOCS and %u AICS", vocs_count,
|
||||||
aics_count);
|
aics_count);
|
||||||
|
|
||||||
if (bt_vcp_vol_ctlr_included_get(vol_ctlr, &vcp_included)) {
|
if (bt_vcp_vol_ctlr_included_get(vol_ctlr, &vcp_included)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue