自动识别连接模式
authorliangzhenying <867174124@qq.com>
Sat, 30 Mar 2024 07:57:53 +0000 (15:57 +0800)
committerliangzhenying <867174124@qq.com>
Sat, 30 Mar 2024 07:57:53 +0000 (15:57 +0800)
12 files changed:
MouseSdk/AiMouseSdk/AiMouse.h
MouseSdk/AiMouseSdk/AiMouse.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/BleManager.h
MouseSdk/MouseSdk/BleManager.m
MouseSdk/MouseSdk/DeviceManger.h [new file with mode: 0644]
MouseSdk/MouseSdk/DeviceManger.m [new file with mode: 0644]
MouseSdk/MouseSdk/HidManager.h
MouseSdk/MouseSdk/HidManager.m
MouseSdk/MouseSdk/ViewController.m

index 9f3f9a2..a5e4b9b 100644 (file)
@@ -10,7 +10,7 @@
 
 typedef NS_ENUM(NSInteger,AiMouseConnectType) {
     AiMouseConnectType_bluetooth = 0,///蓝牙
-    AiMouseConnectType_usb,///usb
+    AiMouseConnectType_hid,///hid
 };
 
 typedef NS_ENUM(NSInteger,AiMouseAuthState) {
index 897d041..25892f5 100644 (file)
     _connectType = type;
     [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"];
     
-    if (type == AiMouseConnectType_usb) {
+    if (type == AiMouseConnectType_hid) {
         [self.recordManager checkPermissions];
     }
 }
 }
 
 - (void)sendAiDataToSdk:(NSData *)data{
-    if(self.connectType == AiMouseConnectType_usb){
+    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]];
         }
     }
     else if (self.connectType == AiMouseConnectType_bluetooth){
-        NSString *str = [[AiMouseTools dataToHexString:data] lowercaseString];
-        NSString *cmd = [str substringWithRange:NSMakeRange(0, 12)];
-        //    0A65004E003200010101C0C10000A5A5
         if(data.length == 16){
+            //0A65004E003200010101C0C10000A5A5
             NSData *cmd = [data subdataWithRange:NSMakeRange(5, 1)];
-    //        NSString *cmdStr = [[AiMouseTools dataToHexString:cmd] lowercaseString];
-    //        NSLog(@"cmd = %@",cmdStr);
             [self sendCmdData:cmd];
+            return;
         }
-        else if([cmd hasPrefix:@"9c31"]){
+        NSString *cmd = [[AiMouseTools dataToHexString:data] lowercaseString];
+        if([cmd hasPrefix:@"9c31"]){
             //声音
             [self.audioManager receiveData:data];
         }
index ebeee42..2dc25fc 100644 (file)
@@ -9,6 +9,7 @@
 /* Begin PBXBuildFile section */
                182B54802BB6A0D7009F53B6 /* AiRecordManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 182B547E2BB6A0D7009F53B6 /* AiRecordManager.m */; };
                182B54812BB6A0D7009F53B6 /* AiRecordManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 182B547F2BB6A0D7009F53B6 /* AiRecordManager.h */; };
+               182B548D2BB7EC9B009F53B6 /* DeviceManger.m in Sources */ = {isa = PBXBuildFile; fileRef = 182B548C2BB7EC9B009F53B6 /* DeviceManger.m */; };
                1867E5A92BB2706F008FC5FB /* HidManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1867E5A82BB2706F008FC5FB /* HidManager.m */; };
                1877F3E32BB4049600D3220A /* AiMouseConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 1877F3E12BB4049600D3220A /* AiMouseConfig.h */; };
                1877F3E42BB4049600D3220A /* AiMouseConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 1877F3E22BB4049600D3220A /* AiMouseConfig.m */; };
                0311DF3AD67ED792549B96BD /* libPods-MouseSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MouseSdk.a"; sourceTree = BUILT_PRODUCTS_DIR; };
                182B547E2BB6A0D7009F53B6 /* AiRecordManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiRecordManager.m; sourceTree = "<group>"; };
                182B547F2BB6A0D7009F53B6 /* AiRecordManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AiRecordManager.h; sourceTree = "<group>"; };
+               182B548B2BB7EC9B009F53B6 /* DeviceManger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceManger.h; sourceTree = "<group>"; };
+               182B548C2BB7EC9B009F53B6 /* DeviceManger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceManger.m; sourceTree = "<group>"; };
                1867E5A72BB2706F008FC5FB /* HidManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HidManager.h; sourceTree = "<group>"; };
                1867E5A82BB2706F008FC5FB /* HidManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HidManager.m; sourceTree = "<group>"; };
                1877F3E12BB4049600D3220A /* AiMouseConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiMouseConfig.h; sourceTree = "<group>"; };
                                18BF1E212B83066200B8D90F /* BleManager.m */,
                                1867E5A72BB2706F008FC5FB /* HidManager.h */,
                                1867E5A82BB2706F008FC5FB /* HidManager.m */,
