|
本帖最后由 littleshrimp 于 2018-4-25 22:42 编辑
打开keyboard.c
修改reportDesc内容
- uint8_t reportDesc[] = {
- 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
- 0x09, 0x01, // USAGE (Consumer Control)
- 0xa1, 0x01, // COLLECTION (Application)
- 0x15, 0x00, // LOGICAL_MINIMUM (0)
- 0x25, 0x01, // LOGICAL_MAXIMUM (1)
- 0x09, 0xe9, // USAGE (Volume Up)
- 0x09, 0xea, // USAGE (Volume Down)
- 0x09, 0x30, // USAGE (Power)
- 0x75, 0x01, // REPORT_SIZE (1)
- 0x95, 0x02, // REPORT_COUNT (2)
- 0x81, 0x06, // INPUT (Data,Var,Rel)
- 0x09, 0xe2, // USAGE (Mute)
- 0x95, 0x01, // REPORT_COUNT (1)
- 0x81, 0x06, // INPUT (Data,Var,Rel)
- 0x95, 0x05, // REPORT_COUNT (5)
- 0x81, 0x07, // INPUT (Cnst,Var,Rel)
- 0xc0 // END_COLLECTION
- };
复制代码
找到Configure_HidPeripheral函数添加Button初始化内容
- /* Button Init */
- SdkEvalPushButtonInit(BUTTON_1);
复制代码
修改DeviceInputData函数里的内容
- uint8_t buttonState = 0;
- void DeviceInputData(void)
- {
- uint8_t ret, nmbTimes, keys[8]={0,0,0,0,0,0,0,0};
- if(SdkEvalPushButtonGetState(BUTTON_2) == RESET)
- {
- if(buttonState == 0)
- {
- buttonState = 1;
- PRINTF("button1 pressed");
- }
- }
- else
- {
- buttonState = 0;
- }
- if(buttonState == 1)
- {
- if (hidDeviceStatus() & HID_DEVICE_READY_TO_NOTIFY) {
- SdkEvalLedOn(LED3);
- if(buttonState == 1)
- {
- buttonState = 2;
- keys[0] = 1;
- }
- else
- {
- keys[0] = 0;
- }
- ret = hidSendReport(0, INPUT_REPORT, sizeof(keys), keys);
- if (ret != BLE_STATUS_SUCCESS)
- PRINTF("Error during send the report %02x\n", ret);
- keys[0] = 0;
- nmbTimes = 0;
- do {
- ret = hidSendReport(0, INPUT_REPORT, sizeof(keys), keys);
- nmbTimes++;
- } while ((ret != BLE_STATUS_SUCCESS) && (nmbTimes < 200));
- hidSetNotificationPending(TRUE);
- } else {
- SdkEvalLedOff(LED3);
- }
- }
- }
复制代码 工程文件:bluenrg-1自拍杆.rar
|
|