优化代码
authorliangzhenying <867174124@qq.com>
Mon, 26 Aug 2024 12:07:04 +0000 (20:07 +0800)
committerliangzhenying <867174124@qq.com>
Mon, 26 Aug 2024 12:07:04 +0000 (20:07 +0800)
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk/Ble/DeviceManger.m
MouseSdk/MouseSdk/Ble/HidManager.m

index a4fbdf8..355ba17 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index 1249629..4689003 100644 (file)
@@ -67,7 +67,6 @@
         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{
index 05a19f5..e20f681 100644 (file)
 
 #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);
 }