+                               182B548B2BB7EC9B009F53B6 /* DeviceManger.h */,
+                               182B548C2BB7EC9B009F53B6 /* DeviceManger.m */,
                                18BF1DCD2B81AB7C00B8D90F /* AppDelegate.h */,
                                18BF1DCE2B81AB7C00B8D90F /* AppDelegate.m */,
                                18BF1DD02B81AB7C00B8D90F /* ViewController.h */,
                                18BF1DD22B81AB7C00B8D90F /* ViewController.m in Sources */,
                                18BF1DD92B81AB7F00B8D90F /* main.m in Sources */,
                                18F328D52B98569D00CABA2E /* Config.m in Sources */,
+                               182B548D2BB7EC9B009F53B6 /* DeviceManger.m in Sources */,
                                18BF1E762B832D2E00B8D90F /* ScanVC.m in Sources */,
                                18BF1E222B83066200B8D90F /* BleManager.m in Sources */,
                                18BF1DCF2B81AB7C00B8D90F /* AppDelegate.m in Sources */,
index 2454474..fc4e3f5 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 6486004..2d6da70 100644 (file)
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
-            uuid = "FDA64E17-61A3-4439-9354-1E36554FE365"
+            uuid = "0A2B3EE7-9C25-44AC-9ADD-244F3EE1D1DB"
             shouldBeEnabled = "Yes"
             ignoreCount = "0"
             continueAfterRunningActions = "No"
-            filePath = "MouseSdk/BleManager.m"
+            filePath = "MouseSdk/DeviceManger.m"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "184"
-            endingLineNumber = "184"
-            landmarkName = "-aiMouseSendCmdData:"
+            startingLineNumber = "99"
+            endingLineNumber = "99"
+            landmarkName = "-bleDidDisconnect:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "1C8B736A-006B-4670-9A67-8F24675DD8EB"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "MouseSdk/DeviceManger.m"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "95"
+            endingLineNumber = "95"
+            landmarkName = "-bleDidConnect:"
             landmarkType = "7">
-            <Locations>
-               <Location
-                  uuid = "FDA64E17-61A3-4439-9354-1E36554FE365 - 4643c942ae7f0b57"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "-[BleManager aiMouseSendCmdData:]"
-                  moduleName = "MouseSdk"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/apple/Desktop/code/MouseSdk-iOS/MouseSdk/MouseSdk/BleManager.m"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "184"
-                  endingLineNumber = "184"
-                  offsetFromSymbolStart = "378">
-               </Location>
-               <Location
-                  uuid = "FDA64E17-61A3-4439-9354-1E36554FE365 - 4643c942ae7f0b57"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "-[BleManager aiMouseSendCmdData:]"
-                  moduleName = "MouseSdk"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/apple/Desktop/code/MouseSdk-iOS/MouseSdk/MouseSdk/BleManager.m"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "184"
-                  endingLineNumber = "184"
-                  offsetFromSymbolStart = "171">
-               </Location>
-            </Locations>
          </BreakpointContent>
       </BreakpointProxy>
    </Breakpoints>
index d98b352..122b086 100644 (file)
@@ -17,8 +17,9 @@
 @interface BleManager : NSObject
 @property (nonatomic,strong)void (^discoverDevice)(CBPeripheral *peripheral) ;/// 扫描到设备
 @property (nonatomic,strong)void (^didConnectDevice)(CBPeripheral *peripheral);/// 连接成功
+@property (nonatomic,strong)void (^didDisConnectDevice)(CBPeripheral *peripheral);/// 断开连接
 @property (nonatomic,strong)void (^authCallBack)(BOOL isSuccess);/// 鉴权回调
-
+/// 单利
 +(BleManager *)shared;
 
 /// 扫描
index 9d08625..fbc625f 100644 (file)
@@ -41,7 +41,6 @@
     self = [super init];
     if (self) {
         self.centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
-        
     }
     return self;
 }
@@ -91,7 +90,9 @@
 -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
     [self showLog:[NSString stringWithFormat:@"断开连接。。。%@",error.description]];
     [[NSNotificationCenter defaultCenter] postNotificationName:kDidDisconnectBleNotification object:nil];
