if (ws.aiMouseConnectStateDidChangeCallBack) {
ws.aiMouseConnectStateDidChangeCallBack(AiMouseConnectType_hid,connected);
}
-
};
self.hid.receiveInfoDataCallBack = ^(NSData *data) {
[[TlwMouse shared] sendDeviceDataToSdk:data];
// 连接状态改变
- (void)tlwMouseConnectStateDidChange:(BOOL)connected{
- [self showLog:[NSString stringWithFormat:@"设备连接状态返回: %hhd",connected]];
+ [self showLog:@"连接结果回调"];
+ [self showLog:[NSString stringWithFormat:@"设备连接状态返回: %@",@(connected)]];
+ [self showLog:@"准备连接回调"];
if (self.aiMouseConnectStateDidChangeCallBack) {
- self.aiMouseConnectStateDidChangeCallBack(self.getCurrentConnectType.intValue,connected);
+ [self showLog:@"连接回调"];
+ self.aiMouseConnectStateDidChangeCallBack([TlwMouse shared].connectType == AiMouseConnectType_bluetooth ? 0:1,connected);
+ [self showLog:@"连接回调结束"];
}
+ [self showLog:@"准备鉴权回调"];
if (connected == true) {
- self.authCallBack(true);
+ [self showLog:@"鉴权回调"];
}
+ if(self.authCallBack && connected)self.authCallBack(connected);
+ [self showLog:@"鉴权回调结束"];
}
- (void)showLog:(NSString *)log{
#pragma mark - Hid CallBack
/// 匹配到设备回调
-//static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
-void hidAppearDevice(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef){
+static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
[HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
[[HidManager shared] showLog:([NSString stringWithFormat:@"发现设备 %@",inIOHIDDeviceRef])];
//注册消息回调
unsigned char InputBuffer[64];
- IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
+ IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), &hidReceiveData, NULL);
IOReturn result = IOHIDDeviceOpen([HidManager shared].deviceInfoCha, kIOHIDOptionsTypeNone);
if (result != kIOReturnSuccess) {
}
/// 设备移除回调
-void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
+static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
[[HidManager shared] showLog:[NSString stringWithFormat:@"拔出设备 %@ ",inIOHIDDeviceRef]];
[HidManager shared].deviceInfoCha = nil;
}
- void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){
+static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){
// [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理前 %@",[[HidManager shared] dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]];
if (report[0] == 0x01 || report[0] == 0x02) {
//鼠标键盘活动事件
[dict setValue:[NSNumber numberWithLong:vendorID] forKey:[NSString stringWithCString:kIOHIDVendorIDKey encoding:NSUTF8StringEncoding]];
IOHIDManagerSetDeviceMatching(self.hidManager, (__bridge CFMutableDictionaryRef)dict);
//设置匹配到设备回调
- IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, hidAppearDevice, NULL);
+ IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, &hidAppearDevice, NULL);
//设置移除设备回调
IOHIDManagerRegisterDeviceRemovalCallback(self.hidManager, &hidDisAppearDevice, NULL);
}