BLE_HID_UART_CAPTURE¶
1 功能概述¶
此项目演示基于HID服务和串口透传服务实现用按键进行拍照、录像和调焦,同时也能通过串口透传数据给手机。用 K1 和 K2 按键可以唤醒安卓手机的相机,切换录像和拍照,切换前后摄像头,远近调焦。我们可以在相机模式下和录像模式下可以实现拍照录像功能。pan101x 芯片受限于ram资源,此工程暂不支持pan101x。
2 环境要求¶
board: `pan107x evb
uart0(option): 用来显示串口log(端口P16、P17,波特率921600,选项
8n1
)uart1: 串口透传,P24作为uart_tx,P10作为uart_rx,波特率115200
手机app
nrf connect
4 演示说明¶
在设置蓝牙界面连接
Capture pi
进行配对,通过按键KEY1唤醒手机原生相机,可以切换录像和拍照,通过按键KEY2音量减小键实现拍照和录像快捷键功能。具体操作说明可参考文档:ble_hid_selfie.mdK1和K2按键还可修改成其他功能,其他键值对应的功能如下:
键值
功能
CONSUMER_KEY_VAL_VOLUME_INCREMENT
音量加或拍照录像
CONSUMER_KEY_VAL_VOLUME_DECREMENT
音量减或拍照录像
CONSUMER_KEY_VAL_MODE_STEP
切换前后摄像头
CONSUMER_KEY_VAL_VCR_PLUS
切换拍照或录像
CONSUMER_KEY_VAL_AC_ZOOM_IN
镜头放大
CONSUMER_KEY_VAL_AC_ZOOM_OUT
镜头缩小
hog
相关GATT Service的初始化在gatt_svr.c
中:static const struct ble_gatt_svc_def gatt_svr_svcs[] = { { /* Service: Heart-rate */ .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 = gatt_svr_chr_access_hid, .flags = BLE_GATT_CHR_F_READ, }, { /* Characteristic: hids report map */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT_MAP), .access_cb = gatt_svr_chr_access_hid, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC, }, { /* Characteristic: hids inout report */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_REPORT), .access_cb = gatt_svr_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 = gatt_svr_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 = gatt_svr_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 = gatt_svr_chr_access_hid_consumer_report, .att_flags = BLE_ATT_F_READ, }, { 0 }, } }, { /* Characteristic: Body sensor location */ .uuid = BLE_UUID16_DECLARE(BT_UUID_HIDS_CTRL_POINT), .access_cb = gatt_svr_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
中通过串口透传发送命令实现和按键一样的功能,透传发送的命令如下代码:
if(send_data[2] == 0x92) { hog_send_consumer_key(CONSUMER_KEY_VAL_MODE_STEP); } else if(send_data[2] == 0x93) { hog_send_consumer_key(CONSUMER_KEY_VAL_VOLUME_DECREMENT); } else if(send_data[2] == 0x94) { hog_send_consumer_key(CONSUMER_KEY_VAL_VCR_PLUS); } else if((send_data[2] == 0xA0) && (send_data[3] == 0x00) && (send_data[4] == 0x82)) { hog_send_consumer_key(CONSUMER_KEY_VAL_AC_ZOOM_IN); } else if((send_data[2] == 0xA0) && (send_data[3] == 0x00) && (send_data[4] == 0xAA)) { hog_send_consumer_key(CONSUMER_KEY_VAL_AC_ZOOM_OUT); } else if((send_data[2] == 0xA0) && (send_data[3] == 0x00) && (send_data[4] == 0x96)) { hog_send_consumer_key(CONSUMER_KEY_VAL_REALEASED); } else if((send_data[2] == 0x80) && (send_data[3] == 0x84) && (send_data[4] == 0x02)) { hog_send_consumer_key(CONSUMER_KEY_VAL_REALEASED); }
send_data[0]和send_data[1]都为0xAA,其他串口透传命令可参考文档 ble_hid_uart_mult_roles.md