-    
+    if(self.didDisConnectDevice){
+        self.didDisConnectDevice(peripheral);
+    }
     [self autoConnectDevice];
 }
 - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error{
diff --git a/MouseSdk/MouseSdk/DeviceManger.h b/MouseSdk/MouseSdk/DeviceManger.h
new file mode 100644 (file)
index 0000000..234f4ab
--- /dev/null
@@ -0,0 +1,29 @@
+//
+//  DeviceManger.h
+//  MouseSdk
+//
+//  Created by incar on 2024/3/30.
+//
+
+#import <Foundation/Foundation.h>
+#import <AiMouseSdk/AiMouseSdk.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface DeviceManger : NSObject
+@property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型
+@property (nonatomic,strong)void (^authCallBack)(BOOL isSuccess);/// 鉴权回调
+@property (nonatomic,strong)void (^connectStateCallBack)(AiMouseConnectType connectType,BOOL isConnect);///是否连接成功
+
++(DeviceManger *)shared;
+
+/// 切换连接类型
+/// - Parameter type: 连接类型
+- (void)switchConnect:(AiMouseConnectType)type;
+
+/// 获取设备信息
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/MouseSdk/MouseSdk/DeviceManger.m b/MouseSdk/MouseSdk/DeviceManger.m
new file mode 100644 (file)
index 0000000..4a2a3af
--- /dev/null
@@ -0,0 +1,102 @@
+//
+//  DeviceManger.m
+//  MouseSdk
+//
+//  Created by incar on 2024/3/30.
+//
+
+#import "DeviceManger.h"
+#import "HidManager.h"
+#import "BleManager.h"
+
+@interface DeviceManger()
+
+@property (nonatomic,strong) BleManager *ble;
+@property (nonatomic,strong) HidManager *hid;
+@end
+
+@implementation DeviceManger
++(DeviceManger *)shared{
+    static DeviceManger *manager = nil;
+    static dispatch_once_t oncePredicate;
+    dispatch_once(&oncePredicate, ^{
+        manager = [[DeviceManger alloc]init];
+    });
+    return manager;
+}
+
+- (instancetype)init{
+    self = [super init];
+    if (self) {
+        [self setupBle];
+        [self setupHid];
+    }
+    return self;
+}
+
+-(AiMouseConnectType)connectType{
+    return [AiMouse shared].connectType;
+}
+
+- (void)switchConnect:(AiMouseConnectType)type{
+    [[AiMouse shared] switchConnect:type];
+    
+    if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) {
+        [self setupBle];
+    }
+    else{
+        [self setupHid];
+    }
+}
+
+- (void)setupHid{
+    self.ble = [BleManager shared];
+    __weak typeof(self) ws = self;
+    self.ble.authCallBack = ^(BOOL isSuccess) {
+       if(ws.authCallBack)ws.authCallBack(isSuccess);
+    };
+    self.ble.didConnectDevice = ^(CBPeripheral *peripheral) {
+        if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_bluetooth,true);
+    };
+    self.ble.didDisConnectDevice = ^(CBPeripheral *peripheral) {
+        if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_bluetooth,false);
+    };
+}
+
+- (void)setupBle{
+    self.hid = [HidManager shared];
+    __weak typeof(self) ws = self;
+    self.hid.authCallBack = ^(BOOL isSuccess) {
+       if(ws.authCallBack)ws.authCallBack(isSuccess);
+    };
+    self.hid.connectStateCallBack = ^(BOOL isConnnect) {
+        if(ws.connectStateCallBack)ws.connectStateCallBack(AiMouseConnectType_hid,isConnnect);
+    };
+    [self setupBleNotification];
+}
+
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation{
+    if ([AiMouse shared].connectType == AiMouseConnectType_bluetooth) {
+        [self.ble getDeviceInfo:completation];
+    }
+    else{
+        [self.hid getDeviceInfo:completation];
+    }
+}
+
+
+#pragma mark - notication
+- (void)setupBleNotification{
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bleDidConnect:) name:kDidConnectBleNotification object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bleDidDisconnect:) name:kDidDisconnectBleNotification object:nil];
+}
+
+- (void)bleDidConnect:(NSNotification *)notification{
+    if(self.connectStateCallBack)self.connectStateCallBack(AiMouseConnectType_bluetooth,true);
+}
+
+- (void)bleDidDisconnect:(NSNotification *)notification{
+    if(self.connectStateCallBack)self.connectStateCallBack(AiMouseConnectType_bluetooth,false);
+    [[AiMouse shared] switchConnect:AiMouseConnectType_hid];
+}
+@end
index 826614b..8c32827 100644 (file)
@@ -11,9 +11,9 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @interface HidManager : NSObject
-@property (nonatomic,strong)void (^connectStateDidChange)(BOOL isConnnect);/// 设备是否连上
+@property (nonatomic,strong)void (^connectStateCallBack)(BOOL isConnnect);/// 设备是否连上
 @property (nonatomic,strong)void (^authCallBack)(BOOL isSuccess);/// 鉴权回调
