#endif
#define LOG_TAG "HID_KEYBOARD"
+#define INIT_BOND 0
+
/**
* Variables
**/
static bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
static char remote_addr[18] = "F6:FB:8F:D8:C8:7C";
static bool address_input = false;
+#if INIT_BOND
static bool scanning = false;
static bool setup_in_progress = false;
static GSList *le_scan_list;
static bool g_wait_flag;
static int g_wait_count;
+#endif
static bool device_bonded = false;
static bool hid_connected = false;
#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
#define HID_PRT(format, args...) PRT(format"\n", ##args)
+#if INIT_BOND
#define WAIT_FOR_SYNC {\
g_wait_flag = true;\
g_wait_count = 0;\
g_wait_count++;\
}\
}
+#endif
typedef struct {
const char *tc_name;
typedef enum {
BT_HID_DEVICE_SET_ADDRESS = 1,
+#if INIT_BOND
BT_HID_DEVICE_TEST_SETUP,
+#endif
BT_HID_DEVICE_TEST_VOLUME_UP,
BT_HID_DEVICE_TEST_VOLUME_DOWN,
BT_HID_DEVICE_TEST_CHANNEL_UP,
BT_HID_DEVICE_TEST_DISCONNECT_HID,
BT_HID_DEVICE_TEST_CONNECT_AUDIO,
BT_HID_DEVICE_TEST_DISCONNECT_AUDIO,
+#if INIT_BOND
BT_HID_DEVICE_TEST_SEARCH,
BT_HID_DEVICE_TEST_STOP_SEARCH,
+#endif
BT_HID_DEVICE_TEST_FINISH = 0xFF,
} bt_hid_test_type_e;
tc_table_t tc_hid_device[] = {
{"SET ADDRESS"
, BT_HID_DEVICE_SET_ADDRESS},
+#if INIT_BOND
{"Initial Setup (Bond & Connects)"
, BT_HID_DEVICE_TEST_SETUP},
+#endif
{"Volume Up"
, BT_HID_DEVICE_TEST_VOLUME_UP},
{"Volume Down"
, BT_HID_DEVICE_TEST_CHANNEL_UP},
{"Channel Down"
, BT_HID_DEVICE_TEST_CHANNEL_DOWN},
- {"AUDIO Connect only"
- , BT_HID_DEVICE_TEST_CONNECT_AUDIO},
- {"AUDIO Disconnect only"
- , BT_HID_DEVICE_TEST_DISCONNECT_AUDIO},
{"HID Connect only"
, BT_HID_DEVICE_TEST_CONNECT_HID},
{"HID Disconnect only"
, BT_HID_DEVICE_TEST_DISCONNECT_HID},
+ {"AUDIO Connect only"
+ , BT_HID_DEVICE_TEST_CONNECT_AUDIO},
+ {"AUDIO Disconnect only"
+ , BT_HID_DEVICE_TEST_DISCONNECT_AUDIO},
+#if INIT_BOND
{"Search TV"
, BT_HID_DEVICE_TEST_SEARCH},
{"Stop to search"
, BT_HID_DEVICE_TEST_STOP_SEARCH},
+#endif
{"Finish"
, BT_HID_DEVICE_TEST_FINISH},
{NULL, 0x0000},
return FALSE;
}
+static gboolean __bt_audio_connect_cb(gpointer user_data)
+{
+ int ret;
+
+ if (audio_connected == true)
+ return FALSE;
+
+ HID_PRT("Try to connect audio..");
+ ret = bt_audio_connect(remote_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK);
+ HID_PRT("returns %s", __bt_get_error_message(ret));
+
+ return TRUE;
+}
+
static void __bt_hid_device_connection_state_changed_cb(int result,
bool connected, const char *remote_address, void *user_data)
{
HID_PRT("Remote Address: %s", remote_address);
HID_PRT("Connected [%d]", connected);
+#if INIT_BOND
g_wait_flag = false;
+#endif
if (connected == true && result == BT_ERROR_NONE) {
g_strlcpy(remote_addr, remote_address, 18);
hid_connected = true;
+
+ /* Try to connect Audio */
+ if (audio_connected == false)
+ g_timeout_add(2000, __bt_audio_connect_cb, NULL);
} else {
hid_connected = false;
}
HID_PRT("address [%s]", remote_address);
HID_PRT("type [%d]", type);
+#if INIT_BOND
g_wait_flag = false;
+#endif
if (connected == true && result == BT_ERROR_NONE) {
g_strlcpy(remote_addr, remote_address, 18);
HID_PRT("result: %s", __bt_get_error_message(result));
}
+#if INIT_BOND
g_wait_flag = false;
+#endif
}
static void __bt_state_changed_impl(int result,
g_main_loop_quit(g_mainloop);
}
+#if INIT_BOND
gint __bt_compare_address(gpointer *a, gpointer *b)
{
bt_adapter_le_device_scan_result_info_s *info = (bt_adapter_le_device_scan_result_info_s *)a;
if (ret == BT_ERROR_NONE)
scanning = true;
}
+#else
+static bool __bt_adapter_bonded_device_cb(bt_device_info_s *device_info, void *user_data)
+{
+ if (device_info != NULL) {
+ if (g_strrstr(device_info->remote_name, "[TV]")) {
+ HID_PRT("TV is boned : %s [%s]", device_info->remote_name, device_info->remote_address);
+ g_strlcpy(remote_addr, device_info->remote_address, 18);
+ return false;
+ }
+ }
+
+ return true;
+}
+#endif
static gboolean __bt_start_service(gpointer user_data)
{
ret = bt_audio_initialize();
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, 0);
+
+ ret = bt_adapter_set_name("Tizen Keyboard");
+
ret = bt_audio_select_role(BT_A2DP_SINK);
ret = bt_device_set_bond_created_cb(__bt_device_bond_created_cb, NULL);
HID_PRT("A2DP connected devices returns %s\n", __bt_get_error_message(ret));
if (hid_connected == false && audio_connected == false) {
+#if INIT_BOND
HID_PRT("No TV is connected, try to search...");
+
__bt_find_remote_tv();
+#else
+ ret = bt_adapter_foreach_bonded_device(__bt_adapter_bonded_device_cb, NULL);
+#endif
}
-
return FALSE;
}
+#if INIT_BOND
static void __bt_stop_setup(void)
{
setup_in_progress = false;
return ret;
}
-
+#endif
static void __bt_tc_usage_print(void)
{
HID_PRT("\n");
}
+static int key_code = 0x01;
+
static int __bt_test_input_callback(void *data)
{
int ret = 0;
int test_id = (int)data;
- GSList *l = NULL;
+ bt_hid_key_data_s send_data;
+ char pressedkey[8] = { 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ char pressedkey1[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+#if INIT_BOND
int cnt = 0;
+ GSList *l = NULL;
bt_adapter_le_device_scan_result_info_s *info;
- 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};
if (setup_in_progress == true &&
test_id != BT_HID_DEVICE_TEST_SETUP &&
HID_PRT("Wait to finish setup");
return 0;
}
+#endif
switch (test_id) {
case BT_HID_DEVICE_SET_ADDRESS:
address_input = true;
break;
+#if INIT_BOND
case BT_HID_DEVICE_TEST_SETUP:
if (setup_in_progress == true) {
HID_PRT("Stop the initial setup");
}
}
break;
+#endif
case BT_HID_DEVICE_TEST_VOLUME_UP:
- pressed_data[0] = 0x07; /* Vol up */
+ pressedkey[0] = 0x43; /* Vol up */
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, pressed_data, 6);
+ memcpy(send_data.key, pressedkey, 8);
+ send_data.modifier = 0;
+
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
HID_PRT("returns %d\n", ret);
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, released_data, 6);
+ memcpy(send_data.key, pressedkey1, 8);
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
+
break;
case BT_HID_DEVICE_TEST_VOLUME_DOWN:
- pressed_data[0] = 0x0B; /* Vol down */
+ pressedkey[0] = 0x42; /* Vol down */
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, pressed_data, 6);
+ memcpy(send_data.key, pressedkey, 8);
+ send_data.modifier = 0;
+
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
HID_PRT("returns %d\n", ret);
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, released_data, 6);
+ memcpy(send_data.key, pressedkey1, 8);
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
+
break;
case BT_HID_DEVICE_TEST_CHANNEL_UP:
- pressed_data[0] = 0x12; /* CH up */
+ pressedkey[0] = 0x45; /* CH up */
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, pressed_data, 6);
+ HID_PRT("key_code %d", key_code);
+
+ memcpy(send_data.key, pressedkey, 8);
+ send_data.modifier = 0;
+
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
HID_PRT("returns %d\n", ret);
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, released_data, 6);
+ memcpy(send_data.key, pressedkey1, 8);
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
+
break;
case BT_HID_DEVICE_TEST_CHANNEL_DOWN:
- pressed_data[0] = 0x10; /* CH down */
+ pressedkey[0] = 0x44; /* CH down */
+
+ memcpy(send_data.key, pressedkey, 8);
+ send_data.modifier = 0;
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, pressed_data, 6);
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
HID_PRT("returns %d\n", ret);
- ret = bt_hid_device_send_custom_event(remote_addr,
- report_id, released_data, 6);
+ memcpy(send_data.key, pressedkey1, 8);
+ ret = bt_hid_device_send_key_event(remote_addr, &send_data);
+
break;
case BT_HID_DEVICE_TEST_CONNECT_AUDIO:
ret = bt_audio_connect(remote_addr, BT_AUDIO_PROFILE_TYPE_A2DP_SINK);
ret = bt_hid_device_disconnect(remote_addr);
HID_PRT("returns %s", __bt_get_error_message(ret));
break;
+#if INIT_BOND
case BT_HID_DEVICE_TEST_SEARCH:
__bt_find_remote_tv();
break;
le_scan_list = NULL;
break;
+#endif
case BT_HID_DEVICE_TEST_FINISH:
HID_PRT("Finished");
g_main_loop_quit(g_mainloop);
address_input = false;
}
+#if INIT_BOND
if (scanning == true) {
test_id = BT_HID_DEVICE_TEST_STOP_SEARCH;
#ifdef ARCH64
#endif
return TRUE;
}
+#endif
test_id = atoi(buf);