typedef NS_ENUM(NSInteger,AiMouseConnectType) {
AiMouseConnectType_bluetooth = 0,///蓝牙
- AiMouseConnectType_usb,///usb
+ AiMouseConnectType_hid,///hid
};
typedef NS_ENUM(NSInteger,AiMouseAuthState) {
_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];
}
/* 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 */,
<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>
@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;
/// 扫描
self = [super init];
if (self) {
self.centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
-
}
return self;
}
-(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{
--- /dev/null
+//
+// 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
--- /dev/null
+//
+// 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
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;
/// 获取设备信息
@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));
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);
}
}
#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) {
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;
#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
// Do any additional setup after loading the view.
[self setupUI];
- [self setupNotification];
- [self setupBleManger];
- [self setupHidManger];
+ [self setupDeviceManger];
}
- (void)setRepresentedObject:(id)representedObject {
- (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