diff options
author | Atul Rai <a.rai@samsung.com> | 2016-07-01 17:21:14 +0900 |
---|---|---|
committer | Atul Rai <a.rai@samsung.com> | 2016-07-04 11:55:04 +0900 |
commit | 4d143709681993b1235373160e8fa60c9bdad835 (patch) | |
tree | 30aaa8f58a9e7dedecc0ba4afb2fcdc087661687 | |
parent | 57933b7e3b3eb6cf11323d745a8b19947495cd75 (diff) | |
download | bluetooth-4d143709681993b1235373160e8fa60c9bdad835.tar.gz bluetooth-4d143709681993b1235373160e8fa60c9bdad835.tar.bz2 bluetooth-4d143709681993b1235373160e8fa60c9bdad835.zip |
HID: Added new API to send RC key eventssubmit/tizen/20160704.015035accepted/tizen/wearable/20160705.003600accepted/tizen/tv/20160705.003621accepted/tizen/mobile/20160705.003539accepted/tizen/ivi/20160705.003641accepted/tizen/common/20160704.145416
This patch adds API to send RC key event to remote device.
It also adds new test case to demonstarte usage of added API.
Change-Id: I24da5cbc58ed48707275dc110afdd5d1c19aa154
Signed-off-by: Atul Rai <a.rai@samsung.com>
-rw-r--r-- | include/bluetooth_private.h | 33 | ||||
-rw-r--r-- | src/bluetooth-hid.c | 44 | ||||
-rw-r--r-- | test/bt_unit_test.c | 23 | ||||
-rw-r--r-- | test/bt_unit_test.h | 3 |
4 files changed, 101 insertions, 2 deletions
diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 1407f6c..689d051 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -369,6 +369,17 @@ typedef enum { } bt_authentication_type_info_e; /** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_DEVICE_MODULE + * @brief The structure type containing the HID RC key event information. + * @since_tizen 3.0 + * + * @see bt_hid_device_send_rc_key_event() + */ +typedef struct { + unsigned short key[3]; /**< The key value - currently pressed keys : Max 3 at once */ +} bt_hid_rc_key_data_s; + +/** * @internal * @brief Check the initialzating status */ @@ -701,6 +712,28 @@ int bt_passkey_reply(char *passkey, bool authentication_reply); */ int bt_passkey_confirmation_reply(bool confirmation_reply); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Sends the RC key event data. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address device address of remote device. + * @param[in] key_data key data the need to be passed to remote device + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The HID connection must be established. + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_send_rc_key_event(const char *remote_address, + const bt_hid_rc_key_data_s *key_data); + #ifdef __cplusplus } #endif diff --git a/src/bluetooth-hid.c b/src/bluetooth-hid.c index 06a59a5..15eb31f 100644 --- a/src/bluetooth-hid.c +++ b/src/bluetooth-hid.c @@ -283,9 +283,48 @@ int bt_hid_device_send_key_event(const char *remote_address, BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(key_data); + hid_send_key_event_t send_event; - ret = bluetooth_hid_device_send_key_event(remote_address, - *(hid_send_key_event_t *)key_data); + send_event.modify = key_data->modifier; + memcpy(send_event.key, key_data->key, sizeof(send_event.key)); + + ret = bluetooth_hid_device_send_key_event(remote_address, send_event); + if (ret <= 0) { + if (ret == -1) { + /* write fail case */ + if (errno == EACCES || errno == EPERM) + set_last_result(BT_ERROR_PERMISSION_DENIED); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + set_last_result(BT_ERROR_AGAIN); + else + set_last_result(BT_ERROR_OPERATION_FAILED); + } else { + ret = _bt_get_error_code(ret); + set_last_result(ret); + } + + BT_ERR("Write failed, ret = %d", ret); + } + + return ret; +} + +#ifdef TIZEN_WEARABLE +int bt_hid_device_send_rc_key_event(const char *remote_address, + const bt_hid_rc_key_data_s *key_data) +{ + int ret; + BT_CHECK_HID_DEVICE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(key_data); + hid_send_rc_key_event_t send_event; + + send_event.btcode = 0xA1; + send_event.rep_id = 0xF7; + memcpy(send_event.key, key_data->key, sizeof(send_event.key)); + + ret = bluetooth_hid_device_send_rc_key_event(remote_address, send_event); if (ret <= 0) { if (ret == -1) { /* write fail case */ @@ -305,6 +344,7 @@ int bt_hid_device_send_key_event(const char *remote_address, return ret; } +#endif int bt_hid_device_reply_to_report(const char *remote_address, bt_hid_header_type_e header_type, diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 069fa6f..dedb641 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -763,6 +763,10 @@ tc_table_t tc_hid[] = { , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT}, {"bt_hid_device_send_key_event" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT}, +#ifdef TIZEN_WEARABLE + {"bt_hid_device_send_rc_key_event" + , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT}, +#endif {"bt_hid_device_set_data_received_cb" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB}, {"bt_hid_device_unset_data_received_cd" @@ -7349,6 +7353,25 @@ int test_input_callback(void *data) TC_PRT("returns %d\n", ret); break; } +#ifdef TIZEN_WEARABLE + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT: { + bt_hid_rc_key_data_s send_data; + /* Will send volume Up */ + unsigned short key_press[3] = {0x0007, 0x0000, 0x0000}; + unsigned short key_release[3] = {0x0000, 0x0000, 0x0000}; + + memcpy(send_data.key, key_press, sizeof(key_press)); + ret = bt_hid_device_send_rc_key_event( + remote_addr, &send_data); + TC_PRT("returns %d\n", ret); + + memcpy(send_data.key, key_release, sizeof(key_release)); + ret = bt_hid_device_send_rc_key_event( + remote_addr, &send_data); + TC_PRT("returns %d\n", ret); + break; + } +#endif case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB: { ret = bt_hid_device_set_data_received_cb( __bt_hid_device_data_received_cb, diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index 60fd18b..d83f353 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -321,6 +321,9 @@ typedef enum { BT_UNIT_TEST_FUCNTION_HID_DEVICE_DEACTIVATE, BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT, BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT, +#ifdef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT, +#endif BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB, BT_UNIT_TEST_FUNCTION_HID_DEVICE_UNSET_DATA_RECEIVED_CB, BT_UNIT_TEST_FUNCTION_IPSP_REGISTER = 1, |