泰凌微usb、蓝牙模式调试、输出初始版本给千寻
authorliangzhenying <867174124@qq.com>
Wed, 28 Aug 2024 07:00:51 +0000 (15:00 +0800)
committerliangzhenying <867174124@qq.com>
Wed, 28 Aug 2024 07:00:51 +0000 (15:00 +0800)
MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwRecordManager.m
MouseSdk/MouseSdk.xcodeproj/project.pbxproj
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
MouseSdk/MouseSdk/Ble/BleManager.m
MouseSdk/MouseSdk/Ble/DeviceManger.m
MouseSdk/MouseSdk/Ble/HidManager.m
MouseSdk/MouseSdk/Ble/TimerManager.m

index 60051b2..a53d202 100644 (file)
@@ -3,7 +3,7 @@
        archiveVersion = 1;
        classes = {
        };
-       objectVersion = 55;
+       objectVersion = 56;
        objects = {
 
 /* Begin PBXBuildFile section */
                                };
                        };
                        buildConfigurationList = 180E7AA12BD7BB12008558E8 /* Build configuration list for PBXProject "AiMouseSdk" */;
-                       compatibilityVersion = "Xcode 13.0";
+                       compatibilityVersion = "Xcode 14.0";
                        developmentRegion = en;
                        hasScannedForEncodings = 0;
                        knownRegions = (
index bfde2e6..04716c4 100644 (file)
     return _recordManager;
 }
 
