Bluetooth: Audio: Add initial server values in bt_vcs_register_param

Add support for setting initial values in bt_vcs_register_param
when registering a VCS service

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-08-24 12:58:46 +02:00 committed by Anas Nashif
commit 51f2022f7b
4 changed files with 46 additions and 7 deletions

View file

@ -39,11 +39,24 @@ extern "C" {
#define BT_VCS_ERR_INVALID_COUNTER 0x80 #define BT_VCS_ERR_INVALID_COUNTER 0x80
#define BT_VCS_ERR_OP_NOT_SUPPORTED 0x81 #define BT_VCS_ERR_OP_NOT_SUPPORTED 0x81
/** Volume Control Service Mute Values */
#define BT_VCS_STATE_UNMUTED 0x00
#define BT_VCS_STATE_MUTED 0x01
/** @brief Opaque Volume Control Service instance. */ /** @brief Opaque Volume Control Service instance. */
struct bt_vcs; struct bt_vcs;
/** Register structure for Volume Control Service */ /** Register structure for Volume Control Service */
struct bt_vcs_register_param { struct bt_vcs_register_param {
/** Initial step size (1-255) */
uint8_t step;
/** Initial mute state (0-1) */
uint8_t mute;
/** Initial volume level (0-255) */
uint8_t volume;
/** Register parameters for Volume Offset Control Services */ /** Register parameters for Volume Offset Control Services */
struct bt_vocs_register_param vocs_param[BT_VCS_VOCS_CNT]; struct bt_vocs_register_param vocs_param[BT_VCS_VOCS_CNT];

View file

@ -152,7 +152,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
notify = true; notify = true;
} }
if (vcs_inst.srv.state.mute) { if (vcs_inst.srv.state.mute) {
vcs_inst.srv.state.mute = 0; vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
notify = true; notify = true;
} }
volume_change = true; volume_change = true;
@ -164,7 +164,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
notify = true; notify = true;
} }
if (vcs_inst.srv.state.mute) { if (vcs_inst.srv.state.mute) {
vcs_inst.srv.state.mute = 0; vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
notify = true; notify = true;
} }
volume_change = true; volume_change = true;
@ -181,14 +181,14 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
case BT_VCS_OPCODE_UNMUTE: case BT_VCS_OPCODE_UNMUTE:
BT_DBG("Unmute (0x%x)", opcode); BT_DBG("Unmute (0x%x)", opcode);
if (vcs_inst.srv.state.mute) { if (vcs_inst.srv.state.mute) {
vcs_inst.srv.state.mute = 0; vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
notify = true; notify = true;
} }
break; break;
case BT_VCS_OPCODE_MUTE: case BT_VCS_OPCODE_MUTE:
BT_DBG("Mute (0x%x)", opcode); BT_DBG("Mute (0x%x)", opcode);
if (vcs_inst.srv.state.mute == 0) { if (vcs_inst.srv.state.mute == BT_VCS_STATE_UNMUTED) {
vcs_inst.srv.state.mute = 1; vcs_inst.srv.state.mute = BT_VCS_STATE_MUTED;
notify = true; notify = true;
} }
break; break;
@ -362,6 +362,21 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
static bool registered; static bool registered;
int err; int err;
CHECKIF(param == NULL) {
BT_DBG("param is NULL");
return -EINVAL;
}
CHECKIF(param->mute > BT_VCS_STATE_MUTED) {
BT_DBG("Invalid mute value: %u", param->mute);
return -EINVAL;
}
CHECKIF(param->step == 0) {
BT_DBG("Invalid step value: %u", param->step);
return -EINVAL;
}
if (registered) { if (registered) {
*vcs = &vcs_inst; *vcs = &vcs_inst;
return -EALREADY; return -EALREADY;
@ -386,8 +401,9 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
} }
vcs_inst.srv.state.volume = 100; /* Default value */ vcs_inst.srv.state.volume = param->volume;
vcs_inst.srv.volume_step = 1; /* Default value */ vcs_inst.srv.state.mute = param->mute;
vcs_inst.srv.volume_step = param->step;
vcs_inst.srv.service_p = &vcs_svc; vcs_inst.srv.service_p = &vcs_svc;
err = bt_gatt_service_register(&vcs_svc); err = bt_gatt_service_register(&vcs_svc);

View file

@ -193,6 +193,10 @@ static int cmd_vcs_init(const struct shell *sh, size_t argc, char **argv)
vcs_param.aics_param[i].cb = &aics_cbs; vcs_param.aics_param[i].cb = &aics_cbs;
} }
vcs_param.step = 1;
vcs_param.mute = BT_VCS_STATE_UNMUTED;
vcs_param.volume = 100;
vcs_param.cb = &vcs_cbs; vcs_param.cb = &vcs_cbs;
result = bt_vcs_register(&vcs_param, &vcs); result = bt_vcs_register(&vcs_param, &vcs);

View file

@ -474,6 +474,9 @@ static void test_standalone(void)
vcs_param.aics_param[i].cb = &aics_cb; vcs_param.aics_param[i].cb = &aics_cb;
} }
vcs_param.step = 1;
vcs_param.mute = BT_VCS_STATE_UNMUTED;
vcs_param.volume = 100;
vcs_param.cb = &vcs_cb; vcs_param.cb = &vcs_cb;
err = bt_vcs_register(&vcs_param, &vcs); err = bt_vcs_register(&vcs_param, &vcs);
@ -667,6 +670,9 @@ static void test_main(void)
vcs_param.aics_param[i].cb = &aics_cb; vcs_param.aics_param[i].cb = &aics_cb;
} }
vcs_param.step = 1;
vcs_param.mute = BT_VCS_STATE_UNMUTED;
vcs_param.volume = 100;
vcs_param.cb = &vcs_cb; vcs_param.cb = &vcs_cb;
err = bt_vcs_register(&vcs_param, &vcs); err = bt_vcs_register(&vcs_param, &vcs);