From: liangzhenying <867174124@qq.com> Date: Mon, 26 Aug 2024 12:07:04 +0000 (+0800) Subject: 优化代码 X-Git-Tag: 千寻适配d9~38 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=b4d466a45f73001bae8602f8b69f41d60995624c;p=mirrors%2FMouseSdk-MacOS.git 优化代码 --- diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index a4fbdf8..355ba17 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk/Ble/DeviceManger.m b/MouseSdk/MouseSdk/Ble/DeviceManger.m index 1249629..4689003 100644 --- a/MouseSdk/MouseSdk/Ble/DeviceManger.m +++ b/MouseSdk/MouseSdk/Ble/DeviceManger.m @@ -67,7 +67,6 @@ if (ws.aiMouseConnectStateDidChangeCallBack) { ws.aiMouseConnectStateDidChangeCallBack(AiMouseConnectType_hid,connected); } - }; self.hid.receiveInfoDataCallBack = ^(NSData *data) { [[TlwMouse shared] sendDeviceDataToSdk:data]; @@ -341,14 +340,21 @@ // 连接状态改变 - (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{ diff --git a/MouseSdk/MouseSdk/Ble/HidManager.m b/MouseSdk/MouseSdk/Ble/HidManager.m index 05a19f5..e20f681 100644 --- a/MouseSdk/MouseSdk/Ble/HidManager.m +++ b/MouseSdk/MouseSdk/Ble/HidManager.m @@ -35,14 +35,13 @@ #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) { @@ -56,7 +55,7 @@ void hidAppearDevice(void *inContext, IOReturn inResult, void *inSender, IOHIDDe } /// 设备移除回调 -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; @@ -64,7 +63,7 @@ void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDe } - 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) { //鼠标键盘活动事件 @@ -112,7 +111,7 @@ void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDe [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); }