From: liangzhenying <867174124@qq.com> Date: Fri, 23 Aug 2024 11:53:34 +0000 (+0800) Subject: 原有接口动,只支持泰凌微方案 X-Git-Tag: 千寻适配d9~42 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=5e35a50d0b5cd201c41eeafcab6466f96a241aa8;p=mirrors%2FMouseSdk-MacOS.git 原有接口动,只支持泰凌微方案 --- diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.h b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.h index 98376d5..38f5596 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.h +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.h @@ -6,6 +6,7 @@ // #import +#import "AiMouseSdk.h" @interface TlwDeviceInfo : NSObject @property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应 800 1200 1800 2400) @@ -21,16 +22,12 @@ typedef NS_ENUM(NSInteger,TlwMouseLogLevel) { TlwMouseLogLevel_info, }; -typedef NS_ENUM(NSInteger,TlwConnectType) { - TlwConnectType_bluetooth = 0,///蓝牙 - TlwConnectType_hid,///hid -}; - @protocol TlwMouseDelegate /// 设备连接状态 /// - Parameter connected: 是否连接 -- (void)aiMouseConnectStateDidChange:(BOOL)connected; +- (void)tlwMouseConnectStateDidChange:(BOOL)connected; + /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 /// - Parameter data: 数据 @@ -57,7 +54,7 @@ typedef NS_ENUM(NSInteger,TlwConnectType) { @interface TlwMouse : NSObject @property (nonatomic, weak) id delegate;/// 代理 -@property (nonatomic, readonly) TlwConnectType connectType;//连接类型 +@property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型 @property (nonatomic, readonly) BOOL connected;//是否已连接 /// 单利 @@ -72,7 +69,7 @@ typedef NS_ENUM(NSInteger,TlwConnectType) { /// 切换连接类型 /// - Parameter type: 连接类型 -- (void)switchConnect:(TlwConnectType)type; +- (void)switchConnect:(AiMouseConnectType)type; /// 传输业务数据给sdk /// - Parameter data:ai特征传过来的数据 diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m index 4713161..bd7f9ac 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m @@ -46,7 +46,7 @@ -(instancetype)init{ if (self = [super init]) { _logLevel = TlwMouseLogLevel_none; - _connectType = TlwConnectType_bluetooth; + _connectType = AiMouseConnectType_bluetooth; [self.connectManager start]; NSLog(@"[TlwMouseSdk]%@",[NSString stringWithFormat:@"AiMouseSdk_v%@",self.version]); } @@ -101,15 +101,15 @@ [self.connectManager disConnected]; } -- (void)switchConnect:(TlwConnectType)type{ +- (void)switchConnect:(AiMouseConnectType)type{ if(type != _connectType && self.connected){ [self.connectManager disConnected]; } _connectType = type; - [self showLog:type == TlwConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"]; + [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"]; - if (type == TlwConnectType_hid) { + if (type == AiMouseConnectType_hid) { [self.recordManager checkPermissions]; } } @@ -118,7 +118,7 @@ [self.connectManager resetTimeOut]; [self showLog:[NSString stringWithFormat:@"[receive][Ai] %@",data]]; - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ //// 0AFFFF12BC32 // if(data.length == 6){ // NSData *subData = [data subdataWithRange:NSMakeRange(5, 1)]; @@ -138,22 +138,22 @@ // [self showLog:@"未实现指令"]; // } } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ [self bleReceiveAiData:data]; } } -(void)sendDeviceDataToSdk:(NSData *)data{ [self showLog:[NSString stringWithFormat:@"[receive][info] %@",data]]; - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ [self hidReceiveDeviceData:data]; } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ [self bleReceiveDeviceData:data]; } } - (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ self.openRecord = finished; uint8_t cmd = 0x03; uint8_t len = 0x00; @@ -165,7 +165,7 @@ [mData appendBytes:&tail length:1]; [self sendToDevice:mData]; } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ self.openRecord = finished; uint8_t cmd = 0x03; uint8_t dir = 0x01; @@ -178,7 +178,7 @@ } } - (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ self.closeRecord = finished; uint8_t cmd = 0x04; uint8_t len = 0x00; @@ -190,7 +190,7 @@ [mData appendBytes:&tail length:1]; [self sendToDevice:mData]; } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ self.closeRecord = finished; uint8_t cmd = 0x04; uint8_t dir = 0x01; @@ -205,7 +205,7 @@ } - (void)setDPI:(uint8_t)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ self.setDpi = finished; uint8_t type = 0x06; uint8_t len = 0x01; @@ -218,7 +218,7 @@ [mData appendBytes:&tail length:1]; [self sendToDevice:mData]; } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ self.setDpi = finished; uint8_t cmd = 0x06; uint8_t dir = 0x01; @@ -234,7 +234,7 @@ } - (void)getDeviceInfo:(void (^)(TlwDeviceInfo *deviceInfo,NSError *error))finished{ - if(self.connectType == TlwConnectType_hid){ + if(self.connectType == AiMouseConnectType_hid){ self.getMouseInfo = finished; // 0x05fff1fec09f0114ef uint8_t cmd = 0x0c; @@ -248,7 +248,7 @@ [mData appendBytes:&tail length:1]; [self sendToDevice:mData]; } - else if (self.connectType == TlwConnectType_bluetooth){ + else if (self.connectType == AiMouseConnectType_bluetooth){ self.getMouseInfo = finished; uint8_t cmd = 0x0c; uint8_t dir = 0x01; @@ -479,7 +479,7 @@ #pragma mark - TlwConnectManagerDelegate -(void)TlwConnectManager:(TlwConnectManager *)manager connectStateDidChange:(BOOL)connected{ _connected = connected; - if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:connected]; + if([self.delegate respondsToSelector:@selector(tlwMouseConnectStateDidChange:)]) [self.delegate tlwMouseConnectStateDidChange:connected]; } -(void)TlwConnectManagerReSendData:(TlwConnectManager *)manager{ // __weak typeof(self) ws = self; diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index 7c282ad..a2b2e2a 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 675cff0..b9c3bbe 100644 --- a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -107,8 +107,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "23" endingLineNumber = "23" - landmarkName = "TlwVC" - landmarkType = "3"> + landmarkName = "unknown" + landmarkType = "0"> diff --git a/MouseSdk/MouseSdk/Ble/BleManager.h b/MouseSdk/MouseSdk/Ble/BleManager.h index 83f7622..1b3a566 100644 --- a/MouseSdk/MouseSdk/Ble/BleManager.h +++ b/MouseSdk/MouseSdk/Ble/BleManager.h @@ -7,9 +7,10 @@ #import #import +#import "TlwMouseSdk.h" #import "AiMouseSdk.h" -@interface BleManager : NSObject +@interface BleManager : NSObject @property (nonatomic,copy)void (^discoverDevice)(CBPeripheral *peripheral) ;/// 扫描到设备 @property (nonatomic,copy)void (^didConnectDevice)(CBPeripheral *peripheral);/// 连接成功 @property (nonatomic,copy)void (^didDisConnectDevice)(CBPeripheral *peripheral);/// 断开连接 diff --git a/MouseSdk/MouseSdk/Ble/BleManager.m b/MouseSdk/MouseSdk/Ble/BleManager.m index d9e1747..9789e87 100644 --- a/MouseSdk/MouseSdk/Ble/BleManager.m +++ b/MouseSdk/MouseSdk/Ble/BleManager.m @@ -7,12 +7,22 @@ #import "BleManager.h" +//// 服务id +//#define kServiceUUID @"FFF1" +////ai特征 +//#define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8" +////设备信息特征 +//#define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6" + // 服务id -#define kServiceUUID @"FFF1" +#define kServiceUUID @"FFF0" //ai特征 -#define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8" -//设备信息特征 -#define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6" +#define kAiUUID @"00010203-0405-0607-0809-0A0B0C0D2B18" +//写设备信息特征 +#define kSetDeviceInfoUUID @"FFF1" +//通知设备信息特征 +#define kNotifyDeviceInfoUUID @"FFF2" + @interface BleManager () { @@ -154,6 +164,7 @@ } -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ [self showLog:[NSString stringWithFormat:@"(BleManager) didDisconnectPeripheral:断开连接。。。%@",error.description]]; + [self tlwMouseConnectStateDidChange:false]; // dispatch_block_cancel(_block); // 取消定时的执行 if (_isActiveDisconnect) { dispatch_block_cancel(_disconnectBlock);// 取消定时的执行 @@ -168,7 +179,7 @@ else{ //返回设备断开连接 // [self aiMouseConnectStateDidChange:false]; - [[AiMouse shared] didDisconnect]; + [[TlwMouse shared] didDisconnect]; if(self.didDisConnectDevice){ self.didDisConnectDevice(peripheral); @@ -197,35 +208,24 @@ // 发现特征 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { - [self showLog:[NSString stringWithFormat:@"(BleManager) didDiscoverCharacteristicsForService:发现特征"]]; for (CBCharacteristic *characteristic in service.characteristics){ - - [self showLog:[NSString stringWithFormat:@"(BleManager) didDiscoverCharacteristicsForService:service.characteristicUUID %@",characteristic.UUID.UUIDString]]; - if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) { - [self showLog:[NSString stringWithFormat:@"(BleManager) didDiscoverCharacteristicsForService:AI特征"]]; - //AI特征 - self.aiCha = characteristic; + //语音特征 [peripheral setNotifyValue:YES forCharacteristic:characteristic]; } - else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) { - [self showLog:[NSString stringWithFormat:@"(BleManager) didDiscoverCharacteristicsForService:设备信息特征"]]; + else if ([characteristic.UUID.UUIDString isEqualToString:kNotifyDeviceInfoUUID]) { + //通知设备信息特征 + [peripheral setNotifyValue:YES forCharacteristic:characteristic]; + } + else if ([characteristic.UUID.UUIDString isEqualToString:kSetDeviceInfoUUID]) { //设备信息特征 self.deviceInfoCha = characteristic; - [peripheral setNotifyValue:YES forCharacteristic:characteristic]; - -// //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用 -// [self startAuthentication]; - - //按照前端要求,他们自己调用鉴权接口,此处只先设置代理和连接类型 - { //设置代理 - [AiMouse shared].delegate = self; - //切换当前连接类型 - [[AiMouse shared] switchConnect:AiMouseConnectType_bluetooth]; - } - + //切换代理 + [TlwMouse shared].delegate = self; + //切换当前连接类型 + [[TlwMouse shared] switchConnect:AiMouseConnectType_bluetooth]; [self showLog:(@"(BleManager)didDiscoverCharacteristicsForService:回调连接成功 ")]; -// dispatch_block_cancel(_block); // 取消定时的执行 + [self tlwMouseConnectStateDidChange:true]; //此时才返回连接成功 if(self.didConnectDevice){ self.didConnectDevice(peripheral); @@ -242,46 +242,19 @@ if([characteristic.UUID.UUIDString isEqualToString:kAiUUID]){ //AI数据 [self showLog:[NSString stringWithFormat:@"(BleManager) didUpdateValueForCharacteristic:发送AI数据sendAiDataToSdk"]]; - [[AiMouse shared] sendAiDataToSdk:data]; + [[TlwMouse shared] sendAiDataToSdk:data]; } - else if([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]){ + else if([characteristic.UUID.UUIDString isEqualToString:kNotifyDeviceInfoUUID]){ //设备信息数据 [self showLog:[NSString stringWithFormat:@"(BleManager) didUpdateValueForCharacteristic:发送设备信息数据sendDeviceDataToSdk"]]; - [[AiMouse shared] sendDeviceDataToSdk:data]; - } -} - -#pragma mark - AiDelegate - -/// 设备连接状态 -/// - Parameter connected: 是否连接 -- (void)aiMouseConnectStateDidChange:(BOOL)connected { - [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseConnectStateDidChange - 设备连接状态返回: %hhd",connected]]; - - if (self.aiMouseConnectStateDidChangeCallBack) { - self.aiMouseConnectStateDidChangeCallBack(connected); - } - //没有连接 - if (!connected) { - self.connectPeripheral = nil; - self.deviceInfoCha = nil; - self.aiCha = nil; - } -} - -/// 设备鉴权结果返回 -/// - Parameter authState: 鉴权状态 -- (void)aiMouseAuthenticationResult:(AiMouseAuthState)authState{ - [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseAuthenticationResult - 设备鉴权结果返回: %ld",(long)authState]]; - if(self.authCallBack){ - self.authCallBack(authState == AiMouseAuthState_Success); + [[TlwMouse shared] sendDeviceDataToSdk:data]; } } +#pragma mark - TlwMouseDelegate /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 /// - Parameter data: 数据 --(void)aiMouseSendDeviceInfoData:(NSData *)data{ - [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseSendDeviceInfoData:[send] %@",data]]; +-(void)tlwMouseSendDeviceInfoData:(NSData *)data{ if (self.connectPeripheral ==nil) { [self showLog:@"peripheral 为空"]; return; @@ -290,7 +263,7 @@ [self showLog:@"characteristic 为空"]; return; } - [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse]; + [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithResponse]; if (self.aiMouseSendDeviceInfoDataCallBack) { self.aiMouseSendDeviceInfoDataCallBack(data); @@ -299,13 +272,51 @@ /// 鼠标按键指令回调 /// - Parameter data: 数据。 -/// 前 第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音) +/// 前 单击0x06, 按下0x13(开始录音)抬起0x14(结束录音) +/// 中 单击0x03, 按下0x11(开始录音)抬起0x12(结束录音) +/// 后 第一次单击0x01, 第二次单击0x02(结束录音) , 按下0x09(开始录音)抬起0x10(结束录音) +/// 其他未定义 +/// +/// /// 鼠标按键指令回调 富瑞坤 +/// - Parameter data: 数据。 +/// 前 单击43,按下27(开始录音)抬起28(结束录音) /// 中 单击42, 按下25(开始录音)抬起26(结束录音) -/// 后 单击43,按下27(开始录音)抬起28(结束录音) +/// 后 第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音) +/// /// 其他未定义 -- (void)aiMouseSendCmdData:(NSData *)data{ +- (void)tlwMouseSendCmdData:(NSData *)data{ uint8 cmd; [data getBytes:&cmd length:1]; + if( cmd == 0x01){ + cmd = 0x31; + }else if( cmd == 0x02){ + cmd = 0x32; + } + else if( cmd == 0x09){ + cmd = 0x21; + } + else if( cmd == 0x10){ + cmd = 0x22; + } + else if( cmd == 0x03){ + cmd = 0x42; + } + else if( cmd == 0x11){ + cmd = 0x25; + } + else if( cmd == 0x12){ + cmd = 0x26; + } + else if( cmd == 0x06){ + cmd = 0x43; + } + else if( cmd == 0x13){ + cmd = 0x27; + } + else if( cmd == 0x14){ + cmd = 0x28; + } + [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseSendCmdData:收到指令 = %X",cmd]]; if (self.aiMouseSendCmdDataCallBack) { @@ -330,7 +341,7 @@ /// 录音回调 /// - Parameter data: pcm格式语音数据 -- (void)aiMouseSendRecordData:(NSData *)data{ +- (void)tlwMouseSendRecordData:(NSData *)data{ NSString *base64String = [data base64EncodedStringWithOptions:0]; [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseSendRecordData:[appendData] %@\n%@",data,base64String]]; [self.recordData appendData:data]; @@ -338,13 +349,31 @@ self.recordingCallBack(data); } } - +/// 输出日志 - (void)aiMouseAddLog:(NSString *)log { if (self.aiMouseAddLogCallBack) { self.aiMouseAddLogCallBack(log); } } +// 连接状态改变 +- (void)tlwMouseConnectStateDidChange:(BOOL)connected{ + [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseConnectStateDidChange - 设备连接状态返回: %hhd",connected]]; + + if (self.aiMouseConnectStateDidChangeCallBack) { + self.aiMouseConnectStateDidChangeCallBack(connected); + } + if (connected == true) { + self.authCallBack(true); + } + //没有连接 + if (!connected) { + self.connectPeripheral = nil; + self.deviceInfoCha = nil; + self.aiCha = nil; + } +} + #pragma mark - public - (void)connectBleDeviceWithName:(NSString *)bleName { //如果是已连接或者正在连接,不需要在链接了 @@ -428,25 +457,47 @@ /// 获取设备信息 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{ [self showLog:[NSString stringWithFormat:@"(BleManager) getDeviceInfo:获取设备信息"]]; - [[AiMouse shared] getDeviceInfo:completation]; + [[TlwMouse shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) { + AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init]; + info.battery_power = [NSString stringWithFormat:@"%d",deviceInfo.batteryValue] ; + info.CPI = [NSString stringWithFormat:@"%d",deviceInfo.DPI]; + info.CPI_list = @"1,2,3,4"; + info.version = [NSString stringWithFormat:@"%d",deviceInfo.version]; + info.brand = @""; + info.sn = @""; + info.mac = @""; + completation(info,nil); +// @property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应 800 1200 1800 2400) +// @property (nonatomic, assign) int version;///软件版本 +// @property (nonatomic, assign) int batteryState;/// 电池状态 +// @property (nonatomic, assign) int batteryValue;/// 电池百分百电量,0-100 +// /// +// @property (nonatomic, strong) NSString *battery_power;/// 电池百分百电量,0-100 +// @property (nonatomic, strong) NSString *CPI;/// CPI值 +// @property (nonatomic, strong) NSString *CPI_list;/// 可设置的CPI参数列表 +// @property (nonatomic, strong) NSString *version;///软件版本 +// @property (nonatomic, strong) NSString *brand;/// 品牌名称 +// @property (nonatomic, strong) NSString *sn;/// 设备序列号 +// @property (nonatomic, strong) NSString *mac;///设备MAC地址 + }]; } /// 获取信号强度 - (void)getRSSI:(void (^)(NSString *value,NSError *error))complete { - [self showLog:[NSString stringWithFormat:@"(BleManager) getRSSI:获取信号强度"]]; - [[AiMouse shared] getRSSI:complete]; + [self showLog:@"不支持该接口接口"]; + } ///// 鉴权 //-(void)startAuthentication{ // //设置代理 -// [AiMouse shared].delegate = self; +// [TlwMouse shared].delegate = self; // //切换当前连接类型 -// [[AiMouse shared] switchConnect:AiMouseConnectType_bluetooth]; +// [[TlwMouse shared] switchConnect:AiMouseConnectType_bluetooth]; // //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用 // [self showLog:@"(BleManager) startAuthentication 开始鉴权"]; // //鉴权 -// [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) { +// [[TlwMouse shared] startAuthentication:^(AiMouseAuthState state) { // [self showLog:[NSString stringWithFormat:@"(BleManager) startAuthentication 鉴权结果 = %@",@(state)]]; // if(self.authCallBack){ // self.authCallBack(state == AiMouseAuthState_Success); @@ -473,7 +524,7 @@ [self performSelector:@selector(autoConnectDevice) withObject:nil afterDelay:10]; } - (void)showLog:(NSString *)log{ -// NSLog(@"%@",log); + NSLog(@"%@",log); } //将录音数据保存 diff --git a/MouseSdk/MouseSdk/Ble/DeviceManger.m b/MouseSdk/MouseSdk/Ble/DeviceManger.m index a0f5504..01ad3a7 100644 --- a/MouseSdk/MouseSdk/Ble/DeviceManger.m +++ b/MouseSdk/MouseSdk/Ble/DeviceManger.m @@ -8,6 +8,7 @@ #import "DeviceManger.h" #import "HidManager.h" #import "BleManager.h" +#import "TlwMouseSdk.h" @interface DeviceManger() @@ -25,7 +26,7 @@ static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ - [[AiMouse shared] setLogLevel:(AiMouseLogLevel_info)]; + [[TlwMouse shared] setLogLevel:(TlwMouseLogLevel_info)]; manager = [[DeviceManger alloc]init]; }); @@ -39,18 +40,18 @@ [self setupHid]; //先默认设置蓝牙管理对象为鼠标 - [[AiMouse shared] setDelegate:self.ble]; + [[TlwMouse shared] setDelegate:self.ble]; } return self; } -(AiMouseConnectType)connectType{ - return [AiMouse shared].connectType; + return [TlwMouse shared].connectType; } - (NSString *)getCurrentConnectType { - if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { return @"0"; } else { @@ -59,15 +60,15 @@ } //- (void)switchConnect:(AiMouseConnectType)type{ -// [[AiMouse shared] switchConnect:type]; +// [[TlwMouse shared]] switchConnect:type]; // -// if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) { +// if ([TlwMouse shared]].connectType == AiMouseConnectType_bluetooth) { // [self setupBle]; -// [AiMouse shared].delegate = self.ble; +// [TlwMouse shared]].delegate = self.ble; // } // else{ // [self setupHid]; -// [AiMouse shared].delegate = self.hid; +// [TlwMouse shared]].delegate = self.hid; // } //} @@ -247,29 +248,27 @@ #pragma mark ------ 设备相关接口 ///获取设备信息 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation{ -// if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) { -// [self.ble getDeviceInfo:completation]; -// } -// else{ -// [self.hid getDeviceInfo:completation]; -// } - [[AiMouse shared] getDeviceInfo:completation]; + [[TlwMouse shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) { + AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init]; + info.battery_power = [NSString stringWithFormat:@"%d",deviceInfo.batteryValue] ; + info.CPI = [NSString stringWithFormat:@"%d",deviceInfo.DPI]; + info.CPI_list = @"1,2,3,4"; + info.version = [NSString stringWithFormat:@"%d",deviceInfo.version]; + info.brand = @""; + info.sn = @""; + info.mac = @""; + completation(info,nil); + }]; } /// 获取信号强度 - (void)getRSSI:(void (^)(NSString *value,NSError *error))completation{ -// if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) { -// [self.ble getRSSI:completation]; -// } -// else{ -// [self.hid getRSSI:completation]; -// } - [[AiMouse shared] getRSSI:completation]; + completation(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 设置CPI - (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] setCPI:value completation:finished]; + [[TlwMouse shared] setDPI:value completation:finished]; } /// 设置品牌名称 @@ -277,12 +276,13 @@ /// - value: 品牌名称 /// - finished: 设置结果回调 - (void)setBrand:(NSString *)brand completation:(void (^)(BOOL isSuccess,NSError *error))finished { - [[AiMouse shared] setBrand:brand completation:finished]; +// [[TlwMouse shared] setBrand:brand completation:finished]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /////设备鉴权 //-(void)startAuthentication { -// if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) { +// if ([TlwMouse shared]].connectType == AiMouseConnectType_bluetooth) { // [self.ble startAuthentication]; // } // else{ @@ -298,51 +298,59 @@ /// 设置录音模式 - (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] setRecordMode:mode completation:finished]; +// [[TlwMouse shared] setRecordMode:mode completation:finished]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 设置长按滚轮弹出的网页地址 - (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] setUrl:url completation:finished]; +// [[TlwMouse shared] setUrl:url completation:finished]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 设置长按滚轮弹出网页开关 - (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] setUrlState:state completation:finished]; +// [[TlwMouse shared] setUrlState:state completation:finished]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 设置鼠标连接模式 - (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] setMouseMode:mode completation:finished]; +// [[TlwMouse shared] setMouseMode:mode completation:finished]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 获取录音模式 -- (void)getRecordMode:(void (^)(int mode,NSError *error))complete{ - [[AiMouse shared] getRecordMode:complete]; +- (void)getRecordMode:(void (^)(int mode,NSError *error))finished{ +// [[TlwMouse shared] getRecordMode:complete]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 获取长按滚轮弹出的网页地址 -- (void)getUrl:(void (^)(NSString *url,NSError *error))complete{ - [[AiMouse shared] getUrl:complete]; +- (void)getUrl:(void (^)(NSString *url,NSError *error))finished{ +// [[TlwMouse shared] getUrl:complete]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 获取长按滚轮弹出的网页地址开关状态 -- (void)getUrlState:(void (^)(int state,NSError *error))complete{ - [[AiMouse shared] getUrlState:complete]; +- (void)getUrlState:(void (^)(int state,NSError *error))finished{ +// [[TlwMouse shared] getUrlState:complete]; + finished(false,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 获取鼠标连接模式 -- (void)getMouseModel:(void (^)(int mode,NSError *error))complete{ - [[AiMouse shared] getMouseModel:complete]; +- (void)getMouseModel:(void (^)(int mode,NSError *error))finished{ +// [[TlwMouse shared] getMouseModel:complete]; + finished(0,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 打开录音 - (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] openRecord:finished]; + [[TlwMouse shared] openRecord:finished]; } /// 关闭录音 - (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - [[AiMouse shared] closeRecord:finished]; + [[TlwMouse shared] closeRecord:finished]; } @end diff --git a/MouseSdk/MouseSdk/Ble/HidManager.h b/MouseSdk/MouseSdk/Ble/HidManager.h index 823ddfa..681424e 100644 --- a/MouseSdk/MouseSdk/Ble/HidManager.h +++ b/MouseSdk/MouseSdk/Ble/HidManager.h @@ -6,11 +6,12 @@ // #import +#import "TlwMouseSdk.h" #import "AiMouseSdk.h" NS_ASSUME_NONNULL_BEGIN -@interface HidManager : NSObject +@interface HidManager : NSObject @property (nonatomic,copy)void (^connectStateCallBack)(BOOL isConnnect);/// 设备是否连上 /// /// diff --git a/MouseSdk/MouseSdk/Ble/HidManager.m b/MouseSdk/MouseSdk/Ble/HidManager.m index 5680d1f..d145387 100644 --- a/MouseSdk/MouseSdk/Ble/HidManager.m +++ b/MouseSdk/MouseSdk/Ble/HidManager.m @@ -11,17 +11,16 @@ #import "BleManager.h" -//供应商id -const long vendorID = 0x6675; -//产品id -const long productID = 0x8601; +////供应商id +//const long vendorID = 0x6675; +////产品id +//const long productID = 0x8601; @interface HidManager () { dispatch_block_t _block; } @property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管理 -@property(nonatomic, assign) IOHIDDeviceRef aiCha;//ai通道 @property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设备信息通道 @property (nonatomic,strong) NSMutableData *recordData;//录音的数据 @end @@ -68,18 +67,21 @@ const long productID = 0x8601; - (void)open{ //初始化 self.deviceInfoCha = nil; - self.aiCha = nil; [self showLog:@"(HidManager)open:打开设备"]; self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode); IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L); if (ret != kIOReturnSuccess) { - [self showLog:(@"(HidManager)open:打开设备失败!")]; + [self showLog:(@"(HidManager)open:打开hid失败!")]; }else{ - [self showLog:(@"(HidManager)open:打开设备成功!")]; + [self showLog:(@"(HidManager)open:打开hid成功!")]; } //设置匹配设备 + //供应商id + const long vendorID = 0x10D6; + //产品id + const long productID = 0xB008; NSMutableDictionary* dict= [NSMutableDictionary dictionary]; [dict setValue:[NSNumber numberWithLong:productID] forKey:[NSString stringWithCString:kIOHIDProductIDKey encoding:NSUTF8StringEncoding]]; [dict setValue:[NSNumber numberWithLong:vendorID] forKey:[NSString stringWithCString:kIOHIDVendorIDKey encoding:NSUTF8StringEncoding]]; @@ -106,7 +108,6 @@ const long productID = 0x8601; } self.deviceInfoCha = nil; - self.aiCha = nil; } #pragma mark - Hid CallBack @@ -116,44 +117,40 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH [[HidManager shared] showLog:(@"(HidManager)hidAppearDevice:当前处于蓝牙连接状态,对监听到有USB 插入 的事件不做处理")]; return; } -// uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey)); -// uint32_t pid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey)); - uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey)); - uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); -// [[HidManager shared] showLog:[NSString stringWithFormat:@"(HidManager)hidAppearDevice : vid = %u, pid = %u, PrimaryUsagePage = %u, PrimaryUsage = %u,",vid,pid,PrimaryUsagePage,PrimaryUsage]]; -// [[HidManager shared] showLog:[NSString stringWithFormat:@"(HidManager)hidAppearDevice : 发现设备 %@\n ",inIOHIDDeviceRef]]; + + - NSString *tmpPrimaryUsagePage = [NSString stringWithFormat:@"%u",PrimaryUsagePage]; - NSString *tmpPrimaryUsage = [NSString stringWithFormat:@"%u",PrimaryUsage]; - if([tmpPrimaryUsagePage isEqualToString:@"1"] && [tmpPrimaryUsage isEqualToString:@"0"]){ -// [[HidManager shared] showLog:(@"(HidManager)hidAppearDevice :设备信息 - 开始鉴权")]; - //设备信息 - [HidManager shared].deviceInfoCha = inIOHIDDeviceRef; -// //开始鉴权 -// [[HidManager shared] startAuthentication]; - - //按照前端要求,他们自己调用鉴权接口,此处只先设置代理和连接类型 - { //设置代理 - [AiMouse shared].delegate = [HidManager shared]; - //切换当前连接类型 - [[AiMouse shared] switchConnect:AiMouseConnectType_hid]; - } + //设备信息 + [HidManager shared].deviceInfoCha = inIOHIDDeviceRef; + [TlwMouse shared].delegate = [HidManager shared]; + //切换当前连接类型 + [[TlwMouse shared] switchConnect:AiMouseConnectType_hid]; - [[HidManager shared] showLog:(@"(HidManager)hidAppearDevice:回调连接成功 ")]; - [[HidManager shared] cancelBlock]; - //连上设备 - if ([HidManager shared].connectStateCallBack != nil) { - [HidManager shared].connectStateCallBack(true); - } - } - else if([tmpPrimaryUsagePage isEqualToString:@"65283"] && [tmpPrimaryUsage isEqualToString:@"0"]){ - [[HidManager shared] showLog:(@"(HidManager)hidAppearDevice :发现ai")]; - //ai - [HidManager shared].aiCha = inIOHIDDeviceRef; + [[HidManager shared] showLog:(@"(HidManager)hidAppearDevice:回调连接成功 ")]; + [[HidManager shared] cancelBlock]; + + //连上设备 + if ([HidManager shared].connectStateCallBack != nil) { + [HidManager shared].connectStateCallBack(true); } //注册消息回调 - unsigned char InputBuffer[128]; + unsigned char InputBuffer[64]; IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL); + + [[HidManager shared] openDiveceAction]; + +} + +- (void)openDiveceAction{ + IOReturn result = IOHIDDeviceOpen([HidManager shared].deviceInfoCha, kIOHIDOptionsTypeNone); + if (result != kIOReturnSuccess) { + NSLog([NSString stringWithFormat:@"打开设备信息失败! %d",result]); + [self performSelector:@selector(openDiveceAction) withObject:nil afterDelay:2]; + }else{ + NSLog(@"打开设备信息成功!"); + } + CFRetain([HidManager shared].deviceInfoCha); + IOHIDDeviceScheduleWithRunLoop([HidManager shared].deviceInfoCha, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); } /// 设备移除回调 @@ -164,26 +161,17 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender, } [[HidManager shared] showLog:[NSString stringWithFormat:@"(HidManager)hidDisAppearDevice:拔出设备 %@ ",inIOHIDDeviceRef]]; - uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey)); - uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); - - NSString *tmpPrimaryUsagePage = [NSString stringWithFormat:@"%u",PrimaryUsagePage]; - NSString *tmpPrimaryUsage = [NSString stringWithFormat:@"%u",PrimaryUsage]; + //取消执行超时操作 + [[HidManager shared] showLog:(@"(HidManager)hidDisAppearDevice:回调连接失败 ")]; + [[HidManager shared] cancelBlock]; + if ([HidManager shared].connectStateCallBack != nil) { + [HidManager shared].connectStateCallBack(false); + } + + [HidManager shared].deviceInfoCha = nil; - if([tmpPrimaryUsagePage isEqualToString:@"1"] && [tmpPrimaryUsage isEqualToString:@"0"]){ - //取消执行超时操作 - [[HidManager shared] showLog:(@"(HidManager)hidDisAppearDevice:回调连接失败 ")]; - [[HidManager shared] cancelBlock]; - if ([HidManager shared].connectStateCallBack != nil) { - [HidManager shared].connectStateCallBack(false); - } - - [HidManager shared].deviceInfoCha = nil; - [HidManager shared].aiCha = nil; - // [[HidManager shared] aiMouseConnectStateDidChange:false]; - [[AiMouse shared] didDisconnect]; - } + [[TlwMouse shared] didDisconnect]; } - (void)cancelBlock { @@ -191,53 +179,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 (report[0] == 0x01 || report[0] == 0x02) { + //鼠标键盘活动事件 + return; + } NSInteger len = get_data_len(report, reportLength); NSData *data = [[NSData alloc] initWithBytes:report length:len]; - uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); - uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); - - if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ - [[HidManager shared] showLog:@"(HidManager)hidReceiveData:device数据"]; - [[AiMouse shared] sendDeviceDataToSdk:data]; - } - else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){ - [[HidManager shared] showLog:@"(HidManager)hidReceiveData:AI数据"]; - [[AiMouse shared] sendAiDataToSdk:data]; - } -} -#pragma mark - AiDelegate - -/// 设备连接状态 -/// - Parameter connected: 是否连接 -- (void)aiMouseConnectStateDidChange:(BOOL)connected { - [self showLog:[NSString stringWithFormat:@"(BleManager) aiMouseConnectStateDidChange - 设备连接状态返回: %hhd",connected]]; + [[HidManager shared] showLog:@"(HidManager)hidReceiveData:device数据"]; + [[TlwMouse shared] sendDeviceDataToSdk:data]; - if (self.aiMouseConnectStateDidChangeCallBack) { - self.aiMouseConnectStateDidChangeCallBack(connected); - } - //没有连接 - if (!connected) { - [HidManager shared].deviceInfoCha = nil; - [HidManager shared].aiCha = nil; - } -} -/// 设备鉴权结果返回 -/// - Parameter authState: 鉴权状态 -- (void)aiMouseAuthenticationResult:(AiMouseAuthState)authState{ - [self showLog:[NSString stringWithFormat:@"(HidManager) aiMouseAuthenticationResult - 设备鉴权结果返回: %ld",(long)authState]]; - - if(self.authCallBack){ - self.authCallBack(authState == AiMouseAuthState_Success); - } } +#pragma mark - TlwMouseDelegate /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 /// - Parameter data: 数据 --(void)aiMouseSendDeviceInfoData:(NSData *)data{ +-(void)tlwMouseSendDeviceInfoData:(NSData *)data{ [self showLog:[NSString stringWithFormat:@"(HidManager)aiMouseSendDeviceInfoData:[send] %@",data]]; [self sendData:data toDevice:self.deviceInfoCha]; if (self.aiMouseSendDeviceInfoDataCallBack) { @@ -247,14 +205,52 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe /// 鼠标按键指令回调 /// - Parameter data: 数据。 -/// 前 第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音) +/// 前 单击0x06, 按下0x13(开始录音)抬起0x14(结束录音) +/// 中 单击0x03, 按下0x11(开始录音)抬起0x12(结束录音) +/// 后 第一次单击0x01, 第二次单击0x02(结束录音) , 按下0x09(开始录音)抬起0x10(结束录音) +/// 其他未定义 +/// +/// /// 鼠标按键指令回调 富瑞坤 +/// - Parameter data: 数据。 +/// 前 单击43,按下27(开始录音)抬起28(结束录音) /// 中 单击42, 按下25(开始录音)抬起26(结束录音) -/// 后 单击43,按下27(开始录音)抬起28(结束录音) +/// 后 第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音) +/// /// 其他未定义 -- (void)aiMouseSendCmdData:(NSData *)data{ +- (void)tlwMouseSendCmdData:(NSData *)data{ uint8 cmd; [data getBytes:&cmd length:1]; - [self showLog:[NSString stringWithFormat:@"(HidManager)aiMouseSendCmdData:收到指令 = %X",cmd]]; + if( cmd == 0x01){ + cmd = 0x31; + }else if( cmd == 0x02){ + cmd = 0x32; + } + else if( cmd == 0x09){ + cmd = 0x21; + } + else if( cmd == 0x10){ + cmd = 0x22; + } + else if( cmd == 0x03){ + cmd = 0x42; + } + else if( cmd == 0x11){ + cmd = 0x25; + } + else if( cmd == 0x12){ + cmd = 0x26; + } + else if( cmd == 0x06){ + cmd = 0x43; + } + else if( cmd == 0x13){ + cmd = 0x27; + } + else if( cmd == 0x14){ + cmd = 0x28; + } + + [self showLog:[NSString stringWithFormat:@"(HidManager) aiMouseSendCmdData:收到指令 = %X",cmd]]; if (self.aiMouseSendCmdDataCallBack) { self.aiMouseSendCmdDataCallBack([NSString stringWithFormat:@"%X",cmd]); @@ -278,22 +274,36 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe } } } + /// 录音回调 /// - Parameter data: pcm格式语音数据 -- (void)aiMouseSendRecordData:(NSData *)data{ +- (void)tlwMouseSendRecordData:(NSData *)data{ [self showLog:[NSString stringWithFormat:@"(HidManager)aiMouseSendRecordData: %@",data]]; [self.recordData appendData:data]; if (self.recordingCallBack) { self.recordingCallBack(data); } } - +/// 输出日志 - (void)aiMouseAddLog:(NSString *)log { if (self.aiMouseAddLogCallBack) { self.aiMouseAddLogCallBack(log); } } +// 连接状态改变 +- (void)tlwMouseConnectStateDidChange:(BOOL)connected{ + [self showLog:[NSString stringWithFormat:@"(HidManager) aiMouseConnectStateDidChange - 设备连接状态返回: %hhd",connected]]; + + if (self.aiMouseConnectStateDidChangeCallBack) { + self.aiMouseConnectStateDidChangeCallBack(connected); + } + //没有连接 + if (!connected) { + [HidManager shared].deviceInfoCha = nil; + } +} + /// hid数据异常,需要重新开启监听usb设备 - (void)hidDataError { //收到数据异常,需要关闭后重新打开 @@ -304,12 +314,12 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe #pragma mark - public //-(void)startAuthentication{ // //设置代理 -// [AiMouse shared].delegate = self; +// [TlwMouse shared].delegate = self; // //切换当前连接类型 -// [[AiMouse shared] switchConnect:AiMouseConnectType_hid]; +// [[TlwMouse shared] switchConnect:AiMouseConnectType_hid]; // //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用 // [self showLog:@"(HidManager)开始鉴权"]; -// [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) { +// [[TlwMouse shared] startAuthentication:^(AiMouseAuthState state) { // [self showLog:[NSString stringWithFormat:@"(HidManager)鉴权结果 = %@",@(state)]]; // if(self.authCallBack){ // self.authCallBack(state == AiMouseAuthState_Success); @@ -319,13 +329,35 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe /// 获取设备信息 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{ [self showLog:@"(HidManager)getDeviceInfo: 获取设备信息"]; - [[AiMouse shared] getDeviceInfo:completation]; + [[TlwMouse shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) { + AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init]; + info.battery_power = [NSString stringWithFormat:@"%d",deviceInfo.batteryValue] ; + info.CPI = [NSString stringWithFormat:@"%d",deviceInfo.DPI]; + info.CPI_list = @"1,2,3,4"; + info.version = [NSString stringWithFormat:@"%d",deviceInfo.version]; + info.brand = @""; + info.sn = @""; + info.mac = @""; + completation(info,nil); +// @property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应 800 1200 1800 2400) +// @property (nonatomic, assign) int version;///软件版本 +// @property (nonatomic, assign) int batteryState;/// 电池状态 +// @property (nonatomic, assign) int batteryValue;/// 电池百分百电量,0-100 +// /// +// @property (nonatomic, strong) NSString *battery_power;/// 电池百分百电量,0-100 +// @property (nonatomic, strong) NSString *CPI;/// CPI值 +// @property (nonatomic, strong) NSString *CPI_list;/// 可设置的CPI参数列表 +// @property (nonatomic, strong) NSString *version;///软件版本 +// @property (nonatomic, strong) NSString *brand;/// 品牌名称 +// @property (nonatomic, strong) NSString *sn;/// 设备序列号 +// @property (nonatomic, strong) NSString *mac;///设备MAC地址 + }]; } /// 获取信号强度 -- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete { +- (void)getRSSI:(void (^)(NSString *value,NSError *error))finished { [self showLog:[NSString stringWithFormat:@"(HidManager) getRSSI:获取信号强度"]]; - [[AiMouse shared] getRSSI:complete]; + finished(0,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}]); } /// 发送数据给设备 @@ -357,7 +389,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe } - (void)showLog:(NSString *)log{ -// NSLog(@"%@",log); + NSLog(@"%@",log); } /// 实际到数据长度 diff --git a/MouseSdk/MouseSdk/FrkVC.m b/MouseSdk/MouseSdk/FrkVC.m index 1d32bd2..8acb8ea 100644 --- a/MouseSdk/MouseSdk/FrkVC.m +++ b/MouseSdk/MouseSdk/FrkVC.m @@ -173,9 +173,13 @@ // [ws connectStateDidChange:type connectState:isConnected]; // }; - [manager begainMonitorAiMouseConnectStateDidChange:@"VMouse" callBack:^(int connectType, BOOL connected) { +// [manager begainMonitorAiMouseConnectStateDidChange:@"VMouse" callBack:^(int connectType, BOOL connected) { +// [ws connectStateDidChange:connectType connectState:connected]; +// }]; + [manager begainMonitorAiMouseConnectStateDidChange:@"NMMouse" callBack:^(int connectType, BOOL connected) { [ws connectStateDidChange:connectType connectState:connected]; }]; + } - (void)moreAction:(NSButton *)sender { diff --git a/MouseSdk/MouseSdk/Tlw/TlwBleManager.m b/MouseSdk/MouseSdk/Tlw/TlwBleManager.m index a815010..f480817 100644 --- a/MouseSdk/MouseSdk/Tlw/TlwBleManager.m +++ b/MouseSdk/MouseSdk/Tlw/TlwBleManager.m @@ -121,7 +121,7 @@ //切换代理 [TlwMouse shared].delegate = self; //切换当前连接类型 - [[TlwMouse shared] switchConnect:TlwConnectType_bluetooth]; + [[TlwMouse shared] switchConnect:AiMouseConnectType_bluetooth]; } } } diff --git a/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.h b/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.h index c3641a0..16a22d0 100644 --- a/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.h +++ b/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.h @@ -11,14 +11,14 @@ NS_ASSUME_NONNULL_BEGIN @interface TlwDeviceManger : NSObject -@property (nonatomic, readonly) TlwConnectType connectType;//连接类型 -@property (nonatomic,strong)void (^connectStateCallBack)(TlwConnectType connectType,BOOL isConnect);///是否连接成功 +@property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型 +@property (nonatomic,strong)void (^connectStateCallBack)(AiMouseConnectType connectType,BOOL isConnect);///是否连接成功 +(TlwDeviceManger *)shared; /// 切换连接类型 /// - Parameter type: 连接类型 -- (void)switchConnect:(TlwConnectType)type; +- (void)switchConnect:(AiMouseConnectType)type; /// 获取设备信息 - (void)getDeviceInfo:(void (^)(TlwDeviceInfo *deviceInfo,NSError *error))finished; diff --git a/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.m b/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.m index 5f5c3b4..78118ee 100644 --- a/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.m +++ b/MouseSdk/MouseSdk/Tlw/TlwDeviceManger.m @@ -35,14 +35,14 @@ return self; } --(TlwConnectType)connectType{ +-(AiMouseConnectType)connectType{ return [TlwMouse shared].connectType; } -- (void)switchConnect:(TlwConnectType)type{ +- (void)switchConnect:(AiMouseConnectType)type{ [[TlwMouse shared] switchConnect:type]; - if ([TlwMouse shared].connectType == TlwConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { [self setupBle]; } else{ @@ -54,7 +54,7 @@ self.hid = [TlwHidManager shared]; __weak typeof(self) ws = self; self.hid.connectStateCallBack = ^(BOOL isConnnect) { - if(ws.connectStateCallBack)ws.connectStateCallBack(TlwConnectType_hid,isConnnect); + if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_hid,isConnnect); }; } @@ -62,16 +62,16 @@ self.ble = [TlwBleManager shared]; __weak typeof(self) ws = self; self.ble.didConnectDevice = ^(CBPeripheral *peripheral) { - if(ws.connectStateCallBack)ws.connectStateCallBack(TlwConnectType_bluetooth,true); + if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_bluetooth,true); }; self.ble.didDisConnectDevice = ^(CBPeripheral *peripheral) { - if(ws.connectStateCallBack)ws.connectStateCallBack(TlwConnectType_bluetooth,false); + if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_bluetooth,false); }; [self setupBleNotification]; } - (void)getDeviceInfo:(void (^)(TlwDeviceInfo *deviceInfo,NSError *error))finished{ - if ([TlwMouse shared].connectType == TlwConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { [self.ble getDeviceInfo:finished]; } else{ @@ -81,7 +81,7 @@ /// setDPI - (void)setDPI:(int)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{ - if ([TlwMouse shared].connectType == TlwConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { [self.ble setDPI:value completation:finished]; } else{ @@ -91,7 +91,7 @@ /// 打开录音 - (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - if ([TlwMouse shared].connectType == TlwConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { [self.ble openRecord:finished]; } else{ @@ -100,7 +100,7 @@ } /// 停止录音 - (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ - if ([TlwMouse shared].connectType == TlwConnectType_bluetooth) { + if ([TlwMouse shared].connectType == AiMouseConnectType_bluetooth) { [self.ble closeRecord:finished]; } else{ @@ -114,12 +114,12 @@ } - (void)bleDidConnect:(NSNotification *)notification{ - if(self.connectStateCallBack)self.connectStateCallBack(TlwConnectType_bluetooth,true); + if(self.connectStateCallBack)self.connectStateCallBack(AiMouseConnectType_bluetooth,true); } - (void)bleDidDisconnect:(NSNotification *)notification{ - if(self.connectStateCallBack)self.connectStateCallBack(TlwConnectType_bluetooth,false); - [[TlwMouse shared] switchConnect:TlwConnectType_hid]; + if(self.connectStateCallBack)self.connectStateCallBack(AiMouseConnectType_bluetooth,false); + [[TlwMouse shared] switchConnect:AiMouseConnectType_hid]; } @end diff --git a/MouseSdk/MouseSdk/Tlw/TlwHidManager.m b/MouseSdk/MouseSdk/Tlw/TlwHidManager.m index 721653a..23b9d6d 100644 --- a/MouseSdk/MouseSdk/Tlw/TlwHidManager.m +++ b/MouseSdk/MouseSdk/Tlw/TlwHidManager.m @@ -186,7 +186,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe //设置代理 [TlwMouse shared].delegate = self; //切换当前连接类型 - [[TlwMouse shared] switchConnect:TlwConnectType_hid]; + [[TlwMouse shared] switchConnect:AiMouseConnectType_hid]; } /// 发送数据给设备 diff --git a/MouseSdk/MouseSdk/TlwVC.m b/MouseSdk/MouseSdk/TlwVC.m index 03659fb..a66b79c 100644 --- a/MouseSdk/MouseSdk/TlwVC.m +++ b/MouseSdk/MouseSdk/TlwVC.m @@ -1,13 +1,198 @@ +//// +//// TlwVC.m +//// MouseSdk +//// +//// Created by incar on 2024/8/21. +//// // -// TlwVC.m -// MouseSdk +//#import "TlwVC.h" +//#import "TlwScanVC.h" +//#import "TlwDeviceManger.h" // -// Created by incar on 2024/8/21. +//@interface TlwVC () +//@property(nonatomic,strong)NSTextField *typeLabel;///当前模式状态 +//@property(nonatomic,strong)NSTextField *connectLabel;///连接状态 +//@property(nonatomic,strong)NSTextField *authLabel;///鉴权状态 +//@property(nonatomic,strong)NSTextField *deviceInfoLabel;///设备信息 +//@end // - +//@implementation TlwVC +// +////-(instancetype)init{ +//// if (self = [super init]) { +//// +//// } +//// return self; +////} +// +//-(void)dealloc{ +//// [[TlwDeviceManger shared] stop]; +//} +// +//- (void)viewDidLoad { +// [super viewDidLoad]; +// +// // Do any additional setup after loading the view. +// +// [self setupUI]; +// [self setupTlwDeviceManger]; +//} +// +//- (void)loadView{ +// self.view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; +//} +// +//- (void)setupUI{ +// CALayer *viewLayer = [CALayer layer]; +// NSView *backgroundView= [[NSView alloc]init]; +// [backgroundView setWantsLayer:YES]; +// [backgroundView setLayer:viewLayer]; +// backgroundView.layer.backgroundColor = [NSColor greenColor].CGColor; +// [backgroundView setNeedsDisplay:YES]; +// [self.view addSubview:backgroundView]; +// self.title = @"AI SDK"; +// { +// NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 80, 100, 45)]; +// btn.bordered = true; +// btn.title = @"蓝牙扫描"; +// [btn setTarget:self]; +// [btn setAction:@selector(scanAction)]; +// btn.state = 1; +// [self.view addSubview:btn]; +// } +// { +// NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 180, 100, 45)]; +// btn.bordered = true; +// btn.title = @"选择指令"; +// [btn setTarget:self]; +// [btn setAction:@selector(showPopupMenu:)]; +// +// btn.state = 1; +// [self.view addSubview:btn]; +// } +// { +// NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 80, 300, 35)]; +// label.editable = NO; +// label.bordered = NO; +// label.stringValue = @"连接模式:--"; +// label.backgroundColor = NSColor.clearColor; +// self.typeLabel = label; +// [self.view addSubview:label]; +// } +// { +// NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 120, 300, 35)]; +// label.editable = NO; +// label.bordered = NO; +// label.stringValue = @"连接状态:未连接"; +// label.backgroundColor = NSColor.clearColor; +// self.connectLabel = label; +// [self.view addSubview:label]; +// } +// { +// NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 160, 300, 35)]; +// label.editable = NO; +// label.bordered = NO; +// label.stringValue = @"鉴权状态:unknow"; +// label.backgroundColor = NSColor.clearColor; +// self.authLabel = label; +// [self.view addSubview:label]; +// } +// { +// NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 260, 300, 100)]; +// label.editable = NO; +// label.bordered = NO; +// label.stringValue = @""; +// label.backgroundColor = NSColor.clearColor; +// self.deviceInfoLabel = label; +// [self.view addSubview:label]; +// } +//} +// +//#pragma mark - action +//- (void)scanAction{ +// TlwScanVC *vc = [[TlwScanVC alloc] initWithNibName:nil bundle:nil]; +// [self presentViewControllerAsModalWindow:vc]; +//} +// +//- (void)connectStateDidChange:(AiMouseConnectType)type connectState:(BOOL)isConnected{ +// dispatch_async(dispatch_get_main_queue(), ^{ +// if(isConnected){ +// self.typeLabel.stringValue = type == AiMouseConnectType_bluetooth ?@"连接模式:蓝牙":@"连接模式:hid"; +// self.connectLabel.stringValue = isConnected?@"连接状态:已连接":@"连接状态:未连接"; +// } +// else{ +// self.typeLabel.stringValue = @"连接模式:--"; +// self.connectLabel.stringValue = @"连接状态:未连接"; +// } +// }); +//} +// +//- (void)setupTlwDeviceManger{ +// TlwDeviceManger *manager = [TlwDeviceManger shared]; +//// [manager start]; +// __weak typeof(self) ws = self; +// manager.connectStateCallBack = ^(AiMouseConnectType type,BOOL isConnected) { +// [ws connectStateDidChange:type connectState:isConnected]; +// }; +//} +// +// +//- (void)showPopupMenu:(NSButton *)sender { +// NSMenu *popupMenu = [[NSMenu alloc] initWithTitle:@"Popup Menu"]; +// NSMenuItem *item1 = [[NSMenuItem alloc] initWithTitle:@"语音开启" action:@selector(voiceStart:) keyEquivalent:@"1"]; +// NSMenuItem *item2 = [[NSMenuItem alloc] initWithTitle:@"语音停止" action:@selector(voiceStop:) keyEquivalent:@"2"]; +// NSMenuItem *item3 = [[NSMenuItem alloc] initWithTitle:@"设置DPI" action:@selector(setDPI:) keyEquivalent:@"3"]; +// NSMenuItem *item4 = [[NSMenuItem alloc] initWithTitle:@"鼠标状态查询" action:@selector(searchState:) keyEquivalent:@"3"]; +//// NSMenuItem *item5 = [[NSMenuItem alloc] initWithTitle:@"向鼠标告知APP下载地址" action:@selector(setDownLoadURL:) keyEquivalent:@"3"]; +//// NSMenuItem *item8 = [[NSMenuItem alloc] initWithTitle:@":读取鼠标序列号" action:@selector(getSN:) keyEquivalent:@"3"]; +//// NSMenuItem *item9 = [[NSMenuItem alloc] initWithTitle:@":发送弹UR开关命令" action:@selector(sendUR:) keyEquivalent:@"3"]; +// +// [popupMenu addItem:item1]; +// [popupMenu addItem:item2]; +// [popupMenu addItem:item3]; +// [popupMenu addItem:item4]; +// +// NSPoint buttonLocation = [sender convertPoint:NSZeroPoint toView:self.view]; +// [popupMenu popUpMenuPositioningItem:nil atLocation:buttonLocation inView:self.view]; +//} +// +//- (void)voiceStart:(NSMenuItem*)sender { +// [[TlwDeviceManger shared] openRecord:^(BOOL isSuccess, NSError * _Nonnull error) { +// +// }]; +//} +//- (void)voiceStop:(NSMenuItem*)sender { +// [[TlwDeviceManger shared] closeRecord:^(BOOL isSuccess, NSError * _Nonnull error) { +// +// }]; +//} +//- (void)setDPI:(NSMenuItem*)sender { +// [[TlwDeviceManger shared] setDPI:2 completation:^(BOOL isSuccess, NSError * _Nonnull error) { +// +// }]; +//} +//- (void)searchState:(NSMenuItem*)sender { +// [[TlwDeviceManger shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) { +//// if (deviceInfo) { +//// NSString *info = deviceInfo.description; +//// dispatch_async(dispatch_get_main_queue(), ^{ +//// self.deviceInfoLabel.stringValue = info; +//// }); +//// } +//// else{ +//// NSString *info = [NSString stringWithFormat:@"error == %@",error.description]; +//// NSLog(@"%@",info); +//// dispatch_async(dispatch_get_main_queue(), ^{ +//// self.deviceInfoLabel.stringValue = info; +//// }); +//// } +// }]; +//} +// +//@end #import "TlwVC.h" -#import "TlwScanVC.h" -#import "TlwDeviceManger.h" +#import "ScanVC.h" +#import "DeviceManger.h" @interface TlwVC () @property(nonatomic,strong)NSTextField *typeLabel;///当前模式状态 @@ -18,24 +203,24 @@ @implementation TlwVC -//-(instancetype)init{ -// if (self = [super init]) { -// -// } -// return self; -//} +-(instancetype)init{ + if (self = [super init]) { +// [[DeviceManger shared] start]; + } + return self; +} -(void)dealloc{ -// [[TlwDeviceManger shared] stop]; +// [[DeviceManger shared] stop]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. - +// [[DeviceManger shared] start]; [self setupUI]; - [self setupTlwDeviceManger]; + [self setupDeviceManger]; } - (void)loadView{ @@ -50,6 +235,7 @@ backgroundView.layer.backgroundColor = [NSColor greenColor].CGColor; [backgroundView setNeedsDisplay:YES]; [self.view addSubview:backgroundView]; + self.title = @"AI SDK"; { NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 80, 100, 45)]; @@ -63,10 +249,18 @@ { NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 180, 100, 45)]; btn.bordered = true; - btn.title = @"选择指令"; + btn.title = @"获取设备信息"; [btn setTarget:self]; - [btn setAction:@selector(showPopupMenu:)]; - + [btn setAction:@selector(geviceInfoAction)]; + btn.state = 1; + [self.view addSubview:btn]; + } + { + NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 280, 100, 45)]; + btn.bordered = true; + btn.title = @"更多指令"; + [btn setTarget:self]; + [btn setAction:@selector(moreAction:)]; btn.state = 1; [self.view addSubview:btn]; } @@ -110,15 +304,42 @@ #pragma mark - action - (void)scanAction{ - TlwScanVC *vc = [[TlwScanVC alloc] initWithNibName:nil bundle:nil]; + ScanVC *vc = [[ScanVC alloc] initWithNibName:nil bundle:nil]; [self presentViewControllerAsModalWindow:vc]; } -- (void)connectStateDidChange:(TlwConnectType)type connectState:(BOOL)isConnected{ +/// 获取设备信息 +- (void)geviceInfoAction{ + [[DeviceManger shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) { + if (deviceInfo) { + NSString *info = deviceInfo.description; + dispatch_async(dispatch_get_main_queue(), ^{ + self.deviceInfoLabel.stringValue = info; + }); + } + else{ + NSString *info = [NSString stringWithFormat:@"error == %@",error.description]; + NSLog(@"%@",info); + dispatch_async(dispatch_get_main_queue(), ^{ + self.deviceInfoLabel.stringValue = info; + }); + } + }]; +} +- (void)showAuthResult:(BOOL)isSuccess{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.authLabel.stringValue = isSuccess?@"鉴权状态:鉴权成功":@"鉴权状态:鉴权失败"; + if(isSuccess){ + [self geviceInfoAction]; + } + }); +} +- (void)connectStateDidChange:(AiMouseConnectType)type connectState:(BOOL)isConnected{ dispatch_async(dispatch_get_main_queue(), ^{ if(isConnected){ - self.typeLabel.stringValue = type == TlwConnectType_bluetooth ?@"连接模式:蓝牙":@"连接模式:hid"; + self.typeLabel.stringValue = type == AiMouseConnectType_bluetooth ?@"连接模式:蓝牙":@"连接模式:hid"; self.connectLabel.stringValue = isConnected?@"连接状态:已连接":@"连接状态:未连接"; + [self geviceInfoAction]; } else{ self.typeLabel.stringValue = @"连接模式:--"; @@ -127,25 +348,27 @@ }); } -- (void)setupTlwDeviceManger{ - TlwDeviceManger *manager = [TlwDeviceManger shared]; -// [manager start]; +- (void)setupDeviceManger{ + DeviceManger *manager = [DeviceManger shared]; __weak typeof(self) ws = self; - manager.connectStateCallBack = ^(TlwConnectType type,BOOL isConnected) { - [ws connectStateDidChange:type connectState:isConnected]; + manager.authCallBack = ^(BOOL isSuccess) { + [ws showAuthResult:isSuccess]; }; +// manager.connectStateCallBack = ^(AiMouseConnectType type,BOOL isConnected) { +// [ws connectStateDidChange:type connectState:isConnected]; +// }; + + [manager begainMonitorAiMouseConnectStateDidChange:@"VMouse" callBack:^(int connectType, BOOL connected) { + [ws connectStateDidChange:connectType connectState:connected]; + }]; } - -- (void)showPopupMenu:(NSButton *)sender { +- (void)moreAction:(NSButton *)sender { NSMenu *popupMenu = [[NSMenu alloc] initWithTitle:@"Popup Menu"]; NSMenuItem *item1 = [[NSMenuItem alloc] initWithTitle:@"语音开启" action:@selector(voiceStart:) keyEquivalent:@"1"]; NSMenuItem *item2 = [[NSMenuItem alloc] initWithTitle:@"语音停止" action:@selector(voiceStop:) keyEquivalent:@"2"]; NSMenuItem *item3 = [[NSMenuItem alloc] initWithTitle:@"设置DPI" action:@selector(setDPI:) keyEquivalent:@"3"]; NSMenuItem *item4 = [[NSMenuItem alloc] initWithTitle:@"鼠标状态查询" action:@selector(searchState:) keyEquivalent:@"3"]; -// NSMenuItem *item5 = [[NSMenuItem alloc] initWithTitle:@"向鼠标告知APP下载地址" action:@selector(setDownLoadURL:) keyEquivalent:@"3"]; -// NSMenuItem *item8 = [[NSMenuItem alloc] initWithTitle:@":读取鼠标序列号" action:@selector(getSN:) keyEquivalent:@"3"]; -// NSMenuItem *item9 = [[NSMenuItem alloc] initWithTitle:@":发送弹UR开关命令" action:@selector(sendUR:) keyEquivalent:@"3"]; [popupMenu addItem:item1]; [popupMenu addItem:item2]; @@ -157,36 +380,35 @@ } - (void)voiceStart:(NSMenuItem*)sender { - [[TlwDeviceManger shared] openRecord:^(BOOL isSuccess, NSError * _Nonnull error) { + [[DeviceManger shared] openRecord:^(BOOL isSuccess, NSError * _Nonnull error) { }]; } - (void)voiceStop:(NSMenuItem*)sender { - [[TlwDeviceManger shared] closeRecord:^(BOOL isSuccess, NSError * _Nonnull error) { + [[DeviceManger shared] closeRecord:^(BOOL isSuccess, NSError * _Nonnull error) { }]; } - (void)setDPI:(NSMenuItem*)sender { - [[TlwDeviceManger shared] setDPI:2 completation:^(BOOL isSuccess, NSError * _Nonnull error) { + [[DeviceManger shared] setCPI:2 completation:^(BOOL isSuccess, NSError * _Nonnull error) { }]; } - (void)searchState:(NSMenuItem*)sender { - [[TlwDeviceManger shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) { -// if (deviceInfo) { -// NSString *info = deviceInfo.description; -// dispatch_async(dispatch_get_main_queue(), ^{ -// self.deviceInfoLabel.stringValue = info; -// }); -// } -// else{ -// NSString *info = [NSString stringWithFormat:@"error == %@",error.description]; -// NSLog(@"%@",info); -// dispatch_async(dispatch_get_main_queue(), ^{ -// self.deviceInfoLabel.stringValue = info; -// }); -// } + [[DeviceManger shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) { + if (deviceInfo) { + NSString *info = deviceInfo.description; + dispatch_async(dispatch_get_main_queue(), ^{ + self.deviceInfoLabel.stringValue = info; + }); + } + else{ + NSString *info = [NSString stringWithFormat:@"error == %@",error.description]; + NSLog(@"%@",info); + dispatch_async(dispatch_get_main_queue(), ^{ + self.deviceInfoLabel.stringValue = info; + }); + } }]; } - @end diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m index 4b89781..ca849f7 100644 --- a/MouseSdk/MouseSdk/ViewController.m +++ b/MouseSdk/MouseSdk/ViewController.m @@ -53,7 +53,7 @@ #pragma mark - action - (void)frkAction{ -// [HidManager shared]; + [HidManager shared]; // return; FrkVC *vc = [[FrkVC alloc] initWithNibName:nil bundle:nil]; [self presentViewControllerAsModalWindow:vc];