-///单利
+
 +(HidManager *)shared;
 
 /// 获取设备信息
index c15857a..60ea2c1 100644 (file)
@@ -14,7 +14,6 @@
 
 @interface HidManager ()<AiMouseDelegate>
 
-//IOHIDDeviceRef deviceRef;
 @property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管理
 @property(nonatomic, assign) IOHIDDeviceRef authCha;//鉴权特征
 @property(nonatomic, assign) IOHIDDeviceRef aiCha;//ai特征
     self = [super init];
     if (self) {
         [self initHid];
+        [self open];
     }
     return self;
 }
 
 - (void)initHid{
+
+}
+
+- (void)open{
     self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
     IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
     IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L);
     IOHIDManagerRegisterDeviceRemovalCallback(self.hidManager, &hidDisAppearDevice, NULL);
 }
 
+- (void)close{
+    IOReturn ret = IOHIDManagerClose(self.hidManager, 0);
+    if (ret != kIOReturnSuccess) {
+        NSLog(@"关闭设备失败!");
+    }else{
+        NSLog(@"关闭设备成功!");
+    }
+}
+
 #pragma mark - Hid CallBack
 static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
     uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));
@@ -86,16 +99,15 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH
     
     unsigned char InputBuffer[128];
     IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
-    //    CFRelease(ref);
 }
 
 static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
     NSLog(@"拔出设备 %@ ",inIOHIDDeviceRef);
-    uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inSender, CFSTR(kIOHIDPrimaryUsagePageKey));
-    uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inSender, CFSTR(kIOHIDPrimaryUsageKey));
+    uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));
+    uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));
 
     if(PrimaryUsagePage == 1 && PrimaryUsage == 0){
-        [HidManager shared].connectStateDidChange(false);
+        [HidManager shared].connectStateCallBack(false);
     }
 }
 
@@ -177,10 +189,10 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
 
 #pragma mark - public
 -(void)startAuthentication{
-    [HidManager shared].connectStateDidChange(true);
+    [HidManager shared].connectStateCallBack(true);
     [AiMouse shared].delegate = self;
     //切换当前连接类型
-    [[AiMouse shared] switchConnect:AiMouseConnectType_usb];
+    [[AiMouse shared] switchConnect:AiMouseConnectType_hid];
     //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用
     [self showLog:@"开始鉴权"];
     [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
@@ -223,7 +235,6 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
 
 static inline int get_data_len(uint8_t *buf, u_long len) {
     if (len <= 0 ) return 0;
-    
     int url_len = 0;
     while (buf[url_len] != 0x00) url_len++;
     return url_len;
index 6bf7f72..60a34cb 100644 (file)
@@ -7,12 +7,11 @@
 
 #import "ViewController.h"
 #import "ScanVC.h"
-#import "BleManager.h"
-#import "HidManager.h"
+#import "DeviceManger.h"
 
 @interface ViewController ()
-@property(nonatomic,strong)NSTextField *bleLabel;///蓝牙连接状态
-@property(nonatomic,strong)NSTextField *usbLabel;///usb连接状态
+@property(nonatomic,strong)NSTextField *typeLabel;///当前模式状态
+@property(nonatomic,strong)NSTextField *connectLabel;///连接状态
 @property(nonatomic,strong)NSTextField *authLabel;///鉴权状态
 @property(nonatomic,strong)NSTextField *deviceInfoLabel;///设备信息
 @end
@@ -24,9 +23,7 @@
     
     // Do any additional setup after loading the view.
     [self setupUI];
-    [self setupNotification];
-    [self setupBleManger];
-    [self setupHidManger];
+    [self setupDeviceManger];
 }
 
 - (void)setRepresentedObject:(id)representedObject {
@@ -37,7 +34,6 @@
 
 - (void)setupUI{
     self.title = @"AI SDK";
-
     {
         NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 100, 100, 45)];
         btn.bordered = true;
     {
         NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 200, 100, 45)];
         btn.bordered = true;
-        btn.title = @"è\93\9dç\89\99è\8e·å\8f\96设å¤\87ä¿¡æ\81¯";
+        btn.title = @"获取设备信息";
         [btn setTarget:self];
-        [btn setAction:@selector(bleGetDeviceInfoAction)];
-        btn.state = 1;
-        [self.view addSubview:btn];
-    }
-    {
-        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 260, 100, 45)];
-        btn.bordered = true;
-        btn.title = @"2.4g获取设备信息";
-        [btn setTarget:self];
-        [btn setAction:@selector(hidGetDeviceInfoAction)];
+        [btn setAction:@selector(geviceInfoAction)];
         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.stringValue = @"连接模式:--";
         label.backgroundColor = NSColor.clearColor;
