From: liangzhenying <867174124@qq.com> Date: Fri, 13 Sep 2024 07:04:42 +0000 (+0800) Subject: 兼容一键上网版 X-Git-Tag: 千寻适配d9~10 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7cb6d05ef9759585cbc8cc9d4b85a351dac4843e;p=mirrors%2FMouseSdk-MacOS.git 兼容一键上网版 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj index 3c23d96..484388d 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj @@ -401,6 +401,8 @@ 18AD83262BFAE8B9009BDE3B /* AiDeviceInfoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AD83242BFAE8B9009BDE3B /* AiDeviceInfoManager.m */; }; 18AD83292BFB22DE009BDE3B /* AiSender.h in Headers */ = {isa = PBXBuildFile; fileRef = 18AD83272BFB22DE009BDE3B /* AiSender.h */; }; 18AD832A2BFB22DE009BDE3B /* AiSender.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AD83282BFB22DE009BDE3B /* AiSender.m */; }; + 18D57A022C917385003D5714 /* NMouseSdk.h in Headers */ = {isa = PBXBuildFile; fileRef = 18D57A002C917385003D5714 /* NMouseSdk.h */; }; + 18D57A032C917385003D5714 /* NMouseSdk.m in Sources */ = {isa = PBXBuildFile; fileRef = 18D57A012C917385003D5714 /* NMouseSdk.m */; }; 18EF7AF92C7603E800AC5223 /* adpcm.h in Headers */ = {isa = PBXBuildFile; fileRef = 18EF7AEA2C7603E800AC5223 /* adpcm.h */; }; 18EF7AFA2C7603E800AC5223 /* TlwMouseSdk.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EF7AEB2C7603E800AC5223 /* TlwMouseSdk.m */; }; 18EF7AFB2C7603E800AC5223 /* TlwTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EF7AEC2C7603E800AC5223 /* TlwTools.m */; }; @@ -571,7 +573,7 @@ 180E7D102BD8FF11008558E8 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; 180E7D122BD8FF3A008558E8 /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = usr/lib/libiconv.tbd; sourceTree = SDKROOT; }; 180E7D142BD8FF5C008558E8 /* liblzma.5.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = liblzma.5.tbd; path = usr/lib/liblzma.5.tbd; sourceTree = SDKROOT; }; - 181272BA2C81BF460046CCF2 /* libAiMouseSdk copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libAiMouseSdk copy.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 181272BA2C81BF460046CCF2 /* libAiMouseSdk copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libAiMouseSdk copy.a"; path = "/Users/apple/Desktop/code/MouseSdk-MacOS/MouseSdk/AiMouseSdk/build/Debug/libAiMouseSdk copy.a"; sourceTree = ""; }; 181CE5BF2C6EED9900EF8D07 /* AiAliAuthManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AiAliAuthManager.h; sourceTree = ""; }; 181CE5C02C6EED9900EF8D07 /* AiAliAuthManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiAliAuthManager.m; sourceTree = ""; }; 184A70F42BDA4C040025A332 /* AFSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFSecurityPolicy.h; sourceTree = ""; }; @@ -610,6 +612,8 @@ 18AD83242BFAE8B9009BDE3B /* AiDeviceInfoManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiDeviceInfoManager.m; sourceTree = ""; }; 18AD83272BFB22DE009BDE3B /* AiSender.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiSender.h; sourceTree = ""; }; 18AD83282BFB22DE009BDE3B /* AiSender.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiSender.m; sourceTree = ""; }; + 18D57A002C917385003D5714 /* NMouseSdk.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NMouseSdk.h; sourceTree = ""; }; + 18D57A012C917385003D5714 /* NMouseSdk.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NMouseSdk.m; sourceTree = ""; }; 18EF7AEA2C7603E800AC5223 /* adpcm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = adpcm.h; sourceTree = ""; }; 18EF7AEB2C7603E800AC5223 /* TlwMouseSdk.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TlwMouseSdk.m; sourceTree = ""; }; 18EF7AEC2C7603E800AC5223 /* TlwTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TlwTools.m; sourceTree = ""; }; @@ -671,12 +675,12 @@ 180E7A9D2BD7BB12008558E8 = { isa = PBXGroup; children = ( + 18D579FF2C91733E003D5714 /* NMouseSdk */, 18862A172C8064E300D3564D /* Manager */, 18EF7AE72C7603E800AC5223 /* TlwMouseSdk */, 180E7AA82BD7BB12008558E8 /* AiMouseSdk */, 180E7AA72BD7BB12008558E8 /* Products */, 180E7D092BD8FEB2008558E8 /* Frameworks */, - 181272BA2C81BF460046CCF2 /* libAiMouseSdk copy.a */, ); sourceTree = ""; }; @@ -991,6 +995,15 @@ path = Manager; sourceTree = ""; }; + 18D579FF2C91733E003D5714 /* NMouseSdk */ = { + isa = PBXGroup; + children = ( + 18D57A002C917385003D5714 /* NMouseSdk.h */, + 18D57A012C917385003D5714 /* NMouseSdk.m */, + ); + path = NMouseSdk; + sourceTree = ""; + }; 18EF7AE72C7603E800AC5223 /* TlwMouseSdk */ = { isa = PBXGroup; children = ( @@ -1041,6 +1054,7 @@ 180E7CC02BD8FC4E008558E8 /* mastering_display_metadata.h in Headers */, 180E7CA02BD8FC4E008558E8 /* crc.h in Headers */, 180E7C8A2BD8FC4E008558E8 /* hwcontext_cuda.h in Headers */, + 18D57A022C917385003D5714 /* NMouseSdk.h in Headers */, 180E7CA62BD8FC4E008558E8 /* hwcontext_vaapi.h in Headers */, 180E7CAB2BD8FC4E008558E8 /* tree.h in Headers */, 180E7C902BD8FC4E008558E8 /* hwcontext_mediacodec.h in Headers */, @@ -1442,6 +1456,7 @@ 180E7BDF2BD7BD84008558E8 /* AiMouseConfig.m in Sources */, 18EF7AFC2C7603E800AC5223 /* TlwConnectManager.m in Sources */, 181CE5C22C6EED9900EF8D07 /* AiAliAuthManager.m in Sources */, + 18D57A032C917385003D5714 /* NMouseSdk.m in Sources */, 184A710D2BDA4C050025A332 /* AFSecurityPolicy.m in Sources */, 18862A272C8064E300D3564D /* DeviceManger.m in Sources */, 180E7B552BD7BD83008558E8 /* AiAudioDecoder.m in Sources */, diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index 1f83a0e..0134e32 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -165,7 +165,6 @@ _recordManager = [[AiRecordManager alloc] init]; __weak typeof(self) ws = self; _recordManager.didRecordData = ^(NSData * _Nonnull data) { - [ws showLog:[NSString stringWithFormat:@"%@",data]]; [ws sendRecordData:data]; }; } @@ -229,7 +228,7 @@ } - (void)sendAiDataToSdk:(NSData *)data{ - [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; +// [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; if(self.connectType == AiMouseConnectType_hid){ // 0AFFFF12BC32 diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.h b/MouseSdk/AiMouseSdk/Manager/DeviceManger.h index 7409ad0..baced2c 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.h +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.h @@ -12,6 +12,7 @@ typedef NS_ENUM(NSInteger,AiMouseProductType) { AiMouseProductType_frk = 1,///富瑞坤 AiMouseProductType_tlw = 2,///泰凌微 + AiMouseProductType_n = 3,///一键上网 }; NS_ASSUME_NONNULL_BEGIN diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index 529e8bc..a272c9e 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -9,10 +9,11 @@ #import "HidManager.h" #import "BleManager.h" #import "TlwMouseSdk.h" +#import "NMouseSdk.h" #import "TimerManager.h" #import "AiMouseConfig.h" -@interface DeviceManger() +@interface DeviceManger() @property (nonatomic,strong) NSMutableData *recordData;//录音的数据 @property (nonatomic,strong) BleManager *ble; @@ -20,6 +21,7 @@ @property (nonatomic,strong) TlwMouse *tlwSdk; @property (nonatomic,strong) AiMouse *frkSdk; +@property (nonatomic,strong) NMouseSdk *nSdk; @property (nonatomic,assign) AiMouseProductType productType; //connectType 返回为0代表蓝牙,为1代表usb @@ -32,7 +34,7 @@ static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ manager = [[DeviceManger alloc]init]; - + }); return manager; } @@ -40,6 +42,7 @@ - (instancetype)init{ self = [super init]; if (self) { + [self showLog:@"MouseSdk_v1.0.3"]; [self setupSDK]; [self setupBle]; [self setupHid]; @@ -49,6 +52,9 @@ } #pragma mark ------ 设备初始化 - (void)setupSDK{ + self.nSdk = [[NMouseSdk alloc] init]; + [self.nSdk setDelegate:self]; + self.tlwSdk = [[TlwMouse alloc] init]; [self.tlwSdk setDelegate:self]; [self.tlwSdk setLogLevel:(TlwMouseLogLevel_none)]; @@ -62,7 +68,7 @@ - (void)setupTimer{ [TimerManager shared].timerCallBack = ^{ // [self showLog:@"timer action。。。"]; - if(self.tlwSdk.connected || self.frkSdk.connected){ + if(self.nSdk.connected || self.tlwSdk.connected || self.frkSdk.connected){ // [self.hid close]; } else{ @@ -77,7 +83,10 @@ self.hid.connectStateCallBack = ^(BOOL connected) { if (connected) { ws.productType = ws.hid.productType; - if (ws.hid.productType == AiMouseProductType_tlw) { + if (ws.hid.productType == AiMouseProductType_n) { + [ws.nSdk switchConnect:AiMouseConnectType_hid isConnected:true]; + } + else if (ws.hid.productType == AiMouseProductType_tlw) { [ws.tlwSdk switchConnect:AiMouseConnectType_hid isConnected:true]; } else{ @@ -85,7 +94,11 @@ } } else{ - if (ws.hid.productType == AiMouseProductType_tlw) { + if (ws.hid.productType == AiMouseProductType_n) { + [ws.nSdk switchConnect:AiMouseConnectType_hid isConnected:false]; + [ws.nSdk didDisconnect]; + } + else if (ws.hid.productType == AiMouseProductType_tlw) { [ws.tlwSdk switchConnect:AiMouseConnectType_hid isConnected:false]; [ws.tlwSdk didDisconnect]; } @@ -96,7 +109,10 @@ } }; self.hid.receiveInfoDataCallBack = ^(NSData *data) { - if (ws.productType == AiMouseProductType_tlw) { + if (ws.productType == AiMouseProductType_n) { + [ws.nSdk sendDeviceDataToSdk:data]; + } + else if (ws.productType == AiMouseProductType_tlw) { [ws.tlwSdk sendDeviceDataToSdk:data]; } else{ @@ -118,7 +134,10 @@ // [ws.hid close]; ws.productType = ws.ble.productType; - if (ws.ble.productType == AiMouseProductType_tlw) { + if (ws.ble.productType == AiMouseProductType_n) { + [ws.nSdk switchConnect:AiMouseConnectType_bluetooth isConnected:true]; + } + else if (ws.ble.productType == AiMouseProductType_tlw) { [ws.tlwSdk switchConnect:AiMouseConnectType_bluetooth isConnected:true]; } else{ @@ -126,7 +145,10 @@ } } else{ - if (ws.ble.productType == AiMouseProductType_tlw) { + if (ws.ble.productType == AiMouseProductType_n) { + [ws.nSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; + } + else if (ws.ble.productType == AiMouseProductType_tlw) { [ws.tlwSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; } else{ @@ -135,7 +157,10 @@ } }; self.ble.receiveInfoDataCallBack = ^(NSData *data) { - if (ws.productType == AiMouseProductType_tlw) { + if (ws.productType == AiMouseProductType_n) { + [ws.nSdk sendDeviceDataToSdk:data]; + } + else if (ws.productType == AiMouseProductType_tlw) { [ws.tlwSdk sendDeviceDataToSdk:data]; } else{ @@ -159,6 +184,9 @@ #pragma mark ------ 设备相关接口 -(BOOL)isConneted{ + if (self.nSdk != nil && self.nSdk.connected) { + return true; + } if (self.tlwSdk != nil && self.tlwSdk.connected) { return true; } @@ -168,7 +196,15 @@ return false; } - (NSString *)getCurrentConnectType { - if (self.productType == AiMouseProductType_tlw) { + if (self.productType == AiMouseProductType_n) { + if (self.nSdk.connectType == AiMouseConnectType_bluetooth) { + return @"0"; + } + else { + return @"1"; + } + } + else if (self.productType == AiMouseProductType_tlw) { if (self.tlwSdk.connectType == AiMouseConnectType_bluetooth) { return @"0"; } @@ -186,7 +222,10 @@ } } -(AiMouseConnectType)connectType{ - if (self.productType == AiMouseProductType_tlw) { + if (self.productType == AiMouseProductType_n) { + return self.nSdk.connectType; + } + else if (self.productType == AiMouseProductType_tlw) { return self.tlwSdk.connectType; } else{ @@ -201,7 +240,9 @@ } ///获取设备信息 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ - if (self.productType == AiMouseProductType_tlw) { + if(self.productType == AiMouseProductType_n){ + [self.nSdk getDeviceInfo:finished]; + }else if (self.productType == AiMouseProductType_tlw) { [self.tlwSdk getFullDeviceInfo:finished]; } else{ @@ -211,16 +252,25 @@ /// 获取信号强度 - (void)getRSSI:(void (^)(NSString *value,NSError *error))finished{ - if (self.productType == AiMouseProductType_tlw) { - finished(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; } - else{ + if (self.productType == AiMouseProductType_frk ) { [self.frkSdk getRSSI:finished]; } + else{ + finished(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + } } /// 设置CPI - (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } + if (self.productType == AiMouseProductType_tlw) { [self.tlwSdk setDPI:value completation:finished]; } @@ -234,6 +284,10 @@ /// - value: 品牌名称 /// - finished: 设置结果回调 - (void)setBrand:(NSString *)brand completation:(void (^)(BOOL isSuccess,NSError *error))finished { + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -244,6 +298,10 @@ /// 设置录音模式 - (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -254,6 +312,10 @@ /// 设置长按滚轮弹出的网页地址 - (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -264,6 +326,10 @@ /// 设置长按滚轮弹出网页开关 - (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -274,6 +340,10 @@ /// 设置鼠标连接模式 - (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -284,6 +354,10 @@ /// 获取录音模式 - (void)getRecordMode:(void (^)(int mode,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -294,6 +368,10 @@ /// 获取长按滚轮弹出的网页地址 - (void)getUrl:(void (^)(NSString *url,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -304,6 +382,10 @@ /// 获取长按滚轮弹出的网页地址开关状态 - (void)getUrlState:(void (^)(int state,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -314,6 +396,10 @@ /// 获取鼠标连接模式 - (void)getMouseModel:(void (^)(int mode,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { finished(0,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); } @@ -324,6 +410,10 @@ /// 打开录音 - (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { [self.tlwSdk openRecord:finished]; } @@ -334,6 +424,10 @@ /// 关闭录音 - (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ + if (self.productType == AiMouseProductType_n) { + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"当前鼠标不支持该接口"}]); + return; + } if (self.productType == AiMouseProductType_tlw) { [self.tlwSdk closeRecord:finished]; } @@ -351,6 +445,7 @@ if (connected) { [self.frkSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; + [self.nSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; } if (self.aiMouseConnectStateDidChangeCallBack) { @@ -474,6 +569,55 @@ [self showLog:log]; } +#pragma mark - NMouseDelegate +/// 设备连接状态 +/// - Parameter connected: 是否连接 +- (void)nMouseConnectStateDidChange:(BOOL)connected{ + [self showLog:[NSString stringWithFormat:@"%@设备连接状态返回: %@",self.nSdk.connectType == AiMouseConnectType_bluetooth ? @"tlw 蓝牙 ":@"一键上网 USB",connected ? @"true":@"false"]]; + + if (connected) { + [self.tlwSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; + [self.frkSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; + } + + if (self.aiMouseConnectStateDidChangeCallBack) { + self.aiMouseConnectStateDidChangeCallBack(self.nSdk.connectType == AiMouseConnectType_bluetooth ? 0:1,connected); + } + if(self.authCallBack && connected)self.authCallBack(connected); +} + + +/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 +/// - Parameter data: 数据 +- (void)nMouseSendDeviceInfoData:(NSData *)data{ + if (self.nSdk.connectType == AiMouseConnectType_bluetooth) { + [self.ble writeToDevice:data]; + } + else if (self.nSdk.connectType == AiMouseConnectType_hid){ + [self.hid writeToDevice:data]; + } +} + +/// 鼠标按键指令回调 +/// - Parameter data: 数据。 +/// 前 单击0x06, 按下0x13(开始录音)抬起0x14(结束录音) +/// 中 单击0x03, 按下0x11(开始录音)抬起0x12(结束录音) +/// 后 第一次单击0x01, 第二次单击0x02(结束录音) , 按下0x09(开始录音)抬起0x10(结束录音) +/// 其他未定义 +- (void)nMouseSendCmdData:(NSData *)data{ + uint8 cmd; + [data getBytes:&cmd length:1]; + [self showLog:[NSString stringWithFormat:@"收到指令 = %X",cmd]]; + if (self.aiMouseSendCmdDataCallBack) { + self.aiMouseSendCmdDataCallBack([NSString stringWithFormat:@"%X",cmd]); + } +} + +/// 输出sdk日志 +/// - Parameter log: 日志 +- (void)nMouseAddLog:(NSString *)log{ + [self showLog:log]; +} #pragma mark - AiMouseDelegate /// 设备连接状态 /// - Parameter connected: 是否连接 @@ -482,6 +626,7 @@ if (connected) { [self.tlwSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; + [self.nSdk switchConnect:AiMouseConnectType_bluetooth isConnected:false]; } if (self.aiMouseConnectStateDidChangeCallBack) { diff --git a/MouseSdk/AiMouseSdk/Manager/HidManager.m b/MouseSdk/AiMouseSdk/Manager/HidManager.m index 9251584..4a48cc8 100644 --- a/MouseSdk/AiMouseSdk/Manager/HidManager.m +++ b/MouseSdk/AiMouseSdk/Manager/HidManager.m @@ -44,12 +44,33 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH // [[HidManager shared] showLog:(@"当前处于连接状态,对监听到有USB 插入 的事件不做处理")]; return; } +// 1ea7 0064 uint32_t pid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey)); uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey)); uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey)); uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); +// [[HidManager shared] showLog: inIOHIDDeviceRef]; - if(vid == 0x10D6 && pid == 0xB008){ + + if(vid == 0x1ea7 && pid == 0x0064){ + [[HidManager shared] showLog:([NSString stringWithFormat:@"发现设备%@,pid = %d,vid = %d ,page = %d, usage = %d",inIOHIDDeviceRef,pid,vid,PrimaryUsagePage,PrimaryUsage])]; + [HidManager shared].productType = AiMouseProductType_n; + [HidManager shared].deviceInfoCha = inIOHIDDeviceRef; + //注册消息回调 + unsigned char InputBuffer[64]; + IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), &hidReceiveData, NULL); + + IOReturn result = IOHIDDeviceOpen([HidManager shared].deviceInfoCha, kIOHIDOptionsTypeNone); + if (result != kIOReturnSuccess) { + [[HidManager shared] showLog:[NSString stringWithFormat:@"打开设备失败! %d",result]]; + [[AiDeviceAuthManager shared] showHidAlert]; + return; + }else{ + [[HidManager shared] showLog:@"打开设备成功!"]; + [HidManager shared].connectStateCallBack(true) ; + } + } + else if(vid == 0x10D6 && pid == 0xB008){ [[HidManager shared] showLog:([NSString stringWithFormat:@"发现设备%@,pid = %d,vid = %d ,page = %d, usage = %d",inIOHIDDeviceRef,pid,vid,PrimaryUsagePage,PrimaryUsage])]; [HidManager shared].productType = AiMouseProductType_tlw; [HidManager shared].deviceInfoCha = inIOHIDDeviceRef; @@ -131,8 +152,23 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender, static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){ - - if([HidManager shared].productType == AiMouseProductType_tlw){ + NSData *data = [[NSData alloc] initWithBytes:report length:reportLength]; +// [[HidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; + if([HidManager shared].productType == AiMouseProductType_n){ +// if (report[0] == 0x01 || report[0] == 0x02) { +// //鼠标键盘活动事件 +// return; +// } + uint32_t primaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); + uint32_t primaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); + + if(primaryUsagePage == 65461 && primaryUsage == 1){ + NSData *data = [[NSData alloc] initWithBytes:report length:reportLength]; +// [[HidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; + [HidManager shared].receiveInfoDataCallBack(data); + } + } + else if([HidManager shared].productType == AiMouseProductType_tlw){ if (report[0] == 0x01 || report[0] == 0x02) { //鼠标键盘活动事件 return; @@ -233,13 +269,12 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe } /// 发送数据给设备 -(void)writeToDevice:(NSData *)data{ -// [self showLog:[NSString stringWithFormat:@"hid收到数据:%@",data]]; if(self.deviceInfoCha == nil){ [self showLog:@"sendData: 请先连上设备"]; return; } -// [self showLog:[NSString stringWithFormat:@"向usb设备发送数据 %@",data]]; + [self showLog:[NSString stringWithFormat:@"向usb设备发送数据 %@",data]]; IOReturn ret = IOHIDDeviceSetReport(self.deviceInfoCha, kIOHIDReportTypeOutput, 0, data.bytes, data.length); if (ret != kIOReturnSuccess) { [self showLog:[NSString stringWithFormat:@"发送失败! code = %d",ret]]; diff --git a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.h b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.h new file mode 100644 index 0000000..43fcb34 --- /dev/null +++ b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.h @@ -0,0 +1,61 @@ +// +// NMouseSdk.h +// AiMouseManager +// +// Created by incar on 2024/9/11. +// + +#import +#import "AiMouseSdk.h" +@interface NDeviceInfo : NSObject +@property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应1200,1600,2400,4800) +@property (nonatomic, assign) int version;///软件版本 +@property (nonatomic, assign) int batteryState;/// 电池状态 +@property (nonatomic, assign) int batteryValue;/// 电池百分百电量,0-100 +@end + + +@protocol NMouseSdkDelegate + +/// 设备连接状态 +/// - Parameter connected: 是否连接 +- (void)nMouseConnectStateDidChange:(BOOL)connected; + + +/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 +/// - Parameter data: 数据 +- (void)nMouseSendDeviceInfoData:(NSData *)data; + +/// 鼠标按键指令回调 +// 0x42 Ai键按下 +- (void)nMouseSendCmdData:(NSData *)data; + +/// 输出sdk日志 +/// - Parameter log: 日志 +- (void)nMouseAddLog:(NSString *)log; + +@end + + +@interface NMouseSdk : NSObject +@property (nonatomic, weak) id delegate;/// 代理 +@property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型 +@property (nonatomic, readonly) BOOL connected;//是否已连接 + +/// 切换连接类型 +/// - Parameter type: 连接类型 +- (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted; + +/// 断开连接 +- (void)didDisconnect; + +/// 传输设备信息数据给sdk +/// - Parameter data:设备信息特征传过来的数据 +- (void)sendDeviceDataToSdk:(NSData *)data; + +/// 获取设备信息 +/// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为nil +- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished; +@end + + diff --git a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m new file mode 100644 index 0000000..379d0cb --- /dev/null +++ b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m @@ -0,0 +1,206 @@ +// +// NMouseSdk.m +// AiMouseManager +// +// Created by incar on 2024/9/11. +// + +#import "NMouseSdk.h" +#import "TlwTools.h" +@interface NMouseSdk() + +@property (nonatomic,strong)void (^getDeviceInfoCallBack)(AiMouseDeviceInfo *deviceInfo,NSError *error); + +@property (nonatomic,strong)void (^getSn1CallBack)(NSString *text,NSError *error); +@property (nonatomic,strong)void (^getSn2CallBack)(NSString *text,NSError *error); + +@property (nonatomic,assign)BOOL didReceiveData; +@property (nonatomic,assign)NSInteger dongleTimes; + +@property (nonatomic,strong)AiMouseDeviceInfo *deviceInfo; +@end + +@implementation NMouseSdk + + +/// 切换连接类型 +/// - Parameter type: 连接类型 +- (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted{ + self.didReceiveData = false; + + if(isConneted ){ + _connected = true; + _connectType = type; + [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"]; + + if (type == AiMouseConnectType_hid ) { + [self getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) { + + }]; + [self startCheckConnectState]; + } + else{ + [self TlwConnectManager:nil connectStateDidChange:true]; + } + } + else{ + if (self.connected) { + _connected = false; + [self TlwConnectManager:nil connectStateDidChange:false]; + } + } +} + +- (void)didDisconnect{ + _connected = false; +} + +- (void)sendDeviceDataToSdk:(NSData *)data{ + + NSString *text = [TlwTools dataToHexString:data]; + +// 鼠标 0x020001f0ff0000 +// sn1 0xb52c00bba30d5540 +// sn2 0xb52c01bba30d5540 + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if ([text hasPrefix:@"B52C00"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if (self.getSn1CallBack) { + self.getSn1CallBack([text substringFromIndex:6], nil); + } + } + else if ([text hasPrefix:@"B52C01"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if (self.getSn2CallBack) { + self.getSn2CallBack([text substringFromIndex:6], nil); + } + } + else if([text hasPrefix:@"B5200443"]){ + uint8_t cmd = 0x42; + NSMutableData *mData = [NSMutableData data]; + [mData appendBytes:&cmd length:1]; + [self.delegate nMouseSendCmdData:mData]; + } +} + +- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + self.getDeviceInfoCallBack = finished; + self.deviceInfo = [[AiMouseDeviceInfo alloc] init]; + self.deviceInfo.battery_power = @"0"; + self.deviceInfo.CPI = @"1200"; + self.deviceInfo.CPI_list = @"1200,1600,2400,4800"; + self.deviceInfo.version = @"1"; + self.deviceInfo.brand = @"博仪创新"; + self.deviceInfo.sn = @""; + self.deviceInfo.mac = @""; + + __weak typeof(self) ws = self; + [ws getSn1:^(NSString *text, NSError *error) { + if (text) { + [ws showLog:[NSString stringWithFormat:@"sn1 %@",text]]; + [ws getSn2:^(NSString *text2, NSError *error) { + if (text2) { + [ws showLog:[NSString stringWithFormat:@"sn2 %@",text]]; + ws.deviceInfo.mac = [NSString stringWithFormat:@"%@%@",text,text2]; + ws.deviceInfo.sn = ws.deviceInfo.mac; + ws.getDeviceInfoCallBack(ws.deviceInfo, nil); + } + else{ + ws.getDeviceInfoCallBack(nil, error); + } + }]; + } + else{ + ws.getDeviceInfoCallBack(nil, error); + } + }]; +} + +- (void)getSn1:(void (^)(NSString *text,NSError *error))finished{ + self.getSn1CallBack = finished; + uint8_t cmd = 0xB5; + uint8_t len = 0x2C; + uint8_t tail1 = 0x00; + uint8_t tail2 = 0x00; + uint8_t tail3 = 0x00; + uint8_t tail4 = 0x00; + uint8_t tail5 = 0x00; + uint8_t tail6 = 0x00; + + NSMutableData *mData = NSMutableData.data; + [mData appendBytes:&cmd length:1]; + [mData appendBytes:&len length:1]; + [mData appendBytes:&tail1 length:1]; + [mData appendBytes:&tail2 length:1]; + [mData appendBytes:&tail3 length:1]; + [mData appendBytes:&tail4 length:1]; + [mData appendBytes:&tail5 length:1]; + [mData appendBytes:&tail6 length:1]; + [self sendToDevice:mData]; +} + +- (void)getSn2:(void (^)(NSString *text,NSError *error))finished{ + self.getSn2CallBack = finished; + uint8_t cmd = 0xB5; + uint8_t len = 0x2C; + uint8_t tail1 = 0x01; + uint8_t tail2 = 0x00; + uint8_t tail3 = 0x00; + uint8_t tail4 = 0x00; + uint8_t tail5 = 0x00; + uint8_t tail6 = 0x00; + + NSMutableData *mData = NSMutableData.data; + [mData appendBytes:&cmd length:1]; + [mData appendBytes:&len length:1]; + [mData appendBytes:&tail1 length:1]; + [mData appendBytes:&tail2 length:1]; + [mData appendBytes:&tail3 length:1]; + [mData appendBytes:&tail4 length:1]; + [mData appendBytes:&tail5 length:1]; + [mData appendBytes:&tail6 length:1]; + [self sendToDevice:mData]; +} + +#pragma mark - check connect +- (void)startCheckConnectState{ + self.dongleTimes = 0; + [self checkAction]; +} +- (void)checkAction{ + if (self.deviceInfo.sn && self.deviceInfo.sn.length > 0) { + [self TlwConnectManager:nil connectStateDidChange:true]; + return; + } + self.dongleTimes++; + if (self.dongleTimes > 3) { + [self TlwConnectManager:nil connectStateDidChange:false]; + return; + } + [self performSelector:@selector(checkAction) withObject:nil afterDelay:1]; +} + +#pragma mark - other +-(void)TlwConnectManager:(NSString *)manager connectStateDidChange:(BOOL)connected{ + _connected = connected; + if([self.delegate respondsToSelector:@selector(nMouseConnectStateDidChange:)]) [self.delegate nMouseConnectStateDidChange:connected]; +} +- (void)showLog:(NSString *)log{ + if (self.delegate && [self.delegate respondsToSelector:@selector(nMouseAddLog:)]) { + [self.delegate nMouseAddLog:[NSString stringWithFormat:@"[n]%@",log]]; + } +} + +- (void)sendToDevice:(NSMutableData *)data{ + // if (data.length < 64) { + // NSInteger len = 64 - data.length; + // for (NSInteger i = 0; i < len; i++) { + // uint8_t d = 0x00; + // [data appendBytes:&d length:1]; + // } + // } + [self showLog:[NSString stringWithFormat:@"[send][info] %@",[TlwTools dataToHexString:data]]]; + [self.delegate nMouseSendDeviceInfoData:data]; +} +@end diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m index 786d336..ab3845b 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m @@ -49,7 +49,7 @@ if (self = [super init]) { _logLevel = TlwMouseLogLevel_none; _connectType = AiMouseConnectType_bluetooth; - NSLog(@"[TlwMouseSdk]%@",[NSString stringWithFormat:@"AiMouseSdk_v%@",self.version]); +// NSLog(@"[TlwMouseSdk]%@",[NSString stringWithFormat:@"AiMouseSdk_v%@",self.version]); [self.recordManager checkPermissions]; } return self; @@ -134,7 +134,7 @@ } - (void)sendAiDataToSdk:(NSData *)data{ - [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; +// [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; if(self.connectType == AiMouseConnectType_hid){ } else if (self.connectType == AiMouseConnectType_bluetooth){ @@ -639,7 +639,7 @@ } #pragma mark - other - (void)sendRecordData:(NSData *)data{ - [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]]; +// [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]]; if (self.delegate) [self.delegate tlwMouseSendRecordData:data]; } diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index c7d5c48..5249e7a 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.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index c3ddbcd..86ee2a8 100644 --- a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -40,5 +40,37 @@ + + + + + + + +