HID: Add API to send customized event 81/85781/1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 29 Aug 2016 05:36:10 +0000 (14:36 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 29 Aug 2016 05:36:10 +0000 (14:36 +0900)
Change-Id: Idb6823c7ea2b68081208f32baaf639dc000e00b7
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
include/bluetooth_private.h
src/bluetooth-hid.c
test/bt_unit_test.c

index 142b684..8f8144c 100644 (file)
@@ -633,17 +633,6 @@ 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
  */
@@ -1017,13 +1006,15 @@ int bt_passkey_confirmation_reply(bool confirmation_reply);
 
 /**
  * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE
- * @brief Sends the RC key event data.
+ * @brief Sends the custom 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
+ * @param[in] report_id  reoport id need to be passed to remote device
+ * @param[in] data  The data need to be passed to remote device
+ * @param[in] data_len  The length of the data
  * @return 0 on success, otherwise a negative error value.
  * @retval #BT_ERROR_NONE  Successful
  * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
@@ -1034,8 +1025,8 @@ int bt_passkey_confirmation_reply(bool confirmation_reply);
  * @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);
+int bt_hid_device_send_custom_event(const char *remote_address,
+               unsigned char report_id, const char *data, unsigned int data_len);
 
 #ifdef __cplusplus
 }
index 0b8a11f..c8f4bdf 100644 (file)
@@ -299,45 +299,36 @@ int bt_hid_device_send_key_event(const char *remote_address,
        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 bt_hid_device_send_custom_event(const char *remote_address,
+               unsigned char report_id, const char *data, unsigned int data_len)
 {
        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));
+       BT_CHECK_INPUT_PARAMETER(data);
 
-       ret = bluetooth_hid_device_send_rc_key_event(remote_address, send_event);
+       ret = bluetooth_hid_device_send_custom_event(remote_address,
+                               0xA1, report_id, data, data_len);
        if (ret <= 0) {
                if (ret == -1) {
                        /* write fail case */
-                       if (errno == EACCES || errno == EPERM) {
+                       if (errno == EACCES || errno == EPERM)
                                set_last_result(BT_ERROR_PERMISSION_DENIED);
-                               BT_ERR("PERMISSION_DENIED, errno = %d", errno);
-                       } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                       else if (errno == EAGAIN || errno == EWOULDBLOCK)
                                set_last_result(BT_ERROR_AGAIN);
-                               BT_ERR("BT_ERROR_AGAIN, errno = %d", errno);
-                       } else {
+                       else
                                set_last_result(BT_ERROR_OPERATION_FAILED);
-                               BT_ERR("BT_ERROR_OPERATION_FAILED, errno = %d", errno);
-                       }
                } else {
                        ret = _bt_get_error_code(ret);
                        set_last_result(ret);
-                       BT_ERR("Write failed, ret = %d", ret);
                }
+
+               BT_ERR("Write failed, ret = %d", ret);
        }
 
        return ret;
 }
-#endif
 
 int bt_hid_device_reply_to_report(const char *remote_address,
                bt_hid_header_type_e header_type,
index ac374b5..8676341 100644 (file)
@@ -773,10 +773,8 @@ 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_hid_device_send_custom_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"
@@ -3960,6 +3958,30 @@ int test_set_params(int test_id, char *param)
        }
        case BT_UNIT_TEST_TABLE_HID: {
                switch (test_id) {
+               case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT: {
+                       if (param_index == 0) {
+                               g_test_param.param_count = 1;
+                               g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
+                               param_type = BT_UNIT_TEST_PARAM_TYPE_INT;
+                       }
+
+                       if (param_index > 0) {
+                               g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1);
+                               strcpy(g_test_param.params[param_index - 1], param);
+                       }
+
+                       if (param_index == g_test_param.param_count) {
+                               need_to_set_params = false;
+                               test_input_callback((void *)test_id);
+                               param_index = 0;
+                               return 0;
+                       }
+
+                       TC_PRT("Select TV control mode (1 : Vol Up, 2 : Vol Down, 3 : CH Up, 4 : CH Down) : ");
+                       param_index++;
+
+                       break;
+               }
                default:
                        TC_PRT("There is no param to set\n");
                        need_to_set_params = false;
@@ -7470,25 +7492,36 @@ 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};
+                       unsigned char report_id = 0xF7;
+                       char pressed_data[6]    = {0x07, 0x00, 0x00, 0x00, 0x00, 0x00};
+                       char released_data[6]   = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+                       static int mode = 1;
 
-                       memcpy(send_data.key, key_press, sizeof(key_press));
-                       ret = bt_hid_device_send_rc_key_event(
-                                       remote_addr, &send_data);
+                       if (g_test_param.param_count > 0) {
+                               mode = atoi(g_test_param.params[0]);
+                               __bt_free_test_param(&g_test_param);
+                       }
+
+                       if (mode == 1)
+                               pressed_data[0] = 0x07;  /* Vol up */
+                       else if (mode == 2)
+                               pressed_data[0] = 0x0B; /* Vol down */
+                       else if (mode == 3)
+                               pressed_data[0] = 0x12; /* CH up */
+                       else if (mode == 4)
+                               pressed_data[0] = 0x10; /* CH down */
+
+                       ret = bt_hid_device_send_custom_event(remote_addr,
+                                       report_id, pressed_data, 6);
                        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);
+                       ret = bt_hid_device_send_custom_event(remote_addr,
+                                       report_id, released_data, 6);
                        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,