BLE HID Selfie¶
1 功能概述¶
此项目演示基于HID服务的自拍服务,用 K1 和 K2 模拟的音量键,我们可以在相机模式下可以实现拍照功能。
2 环境要求¶
board:
pan107x evb
uart(option): 用来显示串口log(波特率921600,选项
8n1
)手机app
nrf connect
4 演示说明¶
在设置蓝牙界面连接
PAN Selfie
进行配对,通过按键KEY1和KEY2模拟音量增大和减小,同时利用音量增大键和减小键实现拍照快捷键功能。Try to load HW calibration data.. DONE. - Chip Info : 0x61 - Chip CP Version : 255 - Chip FT Version : 7 - Chip MAC Address : E11000014DE5 - Chip UID : B90801465454455354 - Chip Flash UID : 4250315A3538380B01FD8B435603EF78 - Chip Flash Size : 512 KB [I] app started [I] ble stack init start... [I] Spark Controller Init Start. [I] BLE Heap size:5636 B, remain:64 B [I] Spark Controller Init OK. [I] ble host init ok -> ble thread start... [I] registered service 0x1800 with handle=1 [I] registering characteristic 0x2a00 with def_handle=2 val_handle=3 [I] registering characteristic 0x2a01 with def_handle=4 val_handle=5 [I] registered service 0x1801 with handle=6 [I] registering characteristic 0x2a05 with def_handle=7 val_handle=8 [I] registered service 0x1812 with handle=10 [I] registering characteristic 0x2a4a with def_handle=11 val_handle=12 [I] registering characteristic 0x2a4b with def_handle=13 val_handle=14 [I] registering characteristic 0x2a4d with def_handle=15 val_handle=16 [I] registering descriptor 0x2908 with handle=18 [I] registering characteristic 0x2a4d with def_handle=19 val_handle=20 [I] registering descriptor 0x2908 with handle=22 [I] registering characteristic 0x2a4d with def_handle=23 val_handle=24 [I] registering descriptor 0x2908 with handle=26 [I] registering characteristic 0x2a4c with def_handle=27 val_handle=28 [W] Device Id Address: E1 10 00 01 4D E5 [I] BLE adv start... [I] connection established; status=0 [I] -conn_intvl:45000 us -latency:0 -to:5000 ms [I] mtu update event; conn_handle=0 mtu=247 [E] ..\..\..\..\host\pan_spark_glue.c 389: Host transport alloc HCI Evt buffer failed [I] encryption change event; status=0 [I] handle=0 our_ota_addr_type=0 our_ota_addr=e1 10 00 01 4d e5 [I] our_id_addr_type=0 our_id_addr=e1 10 00 01 4d e5 [I] peer_ota_addr_type=1 peer_ota_addr=9c 25 ce b1 e7 7f [I] peer_id_addr_type=1 peer_id_addr=9c 25 ce b1 e7 7f [I] conn_itvl=36 conn_latency=0 supervision_timeout=500 encrypted=1 authenticated=0 bonded=1 [I] [I] conn upd cmpl: conn_handle:0, itvl:7500 us, latency:0, to:5000 ms [I] subscribe event; cur_notify=0, val_handle=0 [I] conn upd cmpl: conn_handle:0, itvl:45000 us, latency:0, to:5000 ms [I] subscribe event; cur_notify=1, val_handle=0 [I] subscribe event; cur_notify=1, val_handle=0 [I] subscribe event; cur_notify=1, val_handle=0 [I] P06 occurred (KEY1音量增大) [I] notify ok [I] notify ok [I] key_vol_up pressed [I] P12 occurred (KEY2音量减小) [I] notify ok [I] key_vol_down pressed [I] notify ok
hid
相关的初始化在profiles目录下的hid.c
中:
static const struct ble_gatt_svc_def ble_svc_hid_defs[] = { { /* Service: HID */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS), .characteristics = (struct ble_gatt_chr_def[]) { { /* Characteristic: hids information */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_INFO), .access_cb = ble_svc_chr_access_hid, .flags = BLE_GATT_CHR_F_READ, }, { /* Characteristic: hids report map */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_MAP), .access_cb = ble_svc_chr_access_hid, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC, }, { /* Characteristic: hids input report */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT), .access_cb = ble_svc_chr_access_hid_input_report, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, .val_handle = &hid_input_handle, .descriptors = (struct ble_gatt_dsc_def[]) { { .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_REF), .access_cb = ble_svc_chr_access_hid_input_report, .att_flags = BLE_ATT_F_READ, }, { 0 }, } }, { /* Characteristic: hids consumer report */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT), .access_cb = ble_svc_chr_access_hid_consumer_report, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, .val_handle = &hid_consumer_input_handle, .descriptors = (struct ble_gatt_dsc_def[]) { { .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_REF), .access_cb = ble_svc_chr_access_hid_consumer_report, .att_flags = BLE_ATT_F_READ, }, { 0 }, } }, { /* Characteristic: hids consumer report */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT), .access_cb = gatt_svr_chr_access_hid_mouse_report, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, .val_handle = &hid_mouse_input_handle, .descriptors = (struct ble_gatt_dsc_def[]) { { .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_REF), .access_cb = gatt_svr_chr_access_hid_mouse_report, .att_flags = BLE_ATT_F_READ, }, { 0 }, } }, { /* Characteristic: hidS control point */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_CTRL_POINT), .access_cb = ble_svc_chr_access_hid, .flags = BLE_GATT_CHR_F_WRITE_NO_RSP, }, { 0, /* No more characteristics in this service */ }, } }, { 0, /* No more services. */ }, };
相关hog硬件初始化和处理以及发送消息的函数在
hog.c
中