From: liangzhenying <867174124@qq.com> Date: Tue, 3 Sep 2024 08:01:50 +0000 (+0800) Subject: 泰凌微获取到usb模式dongle连接成功后才会给app回调 X-Git-Tag: 千寻适配d9~16 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=62b0bde9dc29ea2d52e3d67921ead45bf1928922;p=mirrors%2FMouseSdk-MacOS.git 泰凌微获取到usb模式dongle连接成功后才会给app回调 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index 1f83a0e..39f9e81 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -439,7 +439,7 @@ } self.isAuthing = true; __weak typeof(self) ws = self; - [self startAuthentication:AiMouseAuthType_none finished:^(AiMouseAuthState state) { + [self startAuthentication:AiMouseAuthType_BeiKeZhiHui finished:^(AiMouseAuthState state) { ws.isAuthing = false; [ws showLog:state == AiMouseAuthState_Success? @"鉴权成功":@"鉴权失败"]; if(ws.delegate) [ws.delegate aiMouseAuthenticationResult:state]; diff --git a/MouseSdk/AiMouseSdk/Manager/HidManager.m b/MouseSdk/AiMouseSdk/Manager/HidManager.m index 9875582..9251584 100644 --- a/MouseSdk/AiMouseSdk/Manager/HidManager.m +++ b/MouseSdk/AiMouseSdk/Manager/HidManager.m @@ -64,10 +64,7 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH return; }else{ [[HidManager shared] showLog:@"打开设备成功!"]; -// [HidManager shared].connectStateCallBack(true) ; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [HidManager shared].connectStateCallBack(true); - }); + [HidManager shared].connectStateCallBack(true) ; } // CFRetain([HidManager shared].deviceInfoCha); // IOHIDDeviceScheduleWithRunLoop([HidManager shared].deviceInfoCha, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m index c7a8526..4e2ee8c 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m @@ -29,6 +29,9 @@ @property (nonatomic, strong) TlwAudioManager *audioManager; @property (nonatomic, strong) AiRecordManager *recordManager; +@property (nonatomic,strong)void (^dongleStateCallBack)(BOOL success); +@property (nonatomic,assign)NSInteger dongleTimes; + @property (nonatomic,strong)void (^openRecordCallBack)(BOOL isSuccess,NSError *error); @property (nonatomic,strong)void (^closeRecordCallBaack)(BOOL isSuccess,NSError *error); @property (nonatomic,strong)void (^setDpiCallBack)(BOOL isSuccess,NSError *error); @@ -92,17 +95,6 @@ [mData appendBytes:&tail length:1]; [self sendToDevice:mData]; } -- (void)sendDongleCmd{ - uint8_t cmd = 0x01; - uint8_t len = 0x00; - uint8_t tail = 0xEF; - NSMutableData *mData = NSMutableData.data; - [mData appendData:[self getHidHeader]]; - [mData appendBytes:&cmd length:1]; - [mData appendBytes:&len length:1]; - [mData appendBytes:&tail length:1]; - [self sendToDevice:mData]; -} #pragma mark - pub Api - (void)setLogLevel:(TlwMouseLogLevel)level{ @@ -114,16 +106,23 @@ } - (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted{ + [NSObject cancelPreviousPerformRequestsWithTarget:self]; if(isConneted ){ _connected = true; _connectType = type; [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"]; - [self TlwConnectManager:nil connectStateDidChange:true]; + if (type == AiMouseConnectType_hid ) { [self.recordManager checkPermissions]; - [self sendOpenCmd]; - [self sendDongleCmd]; +// [self sendOpenCmd]; + [self checkDongleState]; } + else{ + [self TlwConnectManager:nil connectStateDidChange:true]; + } +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// [HidManager shared].connectStateCallBack(true); +// }); } else{ [self stopRecord]; @@ -231,8 +230,6 @@ [mData appendBytes:&value length:1]; [self sendToDevice:mData]; } - - } - (void)getDeviceInfo:(void (^)(TlwDeviceInfo *deviceInfo,NSError *error))finished{ if(self.connectType == AiMouseConnectType_hid){ @@ -291,9 +288,6 @@ - (void)getFullDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ - if (self.getFullInfoCallBack) { - return; - } self.getFullInfoCallBack = finished; self.questTimes = 0; [self checkFullInfoAction]; @@ -302,6 +296,7 @@ - (void)checkFullInfoAction{ self.questTimes++; if (self.questTimes > 3) { + self.getFullInfoCallBack(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); [self switchConnect:AiMouseConnectType_hid isConnected:false ]; return; } @@ -347,6 +342,41 @@ [self performSelector:@selector(checkFullInfoAction) withObject:nil afterDelay:1]; } +#pragma mark - check dongle +- (void)checkDongleState{ + self.dongleTimes = 0; + __weak typeof(self) ws = self; + [self checkDongleStateAction:^(BOOL success) { + ws.dongleStateCallBack = nil; + if (success) { + [ws TlwConnectManager:nil connectStateDidChange:true]; + } + }]; +} +- (void)checkDongleStateAction:(void (^)(BOOL success))finished{ + self.dongleStateCallBack = finished; + [self performSelector:@selector(sendDongleCmd) withObject:nil afterDelay:1]; +} +- (void)sendDongleCmd{ + self.dongleTimes++; + if ( self.dongleStateCallBack == nil) { + return; + } + if (self.dongleTimes > 2) { + [self TlwConnectManager:nil connectStateDidChange:false]; + return; + } + uint8_t cmd = 0x0D; + uint8_t len = 0x00; + uint8_t tail = 0xEF; + NSMutableData *mData = NSMutableData.data; + [mData appendData:[self getHidHeader]]; + [mData appendBytes:&cmd length:1]; + [mData appendBytes:&len length:1]; + [mData appendBytes:&tail length:1]; + [self sendToDevice:mData]; + [self performSelector:@selector(sendDongleCmd) withObject:nil afterDelay:1]; +} #pragma mark - ble - (void)bleReceiveAiData:(NSData *)data{ [self.audioManager receiveData:data]; @@ -534,6 +564,7 @@ [[data subdataWithRange:NSMakeRange(9, 1)] getBytes:&state length:1]; [self showLog:[NSString stringWithFormat:@"dongle version = %d,bind = %d",version,state]]; + if(self.dongleStateCallBack)self.dongleStateCallBack(state == 1); break; } case 0x9f: @@ -637,7 +668,7 @@ } } -#pragma mark - TlwConnectManagerDelegate +#pragma mark - other -(void)TlwConnectManager:(NSString *)manager connectStateDidChange:(BOOL)connected{ _connected = connected; if([self.delegate respondsToSelector:@selector(tlwMouseConnectStateDidChange:)]) [self.delegate tlwMouseConnectStateDidChange:connected]; diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index 31d80b2..06271af 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