-        self.bleLabel = label;
+        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 = @"2.4G连接状态:未连接";
+        label.stringValue = @"连接状态:未连接";
         label.backgroundColor = NSColor.clearColor;
-        self.usbLabel = label;
+        self.connectLabel = label;
         [self.view addSubview:label];
     }
     {
     }
 }
 
-#pragma mark - ble
-- (void)setupBleManger{
-    BleManager *manager = [BleManager shared];
-    __weak typeof(self) ws = self;
-    manager.authCallBack = ^(BOOL isSuccess) {
-        [ws showAuthResult:isSuccess];
-    };
-}
+#pragma mark - action
 - (void)scanAction{
     ScanVC *vc = [[ScanVC alloc] initWithNibName:nil bundle:nil];
     [self presentViewControllerAsModalWindow:vc];
 }
 
-- (void)bleGetDeviceInfoAction{
-    [[BleManager shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {
+/// 获取设备信息
+- (void)geviceInfoAction{
+    [[DeviceManger shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {
         if (deviceInfo) {
             NSString *info = [NSString stringWithFormat:@"battery_power = %@,CPI = %@,CPI_list = %@,version = %@,brand = %@,sn = %@,mac = %@",deviceInfo.battery_power,deviceInfo.CPI,deviceInfo.CPI_list,deviceInfo.version,deviceInfo.brand,deviceInfo.sn,deviceInfo.mac];
             NSLog(@"%@",info);
         self.authLabel.stringValue = isSuccess?@"鉴权状态:鉴权成功":@"鉴权状态:鉴权失败";
     });
 }
-#pragma mark - hid
-- (void)setupHidManger{
-    HidManager *manager = [HidManager shared];
-    __weak typeof(self) ws = self;
-    manager.authCallBack = ^(BOOL isSuccess) {
-        [ws showAuthResult:isSuccess];
-    };
-    manager.connectStateDidChange = ^(BOOL isConnnect) {
-        ws.usbLabel.stringValue = isConnnect? @"2.4g连接状态:已连接":@"2.4g连接状态:未连接";
-    };
-}
-- (void)hidGetDeviceInfoAction{
-    [[HidManager shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {
-        if (deviceInfo) {
-            NSString *info = [NSString stringWithFormat:@"battery_power = %@,CPI = %@,CPI_list = %@,version = %@,brand = %@,sn = %@,mac = %@",deviceInfo.battery_power,deviceInfo.CPI,deviceInfo.CPI_list,deviceInfo.version,deviceInfo.brand,deviceInfo.sn,deviceInfo.mac];
-            NSLog(@"%@",info);
-            
-            dispatch_async(dispatch_get_main_queue(), ^{
-                self.deviceInfoLabel.stringValue = info;
-            });
+- (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{
-            NSString *info = [NSString stringWithFormat:@"error == %@",error.description];
-            NSLog(@"%@",info);
-            dispatch_async(dispatch_get_main_queue(), ^{
-                self.deviceInfoLabel.stringValue = info;
-            });
+            self.typeLabel.stringValue = @"连接模式:--";
+            self.connectLabel.stringValue = @"连接状态:未连接";
         }
-    }];
-}
-
-#pragma mark - notication
-- (void)setupNotification{
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bleDidConnect:) name:kDidConnectBleNotification object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bleDidDisconnect:) name:kDidDisconnectBleNotification object:nil];
-}
-
-- (void)bleDidConnect:(NSNotification *)notification{
-    self.bleLabel.stringValue = @"蓝牙连接状态:已连接";
+    });
 }
 
-- (void)bleDidDisconnect:(NSNotification *)notification{
-    self.bleLabel.stringValue = @"蓝牙连接状态:未连接";
+- (void)setupDeviceManger{
+    DeviceManger *manager = [DeviceManger shared];
+    __weak typeof(self) ws = self;
+    manager.authCallBack = ^(BOOL isSuccess) {
+        [ws showAuthResult:isSuccess];
+    };
+    manager.connectStateCallBack = ^(AiMouseConnectType type,BOOL isConnected) {
+        [ws connectStateDidChange:type connectState:isConnected];
+    };
 }
-
 @end