--(TlwConnectManager *)connectManager{
-    if (!_connectManager) {
-        _connectManager = [[TlwConnectManager alloc] init];
-        _connectManager.delegate = self;
-    }
-    return _connectManager;
-}
+//-(TlwConnectManager *)connectManager{
+//    if (!_connectManager) {
+//        _connectManager = [[TlwConnectManager alloc] init];
+//        _connectManager.delegate = self;
+//    }
+//    return _connectManager;
+//}
 
 #pragma mark - pub Api
 - (void)setLogLevel:(TlwMouseLogLevel)level{
     _connected = isConneted;
     if (isConneted) {
         _connectType = type;
+        [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"];
     }
-//    [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"];
     [self TlwConnectManager:self.connectManager connectStateDidChange:isConneted];
 
     if (type == AiMouseConnectType_hid && isConneted) {
 - (void)sendAiDataToSdk:(NSData *)data{
     [self.connectManager resetTimeOut];
     
-    [self showLog:[NSString stringWithFormat:@"[receive][Ai] %@",data]];
+    [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]];
     if(self.connectType == AiMouseConnectType_hid){
-////        0AFFFF12BC32
-//        if(data.length == 6){
-//            NSData *subData = [data subdataWithRange:NSMakeRange(5, 1)];
-//            [self sendCmdData:subData];
-//            uint8 cmd;
-//            [subData getBytes:&cmd length:1];
-////            [self showLog:[NSString stringWithFormat:@"cmd = %X",cmdInt]];
-//            if(cmd == 0x31 || cmd == 0x21 || cmd == 0x25 ||cmd == 0x27){
-//                self.recordManager.startCmd = subData;
-//                [self startRecord];
-//            }
-//            else if(cmd == 0x32 || cmd == 0x22 || cmd == 0x26 ||cmd == 0x28){
-//                [self stopRecord:false];
-//            }
-//        }
-//        else{
-//            [self showLog:@"未实现指令"];
-//        }
     }
     else if (self.connectType == AiMouseConnectType_bluetooth){
         [self bleReceiveAiData:data];
index 7b3bf47..24e06b1 100644 (file)
 }
 
 - (void)showLog:(NSString *)log{
-//    NSLog(@"%@",log);
+    NSLog(@"%@",log);
 }
 
 //将录音数据保存
index b4f9ef1..0eff9b0 100644 (file)
@@ -3,7 +3,7 @@
        archiveVersion = 1;
        classes = {
        };
-       objectVersion = 55;
+       objectVersion = 56;
        objects = {
 
 /* Begin PBXBuildFile section */
                                };
                        };
                        buildConfigurationList = 18BF1DC52B81AB7C00B8D90F /* Build configuration list for PBXProject "MouseSdk" */;
-                       compatibilityVersion = "Xcode 13.0";
+                       compatibilityVersion = "Xcode 14.0";
                        developmentRegion = en;
                        hasScannedForEncodings = 0;
                        knownRegions = (
index 900de24..f9860c2 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index 8d38756..05a7ad8 100644 (file)
             filePath = "MouseSdk/Ble/DeviceManger.m"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "256"
-            endingLineNumber = "256"
+            startingLineNumber = "251"
+            endingLineNumber = "251"
             landmarkName = "-tlwMouseSendDeviceInfoData:"
             landmarkType = "7">
          </BreakpointContent>
index 23f090e..be15414 100644 (file)
     if (self.deviceInfoCha ==nil) {
         return;
     }
-//    [self showLog:[NSString stringWithFormat:@"向蓝牙设备发送数据 %@",data]];
+    [self showLog:[NSString stringWithFormat:@"向蓝牙设备发送数据 %@",data]];
     [self.crrentPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithResponse];
 }
 
index 9105a5b..b8e24af 100644 (file)
 #import "TimerManager.h"
 
 @interface DeviceManger()<TlwMouseDelegate>
+
+@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
 @property (nonatomic,strong) NSMutableData *recordData;//录音的数据
 @property (nonatomic,strong) BleManager *ble;
 @property (nonatomic,strong) HidManager *hid;
+@property (nonatomic,strong) NSString *mouseName;
 //connectType 返回为0代表蓝牙,为1代表usb
 @property (nonatomic, copy)void (^aiMouseConnectStateDidChangeCallBack)(int connectType, BOOL connected);/// 设备连接状态回调
 @end
 - (instancetype)init{
     self = [super init];
     if (self) {
+        [[TlwMouse shared] setDelegate:self];
         [self setupBle];
         [self setupHid];
-        
-        //先默认设置蓝牙管理对象为鼠标
-        [[TlwMouse shared] setDelegate:self];
+        [self setupTimer];
     }
     return self;
 }
 }
 
 #pragma mark ------ 设备初始化
+- (void)setupTimer{
+    [TimerManager shared].timerCallBack = ^{
+        [self showLog:@"timer action。。。"];
+        if([TlwMouse shared].connected){
+            [self.ble stopScan];
+//            [self.hid close];
+        }
+        else{
+            if(self.mouseName.length > 0 ) {
+                [self.ble startScanWithName:self.mouseName];
+                [self.hid open];
+            }
+        }
+    };
+}
 - (void)setupHid{
     self.hid = [HidManager shared];
     __weak typeof(self) ws = self;
     
     self.hid.connectStateCallBack = ^(BOOL connected) {
+        if (connected) {
+            [ws.ble stopScan];
+        }
         [[TlwMouse shared] switchConnect:AiMouseConnectType_hid isConnected:connected];
-//        if (connected) {
-//            [[TlwMouse shared] switchConnect:AiMouseConnectType_hid isConnected:connected];
-//        }
-//        else{
-//            if ([TlwMouse shared].connectType ==  AiMouseConnectType_hid && [TlwMouse shared].connected){
-//                [[TlwMouse shared] switchConnect:AiMouseConnectType_hid isConnected:false];
-//            }
-//        }
-//        
-//       if(ws.authCallBack && connected)ws.authCallBack(true);
-//        if (ws.aiMouseConnectStateDidChangeCallBack) {
-//            ws.aiMouseConnectStateDidChangeCallBack(AiMouseConnectType_hid,connected);
-//        }
+        
     };
     self.hid.receiveInfoDataCallBack = ^(NSData *data) {
         [[TlwMouse shared] sendDeviceDataToSdk:data];
     __weak typeof(self) ws = self;
     
     self.ble.connectStateCallBack = ^(BOOL connected) {
-        
+        if (connected) {
+            [ws.hid close];
+        }
         [[TlwMouse shared] switchConnect:AiMouseConnectType_bluetooth isConnected:connected];
-        
-//       if(ws.authCallBack && connected)ws.authCallBack(true);
-//        if (ws.aiMouseConnectStateDidChangeCallBack) {
-//            ws.aiMouseConnectStateDidChangeCallBack(AiMouseConnectType_bluetooth,connected);
-//        }
     };
     self.ble.receiveInfoDataCallBack = ^(NSData *data) {
         [[TlwMouse shared] sendDeviceDataToSdk:data];
 
 - (void)begainMonitorAiMouseConnectStateDidChange:(NSString *)mouseName callBack:(void(^)(int connectType, BOOL connected))callBack{
     self.aiMouseConnectStateDidChangeCallBack = callBack;
-    [self.ble startScanWithName:mouseName];
-    
-    [TimerManager shared].timerCallBack = ^{
-        [self showLog:@"timer action。。。"];
-        if([TlwMouse shared].connected){
-            [self.ble stopScan];
-//            [self.hid close];
-        }
-        else{
-            [self.ble startScanWithName:mouseName];
-            [self.hid open];
-        }
-    };
+    self.mouseName = mouseName;
 }
 ///获取设备信息
 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation{
+    [self showLog:@"getDeviceInfo request"];
     [[TlwMouse shared] getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) {
         
         NSString *CPI_list = @"800,1200,1800,2400";// 1-4,800 1200 1800 2400
         info.brand = @"NNMouse";
         info.sn = @"MSCL1BKZ12105000042371";
         info.mac = @"C0310000A583";
+        self.deviceInfo = info;
         
         [self showLog:info.description];
         completation(info,nil);
         [self.hid writeToDevice:data];
     }
     
-    if (self.aiMouseSendDeviceInfoDataCallBack) {
-        // 将NSData转换为Base64编码的字符串
-        NSString *base64String = [data base64EncodedStringWithOptions:0];
-        self.aiMouseSendDeviceInfoDataCallBack(base64String);
-    }
+//    if (self.aiMouseSendDeviceInfoDataCallBack) {
+//        // 将NSData转换为Base64编码的字符串
+//        NSString *base64String = [data base64EncodedStringWithOptions:0];
+//        self.aiMouseSendDeviceInfoDataCallBack(base64String);
+//    }
 }
 
 /// 鼠标按键指令回调
index b4e3d91..8355256 100644 (file)
@@ -56,7 +56,6 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH
 
 /// 设备移除回调
 static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
-    
     [[HidManager shared] showLog:[NSString stringWithFormat:@"拔出设备 %@ ",inIOHIDDeviceRef]];
     [HidManager shared].deviceInfoCha = nil;
     [HidManager shared].connectStateCallBack(false) ;
@@ -64,7 +63,6 @@ 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){
-//     [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理前 %@",[[HidManager shared] dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]];
     if (report[0] == 0x01 || report[0] == 0x02) {
         //鼠标键盘活动事件
         return;
@@ -78,14 +76,6 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     [HidManager shared].receiveInfoDataCallBack(data);
 }
 
-
-///// hid数据异常,需要重新开启监听usb设备
-//- (void)hidDataError {
-//    //收到数据异常,需要关闭后重新打开
-//    [self close];
-//    [self open];
-//}
-
 #pragma mark - public
 - (void)open{
     [self close];
index ced8f49..9401170 100644 (file)
@@ -28,7 +28,7 @@
 #pragma mark - timer
 - (void)addSendTimer{
     dispatch_async(dispatch_queue_create("timeoutQueue", DISPATCH_QUEUE_SERIAL), ^{
-        self.timer = [NSTimer timerWithTimeInterval:5 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
+        self.timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
         [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
         [[NSRunLoop currentRunLoop] run];
     });