From: liangzhenying <867174124@qq.com> Date: Thu, 29 Aug 2024 11:54:59 +0000 (+0800) Subject: usb、蓝牙模式切换优化 X-Git-Tag: 千寻适配d9~27 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7e3f46ff57d8ca3a4af000646732a9165decfdf1;p=mirrors%2FMouseSdk-MacOS.git usb、蓝牙模式切换优化 --- diff --git a/MouseSdk/AiMouseSdk/Manager/BleManager.h b/MouseSdk/AiMouseSdk/Manager/BleManager.h index 13f5777..b351a26 100644 --- a/MouseSdk/AiMouseSdk/Manager/BleManager.h +++ b/MouseSdk/AiMouseSdk/Manager/BleManager.h @@ -17,16 +17,12 @@ @property (nonatomic, copy)void (^logCallBack)(NSString *log);//输出日志 @property (nonatomic, assign)AiMouseProductType productType;// -///// 单利 -//+(BleManager *)shared; +//- (void)startScan; -// bleList:蓝牙设备名称 -- (void)startScanWithName:(NSArray *)bleList; +//- (void)stopScan; -//停止扫描 -- (void)stopScan; +- (void)start; -//写入数据 -(void)writeToDevice:(NSData *)data; @end diff --git a/MouseSdk/AiMouseSdk/Manager/BleManager.m b/MouseSdk/AiMouseSdk/Manager/BleManager.m index 08a2338..fd732e3 100644 --- a/MouseSdk/AiMouseSdk/Manager/BleManager.m +++ b/MouseSdk/AiMouseSdk/Manager/BleManager.m @@ -30,18 +30,12 @@ @property(nonatomic, strong) CBCharacteristic *deviceInfoCha;//设备信息特征 @property (nonatomic,strong) NSMutableData *recordData;//录音的数据 +@property (nonatomic, strong) NSTimer *timer; +@property (nonatomic, strong) dispatch_queue_t mainQueue; + @end @implementation BleManager -//+(BleManager *)shared{ -// static BleManager *manager = nil; -// static dispatch_once_t oncePredicate; -// dispatch_once(&oncePredicate, ^{ -// manager = [[BleManager alloc]init]; -// }); -// return manager; -//} - - (instancetype)init{ self = [super init]; if (self) { @@ -190,21 +184,20 @@ [self.centralManager cancelPeripheralConnection:self.curentPeripheral]; } #pragma mark - public -- (void)startScanWithName:(NSArray *)bleList{ +- (void)startScan{ NSArray *devices = [self.centralManager retrieveConnectedPeripheralsWithServices:@[[CBUUID UUIDWithString:kFrkServiceUUID],[CBUUID UUIDWithString:kTlwServiceUUID]]]; - [self showLog:[NSString stringWithFormat:@"匹配过的设备%@",devices]]; + [self showLog:[NSString stringWithFormat:@"查询配对过的设备%@",devices]]; if (devices.count > 0) { - [self showLog:[NSString stringWithFormat:@"匹配过的设备%@",devices[0].name]]; + [self showLog:[NSString stringWithFormat:@"配对匹配过的设备%@",devices[0].name]]; [self connectPeripheral:devices[0]]; } else{ - [self showLog:[NSString stringWithFormat:@"开始扫描 设备名称 %@",bleList]]; - [self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : [NSNumber numberWithBool:NO]}]; +// [self showLog:[NSString stringWithFormat:@"开始扫描%@",@""]]; +// [self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : [NSNumber numberWithBool:NO]}]; } } - - (void)stopScan{ if (self.centralManager.isScanning) { [self showLog:[NSString stringWithFormat:@":停止扫描"]]; @@ -212,20 +205,6 @@ } } -/// 连接设备 -- (void)connectPeripheral:(CBPeripheral *)peripheral{ - if(self.curentPeripheral != nil && self.curentPeripheral.state == CBPeripheralStateConnected){ - [self showLog:@"当前蓝牙已处理连接状态,不会重连!!!"]; - return; - } - - [self showLog:[NSString stringWithFormat:@"连接设备 %@",peripheral.description]]; - self.curentPeripheral = peripheral; - self.curentPeripheral.delegate = self; - [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}]; - [self performSelector:@selector(checkRightDevice) withObject:nil afterDelay:1]; -} - -(void)writeToDevice:(NSData *)data{ if (self.curentPeripheral ==nil) { return; @@ -243,9 +222,40 @@ } } +#pragma mark - other +- (void)connectPeripheral:(CBPeripheral *)peripheral{ + if(self.curentPeripheral != nil && self.curentPeripheral.state == CBPeripheralStateConnected){ + [self showLog:@"当前蓝牙已处理连接状态,不会重连!!!"]; + return; + } + + [self showLog:[NSString stringWithFormat:@"连接设备 %@",peripheral.description]]; + self.curentPeripheral = peripheral; + self.curentPeripheral.delegate = self; + [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}]; + [self performSelector:@selector(checkRightDevice) withObject:nil afterDelay:1]; +} - (void)showLog:(NSString *)log{ NSString *text = [NSString stringWithFormat:@"[BleManager] %@",log]; if(self.logCallBack) self.logCallBack(text); } +#pragma mark - timer +- (void)start{ + if (self.timer && [self.timer isValid]) { + [self.timer invalidate]; + self.timer = nil; + } + dispatch_async(dispatch_queue_create("timeoutQueue", DISPATCH_QUEUE_SERIAL), ^{ + self.timer = [NSTimer timerWithTimeInterval:5 target:self selector:@selector(timerAction) userInfo:nil repeats:true]; + [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; + [[NSRunLoop currentRunLoop] run]; + }); +} + +- (void)timerAction{ + if(self.curentPeripheral == nil || self.curentPeripheral.state == CBPeripheralStateDisconnected){ + [self startScan]; + } +} @end diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index 6c98783..85b0469 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -19,7 +19,6 @@ @property (nonatomic,strong) NSMutableData *recordData;//录音的数据 @property (nonatomic,strong) BleManager *ble; @property (nonatomic,strong) HidManager *hid; -@property (nonatomic,strong) NSArray *mouseNames; @property (nonatomic,strong) TlwMouse *tlwSdk; @property (nonatomic,strong) AiMouse *frkSdk; @@ -54,14 +53,10 @@ [TimerManager shared].timerCallBack = ^{ // [self showLog:@"timer action。。。"]; if(self.tlwSdk.connected || self.frkSdk.connected){ - [self.ble stopScan]; // [self.hid close]; } else{ - if(self.mouseNames.count > 0 ) { - [self.ble startScanWithName:self.mouseNames]; - [self.hid open]; - } + [self.hid open]; } }; } @@ -70,9 +65,6 @@ __weak typeof(self) ws = self; self.hid.connectStateCallBack = ^(BOOL connected) { - if (connected) { - [ws.ble stopScan]; - } if (ws.hid.productType == AiMouseProductType_tlw) { ws.productType = AiMouseProductType_tlw; ws.tlwSdk = [[TlwMouse alloc] init]; @@ -187,7 +179,7 @@ - (void)begainMonitorAiMouseConnectStateDidChange:(NSString *)mouseName callBack:(void(^)(int connectType, BOOL connected))callBack{ self.aiMouseConnectStateDidChangeCallBack = callBack; - self.mouseNames = @[mouseName,@"VMouse"]; + [self.ble start]; } ///获取设备信息 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index 4786c58..6c28db9 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/AiHidManager.h b/MouseSdk/MouseSdk/AiHidManager.h index 7683c2c..1d0711d 100644 --- a/MouseSdk/MouseSdk/AiHidManager.h +++ b/MouseSdk/MouseSdk/AiHidManager.h @@ -1,19 +1,19 @@ +//// +//// HidManager.h +//// MouseSdk +//// +//// Created by incar on 2024/3/26. +//// // -// HidManager.h -// MouseSdk +//#import // -// Created by incar on 2024/3/26. +//NS_ASSUME_NONNULL_BEGIN // - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface AiHidManager : NSObject -@property (nonatomic,strong)void (^connectStateCallBack)(BOOL isConnnect);/// 设备是否连上 - -+(AiHidManager *)shared; - -@end - -NS_ASSUME_NONNULL_END +//@interface AiHidManager : NSObject +//@property (nonatomic,strong)void (^connectStateCallBack)(BOOL isConnnect);/// 设备是否连上 +// +//+(AiHidManager *)shared; +// +//@end +// +//NS_ASSUME_NONNULL_END diff --git a/MouseSdk/MouseSdk/AiHidManager.m b/MouseSdk/MouseSdk/AiHidManager.m index 2fcf486..15d73c8 100644 --- a/MouseSdk/MouseSdk/AiHidManager.m +++ b/MouseSdk/MouseSdk/AiHidManager.m @@ -1,154 +1,154 @@ +//// +//// HidManager.m +//// MouseSdk +//// +//// Created by incar on 2024/3/26. +//// // -// HidManager.m -// MouseSdk -// -// Created by incar on 2024/3/26. -// - -#import "AiHidManager.h" -#include -#include - - - -//供应商id -//const long vendorID = 0x6675; -//const long productID = 0x8601; - -@interface AiHidManager () - -@property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管理 -@property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设备信息通道 -@property (nonatomic,strong) NSMutableData *recordData;//录音的数据 -@end - -@implementation AiHidManager -+(AiHidManager *)shared{ - static AiHidManager *manager = nil; - static dispatch_once_t oncePredicate; - dispatch_once(&oncePredicate, ^{ - manager = [[AiHidManager alloc]init]; - }); - return manager; -} - -- (instancetype)init{ - self = [super init]; - if (self) { - [self initHid]; - [self open]; - } - return self; -} - -- (void)initHid{ - -} - -- (void)open{ - self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L); - if (ret != kIOReturnSuccess) { - NSLog(@"打开设备失败!"); - }else{ - NSLog(@"打开设备成功!"); - } - //供应商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]]; - IOHIDManagerSetDeviceMatching(self.hidManager, (__bridge CFMutableDictionaryRef)dict); - //设置匹配到设备回调 - IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, &hidAppearDevice, NULL); - //设置移除设备回调 - 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) { - [[AiHidManager shared] showLog:[NSString stringWithFormat:@"发现设备 %@\n ",inIOHIDDeviceRef]]; -// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ - //设备信息 - [AiHidManager shared].deviceInfoCha = inIOHIDDeviceRef; - //注册消息回调 - unsigned char InputBuffer[128]; - IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL); - IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, kIOHIDOptionsTypeNone); - if (ret != kIOReturnSuccess) { - NSLog(@"打开设备信息失败!"); - }else{ - NSLog(@"打开设备信息成功!"); - } - CFRetain(inIOHIDDeviceRef); - IOHIDDeviceScheduleWithRunLoop(inIOHIDDeviceRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); +//#import "AiHidManager.h" +//#include +//#include +// +// +// +////供应商id +////const long vendorID = 0x6675; +////const long productID = 0x8601; +// +//@interface AiHidManager () +// +//@property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管理 +//@property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设备信息通道 +//@property (nonatomic,strong) NSMutableData *recordData;//录音的数据 +//@end +// +//@implementation AiHidManager +//+(AiHidManager *)shared{ +// static AiHidManager *manager = nil; +// static dispatch_once_t oncePredicate; +// dispatch_once(&oncePredicate, ^{ +// manager = [[AiHidManager alloc]init]; +// }); +// return manager; +//} +// +//- (instancetype)init{ +// self = [super init]; +// if (self) { +// [self initHid]; +// [self open]; +// } +// return self; +//} +// +//- (void)initHid{ +// +//} +// +//- (void)open{ +// self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); +// IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); +// IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L); +// if (ret != kIOReturnSuccess) { +// NSLog(@"打开设备失败!"); +// }else{ +// NSLog(@"打开设备成功!"); // } -// else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){ -// //ai -// [AiHidManager shared].aiCha = inIOHIDDeviceRef; +// //供应商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]]; +// IOHIDManagerSetDeviceMatching(self.hidManager, (__bridge CFMutableDictionaryRef)dict); +// //设置匹配到设备回调 +// IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, &hidAppearDevice, NULL); +// //设置移除设备回调 +// 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) { +// [[AiHidManager shared] showLog:[NSString stringWithFormat:@"发现设备 %@\n ",inIOHIDDeviceRef]]; +//// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ +// //设备信息 +// [AiHidManager shared].deviceInfoCha = inIOHIDDeviceRef; // //注册消息回调 // unsigned char InputBuffer[128]; // IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL); -// IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, 0); +// IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, kIOHIDOptionsTypeNone); // if (ret != kIOReturnSuccess) { -// NSLog(@"打开AI失败!"); +// NSLog(@"打开设备信息失败!"); // }else{ -// NSLog(@"打开AI成功!"); +// NSLog(@"打开设备信息成功!"); // } // CFRetain(inIOHIDDeviceRef); // IOHIDDeviceScheduleWithRunLoop(inIOHIDDeviceRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); -// } -} - -/// 设备移除回调 -static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) { - [[AiHidManager shared] showLog:[NSString stringWithFormat:@"拔出设备 %@ ",inIOHIDDeviceRef]]; -// uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey)); -// uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); -// -// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ -// [AiHidManager shared].deviceInfoCha = nil; -//// [AiHidManager shared].aiCha = nil; -// [[AiMouse shared] didDisconnect]; -// } -} - -static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){ -// [[AiHidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理前 %@",[AiMouseTools dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]]; - -// NSInteger len = get_data_len(report, 64); - NSData *data = [[NSData alloc] initWithBytes:report length:64]; - [[AiHidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理后 %@",data]]; - -// uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); -// uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); -// -// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ -// [[AiMouse shared] sendDeviceDataToSdk:data]; -// -// } -// else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){ -// [[AiMouse shared] sendAiDataToSdk:data]; -// } -} - - -- (void)showLog:(NSString *)log{ - NSLog(@"%@",log); -} - -@end +//// } +//// else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){ +//// //ai +//// [AiHidManager shared].aiCha = inIOHIDDeviceRef; +//// //注册消息回调 +//// unsigned char InputBuffer[128]; +//// IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL); +//// IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, 0); +//// if (ret != kIOReturnSuccess) { +//// NSLog(@"打开AI失败!"); +//// }else{ +//// NSLog(@"打开AI成功!"); +//// } +//// CFRetain(inIOHIDDeviceRef); +//// IOHIDDeviceScheduleWithRunLoop(inIOHIDDeviceRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); +//// } +//} +// +///// 设备移除回调 +//static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) { +// [[AiHidManager shared] showLog:[NSString stringWithFormat:@"拔出设备 %@ ",inIOHIDDeviceRef]]; +//// uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey)); +//// uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); +//// +//// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ +//// [AiHidManager shared].deviceInfoCha = nil; +////// [AiHidManager shared].aiCha = nil; +//// [[AiMouse shared] didDisconnect]; +//// } +//} +// +//static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){ +//// [[AiHidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理前 %@",[AiMouseTools dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]]; +// +//// NSInteger len = get_data_len(report, 64); +// NSData *data = [[NSData alloc] initWithBytes:report length:64]; +// [[AiHidManager shared] showLog:[NSString stringWithFormat:@"[receive] 处理后 %@",data]]; +// +//// uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); +//// uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); +//// +//// if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ +//// [[AiMouse shared] sendDeviceDataToSdk:data]; +//// +//// } +//// else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){ +//// [[AiMouse shared] sendAiDataToSdk:data]; +//// } +//} +// +// +//- (void)showLog:(NSString *)log{ +// NSLog(@"%@",log); +//} +// +//@end diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m index 864d188..4ea3ace 100644 --- a/MouseSdk/MouseSdk/ViewController.m +++ b/MouseSdk/MouseSdk/ViewController.m @@ -75,7 +75,6 @@ #import "ViewController.h" #import "ScanVC.h" #import "DeviceManger.h" -#import "AiHidManager.h" @interface ViewController () @property(nonatomic,strong)NSTextField *typeLabel;///当前模式状态 @property(nonatomic,strong)NSTextField *connectLabel;///连接状态 @@ -119,17 +118,17 @@ [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 - 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)]; + NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 100, 100, 45)]; btn.bordered = true; btn.title = @"获取设备信息"; [btn setTarget:self]; @@ -138,7 +137,7 @@ [self.view addSubview:btn]; } { - NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 280, 100, 45)]; + NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 200, 100, 45)]; btn.bordered = true; btn.title = @"更多指令"; [btn setTarget:self]; @@ -264,7 +263,7 @@ }]; } - (void)setDPI:(NSMenuItem*)sender { - [[DeviceManger shared] setCPI:1200 completation:^(BOOL isSuccess, NSError * _Nonnull error) { + [[DeviceManger shared] setCPI:1600 completation:^(BOOL isSuccess, NSError * _Nonnull error) { }]; }