Commit 51f2022f authored by Emil Gydesen's avatar Emil Gydesen Committed by Anas Nashif
Browse files

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: default avatarEmil Gydesen <emil.gydesen@nordicsemi.no>
parent 6a8abcb2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -39,11 +39,24 @@ extern "C" {
#define BT_VCS_ERR_INVALID_COUNTER             0x80
#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. */
struct bt_vcs;

/** Register structure for Volume Control Service */
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 */
	struct bt_vocs_register_param vocs_param[BT_VCS_VOCS_CNT];

+23 −7
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
			notify = true;
		}
		if (vcs_inst.srv.state.mute) {
			vcs_inst.srv.state.mute = 0;
			vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
			notify = true;
		}
		volume_change = true;
@@ -164,7 +164,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
			notify = true;
		}
		if (vcs_inst.srv.state.mute) {
			vcs_inst.srv.state.mute = 0;
			vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
			notify = true;
		}
		volume_change = true;
@@ -181,14 +181,14 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
	case BT_VCS_OPCODE_UNMUTE:
		BT_DBG("Unmute (0x%x)", opcode);
		if (vcs_inst.srv.state.mute) {
			vcs_inst.srv.state.mute = 0;
			vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
			notify = true;
		}
		break;
	case BT_VCS_OPCODE_MUTE:
		BT_DBG("Mute (0x%x)", opcode);
		if (vcs_inst.srv.state.mute == 0) {
			vcs_inst.srv.state.mute = 1;
		if (vcs_inst.srv.state.mute == BT_VCS_STATE_UNMUTED) {
			vcs_inst.srv.state.mute = BT_VCS_STATE_MUTED;
			notify = true;
		}
		break;
@@ -362,6 +362,21 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
	static bool registered;
	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) {
		*vcs = &vcs_inst;
		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.volume_step = 1; /* Default value */
	vcs_inst.srv.state.volume = param->volume;
	vcs_inst.srv.state.mute = param->mute;
	vcs_inst.srv.volume_step = param->step;
	vcs_inst.srv.service_p = &vcs_svc;

	err = bt_gatt_service_register(&vcs_svc);
+4 −0
Original line number Diff line number Diff line
@@ -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.step = 1;
	vcs_param.mute = BT_VCS_STATE_UNMUTED;
	vcs_param.volume = 100;

	vcs_param.cb = &vcs_cbs;

	result = bt_vcs_register(&vcs_param, &vcs);
+6 −0
Original line number Diff line number Diff line
@@ -474,6 +474,9 @@ static void test_standalone(void)
		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;

	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.step = 1;
	vcs_param.mute = BT_VCS_STATE_UNMUTED;
	vcs_param.volume = 100;
	vcs_param.cb = &vcs_cb;

	err = bt_vcs_register(&vcs_param, &vcs);