| 1.0.5 | 支持静态库.a | 梁振营 | 2024-04-22 |\r
| 1.0.6 | 增加鉴权 | 梁振营 | 2024-04-30 |\r
| 1.0.13 | 鉴权流程优化 | 梁振营 | 2024-05-20 |\r
+| 1.0.17 | 增加命令控制录音功能 | 梁振营 | 2024-05-28 |\r
\r
\r
\r
- (void)sendDeviceDataToSdk:(NSData *)data;\r
\r
/// 获取设备信息\r
-/// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为空\r
+/// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为nil\r
- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete;\r
\r
/// 获取信号强度\r
-/// - Parameter completation: 信号强度回调\r
-- (void)getRSSI:(void (^)(NSString *value))complete;\r
+/// - Parameter completation: 信号强度回调,如果获取成功,则value有值,否则为nil\r
+- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete;\r
\r
/// 设置CPI\r
/// - Parameters:\r
/// - value: AiMouseDeviceInfo 中可以设置的值CPI_list\r
/// - finished: 设置结果回调\r
- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+/// 设置录音模式\r
+/// - Parameters:\r
+/// - value: 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音\r
+/// - finished: 设置结果回调\r
+- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+/// 设置长按滚轮弹出的网页地址\r
+/// - Parameters:\r
+/// - url: 最大长度:49字节\r
+/// - finished: 设置结果回调\r
+- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+/// 设置长按滚轮弹出网页开关\r
+/// - Parameters:\r
+/// - state: 0关闭,1打开\r
+/// - finished: 设置结果回调\r
+- (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+/// 设置鼠标连接模式\r
+/// - Parameters:\r
+/// - mode: 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式\r
+/// - finished: 设置结果回调\r
+- (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+\r
+/// 获取录音模式\r
+/// - Parameter complete: mode 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音 。error为nil才代表获取成功\r
+- (void)getRecordMode:(void (^)(int mode,NSError *error))complete;\r
+\r
+/// 获取长按滚轮弹出的网页地址\r
+/// - Parameter complete: url地址 。error为nil才代表获取成功\r
+- (void)getUrl:(void (^)(NSString *url,NSError *error))complete;\r
+\r
+/// 获取长按滚轮弹出的网页地址开关状态\r
+/// - Parameter complete: state 0关闭,1打开。 error为nil才代表获取成功\r
+- (void)getUrlState:(void (^)(int state,NSError *error))complete;\r
+\r
+/// 获取鼠标连接模式\r
+/// - Parameter complete: mode 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式 。error为nil才代表获取成功\r
+- (void)getMouseModel:(void (^)(int mode,NSError *error))complete;\r
+\r
+\r
+/// 打开录音\r
+/// - finished: 执行结果回调\r
+- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished;\r
+\r
+/// 关闭录音\r
+/// - finished: 执行结果回调\r
+- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished;\r
```\r
\r
## SDK相关代理\r
\r
\r
```objective-c\r
+@protocol AiMouseDelegate <NSObject>\r
+\r
/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备\r
/// - Parameter data: 数据\r
- (void)aiMouseSendDeviceInfoData:(NSData *)data;\r
/// 录音回调\r
/// - Parameter data: pcm格式语音数据\r
- (void)aiMouseSendRecordData:(NSData *)data;\r
+\r
+@optional\r
+/// 输出sdk日志\r
+/// - Parameter log: 日志\r
+- (void)aiMouseAddLog:(NSString *)log;\r
+@end\r
```\r
\r
\r
184A71202BDD11C70025A332 /* AiTrippleModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 184A711E2BDD11C70025A332 /* AiTrippleModel.m */; };
184A71242BDE2DA60025A332 /* AiSecretModel.h in Headers */ = {isa = PBXBuildFile; fileRef = 184A71222BDE2DA60025A332 /* AiSecretModel.h */; };
184A71252BDE2DA60025A332 /* AiSecretModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 184A71232BDE2DA60025A332 /* AiSecretModel.m */; };
- 189F3B7D2BDE5254007035F9 /* AiAuthManager2.h in Headers */ = {isa = PBXBuildFile; fileRef = 189F3B7B2BDE5254007035F9 /* AiAuthManager2.h */; };
- 189F3B7E2BDE5254007035F9 /* AiAuthManager2.m in Sources */ = {isa = PBXBuildFile; fileRef = 189F3B7C2BDE5254007035F9 /* AiAuthManager2.m */; };
+ 189C15862C05726600676A80 /* AiConnectManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 189C15842C05726600676A80 /* AiConnectManager.h */; };
+ 189C15872C05726600676A80 /* AiConnectManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 189C15852C05726600676A80 /* AiConnectManager.m */; };
18AD83252BFAE8B9009BDE3B /* AiDeviceInfoManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 18AD83232BFAE8B9009BDE3B /* AiDeviceInfoManager.h */; };
18AD83262BFAE8B9009BDE3B /* AiDeviceInfoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AD83242BFAE8B9009BDE3B /* AiDeviceInfoManager.m */; };
18AD83292BFB22DE009BDE3B /* AiSender.h in Headers */ = {isa = PBXBuildFile; fileRef = 18AD83272BFB22DE009BDE3B /* AiSender.h */; };
184A711E2BDD11C70025A332 /* AiTrippleModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiTrippleModel.m; sourceTree = "<group>"; };
184A71222BDE2DA60025A332 /* AiSecretModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiSecretModel.h; sourceTree = "<group>"; };
184A71232BDE2DA60025A332 /* AiSecretModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiSecretModel.m; sourceTree = "<group>"; };
- 189F3B7B2BDE5254007035F9 /* AiAuthManager2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiAuthManager2.h; sourceTree = "<group>"; };
- 189F3B7C2BDE5254007035F9 /* AiAuthManager2.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiAuthManager2.m; sourceTree = "<group>"; };
+ 189C15842C05726600676A80 /* AiConnectManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiConnectManager.h; sourceTree = "<group>"; };
+ 189C15852C05726600676A80 /* AiConnectManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiConnectManager.m; sourceTree = "<group>"; };
18AD83232BFAE8B9009BDE3B /* AiDeviceInfoManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiDeviceInfoManager.h; sourceTree = "<group>"; };
18AD83242BFAE8B9009BDE3B /* AiDeviceInfoManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiDeviceInfoManager.m; sourceTree = "<group>"; };
18AD83272BFB22DE009BDE3B /* AiSender.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiSender.h; sourceTree = "<group>"; };
180E7AAB2BD7BB12008558E8 /* AiMouseSdk.m */,
18AD83232BFAE8B9009BDE3B /* AiDeviceInfoManager.h */,
18AD83242BFAE8B9009BDE3B /* AiDeviceInfoManager.m */,
+ 189C15842C05726600676A80 /* AiConnectManager.h */,
+ 189C15852C05726600676A80 /* AiConnectManager.m */,
18AD83272BFB22DE009BDE3B /* AiSender.h */,
18AD83282BFB22DE009BDE3B /* AiSender.m */,
180E7AB42BD7BD7D008558E8 /* AiFrameManager.h */,
180E7B4D2BD7BD81008558E8 /* AiFrameManager.m */,
180E7B472BD7BD7F008558E8 /* AiAuthManager.h */,
180E7B522BD7BD82008558E8 /* AiAuthManager.m */,
- 189F3B7B2BDE5254007035F9 /* AiAuthManager2.h */,
- 189F3B7C2BDE5254007035F9 /* AiAuthManager2.m */,
184A711D2BDD11C70025A332 /* AiTrippleModel.h */,
184A711E2BDD11C70025A332 /* AiTrippleModel.m */,
184A71222BDE2DA60025A332 /* AiSecretModel.h */,
180E7CA82BD8FC4E008558E8 /* ffversion.h in Headers */,
180E7CDD2BD8FC4E008558E8 /* intreadwrite.h in Headers */,
184A71052BDA4C050025A332 /* AFURLRequestSerialization.h in Headers */,
- 189F3B7D2BDE5254007035F9 /* AiAuthManager2.h in Headers */,
180E7CB62BD8FC4E008558E8 /* buffer.h in Headers */,
180E7CCC2BD8FC4E008558E8 /* twofish.h in Headers */,
180E7BDE2BD7BD84008558E8 /* AiMouseTools.h in Headers */,
180E7CD42BD8FC4E008558E8 /* hdr_dynamic_metadata.h in Headers */,
180E7CB92BD8FC4E008558E8 /* hwcontext_drm.h in Headers */,
180E7CE22BD8FC4E008558E8 /* version.h in Headers */,
+ 189C15862C05726600676A80 /* AiConnectManager.h in Headers */,
180E7C892BD8FC4E008558E8 /* time.h in Headers */,
180E7CD32BD8FC4E008558E8 /* bprint.h in Headers */,
180E7CB02BD8FC4E008558E8 /* timecode.h in Headers */,
180E7BE42BD7BD84008558E8 /* AiRecordManager.m in Sources */,
180E7BE32BD7BD84008558E8 /* AiFrameManager.m in Sources */,
180E7BE72BD7BD84008558E8 /* AiAudioManager.m in Sources */,
- 189F3B7E2BDE5254007035F9 /* AiAuthManager2.m in Sources */,
+ 189C15872C05726600676A80 /* AiConnectManager.m in Sources */,
180E7BDF2BD7BD84008558E8 /* AiMouseConfig.m in Sources */,
184A710D2BDA4C050025A332 /* AFSecurityPolicy.m in Sources */,
180E7B552BD7BD83008558E8 /* AiAudioDecoder.m in Sources */,
[self showLog:@"获取设备信息错误,鉴权失败!"];
return;
}
- if([info valueForKey:@"deviceSecret"]){
+ if([[info valueForKey:@"deviceSecret"] isKindOfClass:[NSString class]] && ([(NSString *)[info valueForKey:@"deviceSecret"] length] > 2)){
//已注册过,直接登录
[self loginRequest];
}
[manager PUT:url parameters:params headers:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
+ [self showLog:[NSString stringWithFormat:@" %@",str]];
NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
NSString *code = dict[@"code"];
NSString *deviceSecret = [dict valueForKeyPath:@"data.deviceSecret"];
[manager POST:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
+ [self showLog:[NSString stringWithFormat:@"%@",str]];
NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
NSString *code = dict[@"code"];
NSString *token = [dict valueForKeyPath:@"data.token"];
if(self.authCallBack)self.authCallBack(true);
//[self tokenRequest];
}
- else if(code.integerValue == 50021){
+ else if(code.integerValue == 50021 || code.integerValue == 50003){
//密码错误,重置过
[self registerReuest];
}
[manager GET:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
- [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
+ [self showLog:[NSString stringWithFormat:@"%@",str]];
NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
NSString *code = dict[@"code"];
if(code.integerValue == 20000){
+++ /dev/null
-////
-//// AiAuthManager2.h
-//// AiMouseSdk
-////
-//// Created by incar on 2024/4/28.
-////
-//
-//#import <Foundation/Foundation.h>
-//
-//#import "AiMouseSdk.h"
-//NS_ASSUME_NONNULL_BEGIN
-//
-//@interface AiAuthManager2 : NSObject
-//@property (nonatomic,strong)void (^outputLog)(NSString *log);
-//@property (nonatomic,strong)void (^outputData)(NSData *data);
-//@property (nonatomic,strong)void (^authCallBack)(BOOL isSuccess);
-//
-//- (void)loginWith:(AiMouseDeviceInfo *)info;
-//
-//- (void)receiveData:(NSData *)data;
-//@end
-//
-//NS_ASSUME_NONNULL_END
+++ /dev/null
-////
-//// AiAuthManager.m
-//// AiMouse
-////
-//// Created by incar on 2024/2/28.
-////
-//
-//#import "AiAuthManager2.h"
-//#import "AiMouseTools.h"
-//#import "AFNetworking.h"
-//#import "AiTrippleModel.h"
-//#import "AiSecretModel.h"
-//
-//#define kBaseUrl @"http://iot.api.thisiot.com/da/auth"
-//#define kRegisterApi @"active"
-//#define kLoginApi @"login"
-//#define kTokenApi @"token"
-//
-//
-//@interface AiAuthManager2 ()
-//@property (nonatomic,strong)AiMouseDeviceInfo *deviceInfo;
-//@end
-//@implementation AiAuthManager2
-//- (instancetype)init{
-// self = [super init];
-// if (self) {
-//
-// }
-// return self;
-//}
-//
-//#pragma mark - pub api
-//- (void)receiveData:(NSData *)data {
-// [self showLog:[NSString stringWithFormat:@"鉴权数据 = \n%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]]];
-// NSDictionary *dict = [AiMouseTools dataToDictionary:data];
-// NSString *type = dict[@"sid"];
-// if (![type isKindOfClass:[NSString class]]) {
-// [self showLog:@"FGS查询返回数据异常"];
-// return;
-// }
-// if([type isEqualToString:@"FGS"]){
-// //FGS类型
-// NSDictionary *data = [AiMouseTools stringToDictionary:dict[@"data"]];
-// NSString *msg_type = data[@"msg_type"];
-// if ([msg_type isEqualToString:@"FGS_MSG_TYPE_START_FGS_RESP"]) {
-// //查询注册状态
-// NSString *tripplestatus = data[@"tripplestatus"];
-// if ([tripplestatus isKindOfClass:[NSString class]] && [tripplestatus isEqualToString:@"needfetch"]) {
-// //未注册,请求获取三元组
-// [self getTrippleCmd];
-// }
-// else{
-// //已注册,请求获取密钥
-// [self getDeviceSecretCmd];
-// }
-// }
-// else if([msg_type isEqualToString:@"FGS_MSG_TYPE_START_LP_AUTH_RESP"]){
-// //获取到设备三元组,然后拿去注册
-// AiTrippleModel *model = [AiTrippleModel modelWithDict:data];
-// [self registerReuest:model];
-// }
-// else if([msg_type isEqualToString:@"FGS_MSG_TYPE_DS_DOWNLOAD_RESP"]){
-// [self showLog:@"device secret写入结果"];
-// //密钥写入设备
-// [self checkFgsCmd];
-// }
-// }
-// else if([type isEqualToString:@"FND"]) {
-// // FND类型
-// AiSecretModel *model = [AiSecretModel modelWithDict:dict];
-// [self loginRequest:model];
-// }
-//}
-//
-//- (void)loginWith:(AiMouseDeviceInfo *)info{
-// self.deviceInfo = info;
-// [self registerReuest];
-//// [self registerAction];
-//// [self checkFgsCmd];
-//// [self tokenAction];
-//// [self sendDeviceSecretCmd];
-//}
-/////查询设备注册状态
-//- (void)checkFgsCmd{
-// NSDictionary *dict = @{
-// @"data": @"{\"msg_type\":\"FGS_MSG_TYPE_START_FGS_REQ\",\"sidver\":1}",
-// @"sid": @"FGS",
-// @"ver": @(1)
-// };
-// NSData *data = [AiMouseTools dictionaryToData:dict];
-// if (self.outputData) self.outputData(data);
-//}
-/////获取三元组信息
-//- (void)getTrippleCmd{
-// NSDictionary *dict = @{
-// @"data": @"{\"msg_type\":\"FGS_MSG_TYPE_START_LP_AUTH_REQ\",\"message\":\"success\",\"sidver\":1,\"timeStamp\":\"1709795516169\"}",
-// @"sid": @"FGS",
-// @"ver": @(1)
-// };
-// NSData *data = [AiMouseTools dictionaryToData:dict];
-// if (self.outputData) self.outputData(data);
-//}
-/////获取设备密钥
-//-(void)getDeviceSecretCmd{
-// NSDictionary *dict = @{
-// @"data": @"AQ0AMTcwOTc5NzQ3ODQ3Nw==",
-// @"ver": @(1),
-// @"sid": @"FND"
-// };
-// NSData *data = [AiMouseTools dictionaryToData:dict];
-// if (self.outputData) self.outputData(data);
-//}
-/////将设备密钥密钥写到硬件
-//-(void)sendDeviceSecretCmd:(NSString *)deviceSecret{
-// NSDictionary *dict = @{
-// @"ver": @(1),
-// @"sid": @"FGS",
-//// @"data": @"{\"code\":200,\"msg_type\":\"FGS_MSG_TYPE_DS_DOWNLOAD_REQ\",\"deviceSecret\":\"D2eT9eFxhtuhL\",\"sidver\":1,\"message\":\"success\"}"
-// @"data": [NSString stringWithFormat:@"{\"code\":200,\"msg_type\":\"FGS_MSG_TYPE_DS_DOWNLOAD_REQ\",\"deviceSecret\":\"%@\",\"sidver\":1,\"message\":\"success\"}",deviceSecret]
-// };
-// NSData *data = [AiMouseTools dictionaryToData:dict];
-// if (self.outputData) self.outputData(data);
-//}
-//#pragma mark -others
-//- (void)showLog:(NSString *)log {
-// if (self.outputLog) self.outputLog([NSString stringWithFormat:@"[auth]%@",log]);
-//}
-//
-//- (void)registerReuest{
-// NSString *deviceId = self.deviceInfo.mac;//设备ID
-// NSString *sn = self.deviceInfo.sn;//SN号
-// NSString *timeStamp = [NSString stringWithFormat:@"%ld",(NSInteger)[NSDate date].timeIntervalSince1970 * 1000];//时间戳
-// NSString *secretKey = self.deviceInfo.secretKey;//产品秘钥
-// NSString *bid = self.deviceInfo.productKey;//产品Key
-// NSString *signMethod = @"HmacSHA1";//签名方法
-//
-//// NSString *deviceId = @"1";//设备ID
-//// NSString *sn = @"2";//SN号
-//// NSString *timeStamp = @"3";//时间戳
-//// NSString *secretKey = @"4";//产品秘钥
-//// NSString *bid = model.productKey;//产品Key
-//// NSString *signMethod = @"HmacSHA1";//签名方法
-//
-// NSString *sign = [self signByDeviceId:deviceId andSN:sn andTimeStamp:timeStamp andSecretKey:secretKey];//签名内容
-//
-// NSDictionary *params = @{
-// @"bid":bid,
-// @"deviceId":deviceId,
-// @"signMethod":signMethod,
-// @"sign":sign,
-// @"timeStamp":timeStamp,
-// @"sn":sn
-// };
-//// NSDictionary *params = @{
-//// @"deviceName":@"C0C20000A5A5",
-//// @"productKey":@"a1c7Ojs6HMR",
-//// @"random":@"1709890896210",
-//// @"sign":@"d0f60c3f61d7d3867f78f44af64638fcff8cbfd",
-//// @"signMethod":@"hmacsha1",
-//// };
-//
-// NSString *url = [NSString stringWithFormat:@"%@/%@",kBaseUrl,kRegisterApi];
-// [self showLog:[NSString stringWithFormat:@"%@ %@",url,params]];
-//
-// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
-// manager.responseSerializer =[AFHTTPResponseSerializer serializer];
-// manager.responseSerializer =[AFHTTPResponseSerializer serializer];
-// manager.requestSerializer = [AFJSONRequestSerializer serializer];
-//
-// AFSecurityPolicy *policy = [AFSecurityPolicy defaultPolicy];
-// policy.allowInvalidCertificates = YES;//客户端是否信任非法证书
-// policy.validatesDomainName = NO;//是否在证书域字段中验证域名
-// manager.securityPolicy = policy;
-//
-// [manager PUT:url parameters:params headers:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
-// NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-// [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
-// NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
-// NSString *code = dict[@"code"];
-// NSString *deviceSecret = [dict valueForKeyPath:@"data.deviceSecret"];
-// if(code.integerValue == 20000 && deviceSecret){
-//
-// [self showLog:@"激活成功"];
-// }
-// else{
-// if(self.authCallBack)self.authCallBack(false);
-// }
-// } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-// [self showLog:[NSString stringWithFormat:@"error = %@",error]];
-// if(self.authCallBack)self.authCallBack(false);
-// }];
-//}
-//- (void)loginRequest:(AiSecretModel *)model{
-// NSString *bid = @"";//品牌ID,管理中心获取
-// NSString *deviceId = @"";//设备ID
-// NSString *signMethod = @"HmacSHA1”";//签名算法
-// NSString *sign = @"";//签名内容
-// NSString *timeStamp = [NSString stringWithFormat:@"%ld",(NSInteger)[[NSDate date] timeIntervalSince1970] * 1000];//时间戳
-// NSString *deviceSecret = @"";//注册返回的密码
-// NSDictionary *params = @{
-// @"bid":bid,
-// @"deviceId":deviceId,
-// @"signMethod":signMethod,
-// @"sign":sign,
-// @"timeStamp":timeStamp,
-// @"deviceSecret":deviceSecret
-// };
-// NSString *url = [NSString stringWithFormat:@"%@/%@",kBaseUrl,kLoginApi];
-// [self showLog:[NSString stringWithFormat:@"%@ %@",url,params]];
-//
-// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
-// manager.responseSerializer =[AFHTTPResponseSerializer serializer];
-// AFSecurityPolicy *policy = [AFSecurityPolicy defaultPolicy];
-// policy.allowInvalidCertificates = YES;
-// policy.validatesDomainName = NO;
-// manager.securityPolicy = policy;
-//
-// [manager POST:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
-// NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-// [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
-// NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
-// NSString *code = dict[@"code"];
-// if(code.integerValue == 20001){
-// [self showLog:@"登录成功"];
-// if(self.authCallBack)self.authCallBack(true);
-// }
-// else{
-// if(self.authCallBack)self.authCallBack(false);
-// }
-// } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-// [self showLog:[NSString stringWithFormat:@"error = %@",error]];
-// if(self.authCallBack)self.authCallBack(false);
-// }];
-//}
-//- (void)tokenAction{
-// NSDictionary *params = @{
-// @"token":@"",
-// };
-// NSString *url = [NSString stringWithFormat:@"%@/%@",kBaseUrl,kTokenApi];
-// [self showLog:[NSString stringWithFormat:@"%@ %@",url,params]];
-//
-// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
-// manager.responseSerializer =[AFHTTPResponseSerializer serializer];
-// manager.requestSerializer = [AFJSONRequestSerializer serializer];
-// AFSecurityPolicy *policy = [AFSecurityPolicy defaultPolicy];
-// policy.allowInvalidCertificates = YES;
-// policy.validatesDomainName = NO;
-// manager.securityPolicy = policy;
-//
-// [manager GET:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
-// NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-// [self showLog:[NSString stringWithFormat:@"返回的数据 = %@",str]];
-// NSDictionary *dict = [AiMouseTools dataToDictionary:responseObject];
-// NSString *code = dict[@"code"];
-// if(code.integerValue == 20000){
-// [self showLog:@"账号已登录"];
-// }
-// } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-// [self showLog:[NSString stringWithFormat:@"error = %@",error]];
-// }];
-//}
-//
-//- (NSString *)signByDeviceId:(NSString *)deviceId andSN:(NSString *)sn andTimeStamp:(NSString *)timeStamp andSecretKey:(NSString *)secretKey{
-// NSString *str = [NSString stringWithFormat:@"%@%@%@",deviceId,sn,timeStamp];
-// NSString *result = [AiMouseTools stringToHmacSha1:secretKey text:str];
-// return result;
-//}
-//@end
--- /dev/null
+//
+// AiConnectManager.h
+// AiMouseSdk
+//
+// Created by incar on 2024/5/28.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+@class AiConnectManager;
+@protocol AiConnectManagerDelegate <NSObject>
+
+- (void)aiConnectManagerDidDisConnect:(AiConnectManager *)manager;
+
+- (void)aiConnectManager:(AiConnectManager *)manager outputLog:(NSString *)log;
+
+@end
+@interface AiConnectManager : NSObject
+@property (nonatomic, weak) id<AiConnectManagerDelegate> delegate;
+
+//- (void)start;
+
+- (void)reset;
+@end
+
+NS_ASSUME_NONNULL_END
--- /dev/null
+//
+// AiConnectManager.m
+// AiMouseSdk
+//
+// Created by incar on 2024/5/28.
+//
+
+#import "AiConnectManager.h"
+
+@interface AiConnectManager()
+@property (nonatomic, assign) NSInteger maxTimes;
+@property (nonatomic, assign) NSInteger currentValue;
+@property (nonatomic, strong) NSTimer *timer;
+@end
+
+@implementation AiConnectManager
+-(instancetype)init{
+ if (self = [super init]) {
+// [self addSendTimer];
+ }
+ return self;
+}
+
+- (void)reset{
+// self.currentValue = 0;
+// self.maxTimes = 5;
+}
+
+#pragma mark - timer
+- (void)addSendTimer{
+ [self removeSendTimer];
+ self.timer = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
+ [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
+}
+- (void)removeSendTimer{
+ if (self.timer && [self.timer isValid]) {
+ [self.timer invalidate];
+ }
+}
+
+- (void)timerAction{
+ self.currentValue++;
+ if (self.currentValue > 1) {
+ [self showLog:[NSString stringWithFormat:@"监听断开连接第 %ld 次超时...",self.currentValue]];
+ //检测
+ }
+
+ if (self.currentValue == self.maxTimes) {
+ [self removeSendTimer];
+ [self showLog:@"设备已断开连接!!!"];
+ if (self.delegate && [self.delegate respondsToSelector:@selector(aiConnectManagerDidDisConnect:)]) {
+ [self.delegate aiConnectManagerDidDisConnect:self];
+ }
+ return;
+ }
+}
+
+- (void)showLog:(NSString *)log{
+ if (self.delegate && [self.delegate respondsToSelector:@selector(aiConnectManager:outputLog:)]) {
+ [self.delegate aiConnectManager:self outputLog:log];
+ }
+}
+@end
/// 设置鉴权
- (void)setAuthStateToDevice:(BOOL)isSuccess;
+
+
+/// 设置录音模式
+/// - Parameters:
+/// - value: 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音
+/// - finished: 设置结果回调
+- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置长按滚轮弹出的网页地址
+/// - Parameters:
+/// - url: 最大长度:49字节
+/// - finished: 设置结果回调
+- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置长按滚轮弹出网页开关
+/// - Parameters:
+/// - state: 0关闭,1打开
+/// - finished: 设置结果回调
+- (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置鼠标连接模式
+/// - Parameters:
+/// - mode: 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式
+/// - finished: 设置结果回调
+- (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+
+/// 获取录音模式
+/// - Parameter complete: mode 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音
+- (void)getRecordMode:(void (^)(int mode,NSError *error))complete;
+
+/// 获取长按滚轮弹出的网页地址
+/// - Parameter complete: url地址
+- (void)getUrl:(void (^)(NSString *url,NSError *error))complete;
+
+/// 获取长按滚轮弹出的网页地址开关状态
+/// - Parameter complete: 0关闭,1打开
+- (void)getUrlState:(void (^)(int state,NSError *error))complete;
+
+/// 获取鼠标连接模式
+/// - Parameter complete: mode
+- (void)getMouseModel:(void (^)(int mode,NSError *error))complete;
+
+/// 开始录音
+- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 结束录音
+- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished;
@end
NS_ASSUME_NONNULL_END
#import "AiMouseConfig.h"
#import "AiSender.h"
+#define kCmd_Key @"cmd"
+#define kSetCmd_Value @"set_config"
+
+
+#define kSetAuthState_Key @"set_activated_dtate"
+#define kSetDeviceSecret_Key @"set_deviceSecret"
+
+#define kSetCPI_Key @"set_CPI"
+#define kSetUrl_Key @"set_official_url"
+#define kSetUrlActive_Key @"set_official_url_switch"
+#define kSetRecordMode_Key @"set_record_mode"
+#define kSetMouseModel_Key @"set_mouse_mode"
+
+
@interface AiDeviceInfoManager()<AiSenderDelegate>
@property (nonatomic, strong) AiSender *sender;
@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
@property (nonatomic, strong) void (^deviceInfoBlock)(AiMouseDeviceInfo *deviceInfo,NSError *error);
-@property (nonatomic, strong) void (^setCPIBlock)(BOOL isSuccess,NSError *error);
@property (nonatomic, strong) void (^getRSSIBlock)(NSString *value,NSError *error);
-@property (nonatomic, strong) AiCmdFinishBlock setDsBlock;
@property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state);
+@property (nonatomic, strong) AiCmdFinishBlock setDsBlock;
+
+@property (nonatomic, strong) void (^setCPIBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setUrlBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setUrlActiveBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setRecordModeBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setMouseModelBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setOpenRecordBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^setCloseRecordBlock)(BOOL isSuccess,NSError *error);
+
+@property (nonatomic, strong) void (^getRecordModeBlock)(int mode,NSError *error);
+@property (nonatomic, strong) void (^getUrlBlock)(NSString *url,NSError *error);
+@property (nonatomic, strong) void (^getUrlStateBlock)(int state,NSError *error);
+@property (nonatomic, strong) void (^getMouseModelBlock)(int mode,NSError *error);
+
@end
NSDictionary *dict = [AiMouseTools stringToDictionary:str2];
// [self showLog:[NSString stringWithFormat:@"总data = %@",[AiMouseTools dataToHexString:data]]];
// [self showLog:[NSString stringWithFormat:@"fix前 = %@",str]];
- [self showLog:[NSString stringWithFormat:@"receive %@",str2]];
+// [self showLog:[NSString stringWithFormat:@"receive %@",str2]];
if (dict == nil) {
if(data.length > 7 && [[AiMouseTools dataToHexString:[data subdataWithRange:NSMakeRange(0, 7)]] .lowercaseString isEqualToString:@"7b22534e223a22"] ){
//SN异常
[self showLog:@"SN未设置!!!"];
self.deviceInfo.sn = @"";
- [self sendDeviceInfoCmd:@{@"cmd":@"get_MAC"}];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_MAC"}];
}
else if(data.length > 15 && [[AiMouseTools dataToHexString:[data subdataWithRange:NSMakeRange(0, 15)]] .lowercaseString isEqualToString:@"7b2264657669636553656372657422"] ){
//deviceSecret异常
// [self showLog:[NSString stringWithFormat:@"总data = %@",[AiMouseTools dataToHexString:data]]];
// [self showLog:[NSString stringWithFormat:@"fix前 = %@",str]];
// [self showLog:[NSString stringWithFormat:@"fix后 = %@",str2]];
- if(dict[@"set_config"]){
- if([dict[@"set_config"] intValue] == 1){
- if ([sender.sendDict objectForKey:@"set_CPI"]) {
- //设置cpi
- self.setCPIBlock(true, nil);
- self.setCPIBlock = nil;
- return;
- }
- if([sender.sendDict objectForKey:@"set_deviceSecret"]){
- //deviceSecret
- self.setDsBlock(true);
- self.setDsBlock = nil;
- }
+ if(dict[kSetCmd_Value]){
+ [self setCmdCallBack:dict sender:sender];
+ }
+ else{
+ [self getCmdCallBack:dict];
+ }
+}
+
+- (void)setCmdCallBack:(NSDictionary *)dict sender:(AiSender *)sender{
+ if([dict[kSetCmd_Value] intValue] == 1){
+ if ([sender.sendDict objectForKey:kSetCPI_Key]) {
+ //设置cpi
+ self.setCPIBlock(true, nil);
+ return;
}
- else{
- NSError *err = [NSError errorWithDomain:@"AiMouse SDK Error" code:1001 userInfo:@{@"NSLocalizedDescriptionKey":@"请求超时"}];
- if ([sender.sendDict objectForKey:@"set_CPI"]) {
- //设置cpi
- if(self.setCPIBlock) self.setCPIBlock(false, err);
- self.setDsBlock = nil;
- return;
- }
- if ([sender.sendDict objectForKey:@"set_deviceSecret"]){
- //设置deviceSecret
- if(self.setDsBlock) self.setDsBlock(false);
- self.setDsBlock = nil;
- return;
- }
+ if([sender.sendDict objectForKey:kSetDeviceSecret_Key]){
+ //deviceSecret
+ self.setDsBlock(true);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetRecordMode_Key]){
+ self.setRecordModeBlock(true, nil);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetUrl_Key]){
+ self.setUrlBlock(true, nil);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetUrlActive_Key]){
+ self.setUrlActiveBlock(true, nil);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetMouseModel_Key]){
+ self.setMouseModelBlock(true, nil);
+ return;
+ }
+ if ([[sender.sendDict objectForKey:kCmd_Key] isKindOfClass:[NSString class]] && [[sender.sendDict objectForKey:kCmd_Key] isEqualTo:@"open_record"]){
+ if(self.setOpenRecordBlock) self.setOpenRecordBlock(true, nil);
+ return;
+ }
+ if ([[sender.sendDict objectForKey:kCmd_Key] isKindOfClass:[NSString class]] && [[sender.sendDict objectForKey:kCmd_Key] isEqualTo:@"close_record"]){
+ if(self.setCloseRecordBlock) self.setCloseRecordBlock(true, nil);
+ return;
}
}
else{
- if (dict[@"battery_power"]) {
- self.deviceInfo.battery_power = dict[@"battery_power"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_CPI"}];
- }
- else if(dict[@"CPI"]) {
- self.deviceInfo.CPI = dict[@"CPI"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_CPI_list"}];
+ NSError *err = [NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_unknown userInfo:@{@"NSLocalizedDescriptionKey":@"请求失败"}];
+ if ([sender.sendDict objectForKey:kSetCPI_Key]) {
+ self.setCPIBlock(false, err);
+ return;
}
- else if(dict[@"CPI_list"]) {
- self.deviceInfo.CPI_list = dict[@"CPI_list"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_version"}];
+ if ([sender.sendDict objectForKey:kSetDeviceSecret_Key]){
+ self.setDsBlock(false);
+ return;
}
- else if(dict[@"version"]) {
- self.deviceInfo.version = dict[@"version"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_brand"}];
+ if([sender.sendDict objectForKey:kSetRecordMode_Key]){
+ self.setRecordModeBlock(false, err);
+ return;
}
- else if(dict[@"brand"]) {
- self.deviceInfo.brand = dict[@"brand"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_SN"}];
+ if([sender.sendDict objectForKey:kSetUrl_Key]){
+ self.setUrlBlock(false, err);
+ return;
}
- else if(dict[@"SN"]) {
- self.deviceInfo.sn = dict[@"SN"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_MAC"}];
+ if([sender.sendDict objectForKey:kSetUrlActive_Key]){
+ self.setUrlActiveBlock(false, err);
+ return;
}
- else if(dict[@"MAC"]) {
- self.deviceInfo.mac = dict[@"MAC"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_productKey"}];
+ if([sender.sendDict objectForKey:kSetMouseModel_Key]){
+ self.setMouseModelBlock(false, err);
+ return;
}
- else if(dict[@"productKey"]) {
- [self.deviceInfo setValue:dict[@"productKey"] forKey:@"productKey"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_secretKey"}];
+ if ([[sender.sendDict objectForKey:kCmd_Key] isKindOfClass:[NSString class]] && [[sender.sendDict objectForKey:kCmd_Key] isEqualTo:@"open_record"]){
+ if(self.setOpenRecordBlock) self.setOpenRecordBlock(false, err);
+ return;
}
- else if(dict[@"secretKey"]) {
- [self.deviceInfo setValue:dict[@"secretKey"] forKey:@"secretKey"];
- [self sendDeviceInfoCmd:@{@"cmd":@"get_deviceSecret"}];
+ if ([[sender.sendDict objectForKey:kCmd_Key] isKindOfClass:[NSString class]] && [[sender.sendDict objectForKey:kCmd_Key] isEqualTo:@"close_record"]){
+ if(self.setCloseRecordBlock) self.setCloseRecordBlock(false, err);
+ return;
}
- else if(dict[@"deviceSecret"]) {
- [self.deviceInfo setValue:dict[@"deviceSecret"] forKey:@"deviceSecret"];
- if(self.deviceInfoBlock){
- [self showLog:self.deviceInfo.description];
- self.deviceInfoBlock(self.deviceInfo, nil);
- self.deviceInfoBlock= nil;
- }
+ }
+}
+
+- (void)getCmdCallBack:(NSDictionary *)dict{
+ if (dict[@"battery_power"]) {
+ self.deviceInfo.battery_power = dict[@"battery_power"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_CPI"}];
+ }
+ else if(dict[@"CPI"]) {
+ self.deviceInfo.CPI = dict[@"CPI"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_CPI_list"}];
+ }
+ else if(dict[@"CPI_list"]) {
+ self.deviceInfo.CPI_list = dict[@"CPI_list"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_version"}];
+ }
+ else if(dict[@"version"]) {
+ self.deviceInfo.version = dict[@"version"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_brand"}];
+ }
+ else if(dict[@"brand"]) {
+ self.deviceInfo.brand = dict[@"brand"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_SN"}];
+ }
+ else if(dict[@"SN"]) {
+ self.deviceInfo.sn = dict[@"SN"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_MAC"}];
+ }
+ else if(dict[@"MAC"]) {
+ self.deviceInfo.mac = dict[@"MAC"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_productKey"}];
+ }
+ else if(dict[@"productKey"]) {
+ [self.deviceInfo setValue:dict[@"productKey"] forKey:@"productKey"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_secretKey"}];
+ }
+ else if(dict[@"secretKey"]) {
+ [self.deviceInfo setValue:dict[@"secretKey"] forKey:@"secretKey"];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_deviceSecret"}];
+ }
+ else if(dict[@"deviceSecret"]) {
+ [self.deviceInfo setValue:dict[@"deviceSecret"] forKey:@"deviceSecret"];
+ if(self.deviceInfoBlock){
+ [self showLog:self.deviceInfo.description];
+ self.deviceInfoBlock(self.deviceInfo, nil);
+ self.deviceInfoBlock= nil;
}
- else if(dict[@"rssi"]) {
- if(self.getRSSIBlock){
- self.getRSSIBlock(dict[@"rssi"],nil);
- }
+ }
+ else if(dict[@"rssi"]) {
+ if(self.getRSSIBlock){
+ self.getRSSIBlock(dict[@"rssi"],nil);
}
}
+ else if(dict[@"official_url"]) {
+ if(self.getUrlBlock)self.getUrlBlock(dict[@"official_url"],nil);
+ }
+ else if(dict[@"official_url_switch"]) {
+ if(self.getUrlStateBlock)self.getUrlStateBlock([dict[@"official_url_switch"] intValue],nil);
+ }
+ else if(dict[@"mouse_mode"]) {
+ if(self.getMouseModelBlock)self.getMouseModelBlock([dict[@"mouse_mode"] intValue],nil);
+ }
+ else if(dict[@"record_mode"]) {
+ if(self.getRecordModeBlock)self.getRecordModeBlock([dict[@"record_mode"] intValue],nil);
+ }
}
- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{
if(self.sender){
- complete(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:1002 userInfo:@{@"NSLocalizedDescriptionKey":@"有命令正在执行中..."}]);
+ complete(nil,[NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_busy userInfo:@{@"NSLocalizedDescriptionKey":@"有命令正在执行中..."}]);
[self showLog:@"有命令正在执行中..."];
return;
}
-
self.deviceInfo = [[AiMouseDeviceInfo alloc] init];
self.deviceInfoBlock = complete;
- NSDictionary *data = @{@"cmd":@"get_battery_power"};
- [self sendDeviceInfoCmd:data];
-
- // NSData *data = [AiMouseTools dictionaryToData:@{@"cmd":@"set_config",@"set_VMouse_SN":[NSString stringWithFormat:@"%@",@"1234567890"]}];
- // [self sendDeviceInfoData:data];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_battery_power"}];
}
/// 获取信号强度
-/// - Parameter completation: 信号强度回调
- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete{
self.getRSSIBlock = complete;
- NSDictionary *data = @{@"cmd":@"get_rssi"};
- [self sendDeviceInfoCmd:data];
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_rssi"}];
}
- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{
self.setCPIBlock = finished;
- NSDictionary *data = @{@"cmd":@"set_config",@"set_CPI":[NSString stringWithFormat:@"%ld",value]};
- [self sendDeviceInfoCmd:data];
+ [self sendDeviceInfoCmd:@{kCmd_Key:kSetCmd_Value,kSetCPI_Key:[NSString stringWithFormat:@"%ld",value]}];
}
- (void)setDeviceSecret:(NSString *)value completation:(AiCmdFinishBlock)complete{
self.setDsBlock = complete;
- NSDictionary *data = @{@"cmd":@"set_config",@"set_deviceSecret":value};
- [self sendDeviceInfoCmd:data];
+ [self sendDeviceInfoCmd:@{kCmd_Key:kSetCmd_Value,kSetDeviceSecret_Key:value}];
}
-(void)setAuthStateToDevice:(BOOL)isSuccess {
-// NSData *data = [AiMouseTools dictionaryToData:@{@"cmd":@"set_config",@"set_activated_dtate":isSuccess?@"1":@"0"}];
+// NSData *data = [AiMouseTools dictionaryToData:@{kCmd_Value:kCmd_Value,kSetAuthState_Key:isSuccess?@"1":@"0"}];
// [self sendDeviceInfoData:data];
- NSDictionary *data = @{@"cmd":@"set_config",@"set_activated_dtate":isSuccess?@"1":@"0"};
+ [self sendDeviceInfoCmd: @{kCmd_Key:kSetCmd_Value,kSetAuthState_Key:isSuccess?@"1":@"0"}];
+}
+
+#pragma mark - new
+/// 设置录音模式
+- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+ self.setRecordModeBlock = finished;
+ NSDictionary *data = @{kCmd_Key:kSetCmd_Value,kSetRecordMode_Key:[NSString stringWithFormat:@"%d",mode]};
[self sendDeviceInfoCmd:data];
}
+/// 设置长按滚轮弹出的网页地址
+- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+ self.setUrlBlock = finished;
+ NSDictionary *data = @{kCmd_Key:kSetCmd_Value,kSetUrl_Key:url};
+ [self sendDeviceInfoCmd:data];
+}
+
+/// 设置长按滚轮弹出网页开关
+- (void)setUrlState:(int)state completation:(void (^)(BOOL, NSError * _Nonnull))finished{
+ self.setUrlActiveBlock = finished;
+ NSDictionary *data = @{kCmd_Key:kSetCmd_Value,kSetUrlActive_Key:[NSString stringWithFormat:@"%d",state]};
+ [self sendDeviceInfoCmd:data];
+}
+
+/// 设置鼠标连接模式
+- (void)setMouseMode:(int)mode completation:(void (^)(BOOL, NSError * _Nonnull))finished{
+ self.setMouseModelBlock = finished;
+ NSDictionary *data = @{kCmd_Key:kSetCmd_Value,kSetMouseModel_Key:[NSString stringWithFormat:@"%d",mode]};
+ [self sendDeviceInfoCmd:data];
+}
+/// 获取录音模式
+- (void)getRecordMode:(void (^)(int mode,NSError *error))complete{
+ self.getRecordModeBlock = complete;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_record_mode"}];
+}
+
+/// 获取长按滚轮弹出的网页地址
+- (void)getUrl:(void (^)(NSString *url,NSError *error))complete{
+ self.getUrlBlock = complete;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_official_url"}];
+}
+
+/// 获取长按滚轮弹出的网页地址开关状态
+/// - Parameter complete: 0关闭,1打开
+- (void)getUrlState:(void (^)(int state,NSError *error))complete{
+ self.getUrlStateBlock = complete;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_official_url_switch"}];
+}
+
+/// 获取鼠标连接模式
+/// - Parameter complete: mode
+- (void)getMouseModel:(void (^)(int mode,NSError *error))complete{
+ self.getMouseModelBlock = complete;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"get_mouse_mode"}];
+}
+/// 开始录音
+- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{
+ self.setOpenRecordBlock = finished;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"open_record"}];
+}
+
+/// 结束录音
+- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{
+ self.setCloseRecordBlock = finished;
+ [self sendDeviceInfoCmd:@{kCmd_Key:@"close_record"}];
+}
#pragma mark - AiSenderDelegate
- (void)aiSender:(AiSender *)sender reSendCmd:(NSDictionary *)dict{
[self sendCmdToBle:dict];
[self showLog:@"指令超时..."];
- NSString *cmd = [sender.sendDict objectForKey:@"cmd"];
+ NSString *cmd = [sender.sendDict objectForKey:kCmd_Key];
if (![cmd isKindOfClass:[NSString class]] ) {
return;
}
- NSError *err = [NSError errorWithDomain:@"AiMouse SDK Error" code:1001 userInfo:@{@"NSLocalizedDescriptionKey":@"请求超时"}];
- if ([sender.sendDict objectForKey:@"set_CPI"]) {
- //设置cpi
- if(self.setCPIBlock) self.setCPIBlock(false, err);
- self.setDsBlock = nil;
+ NSError *err = [NSError errorWithDomain:@"AiMouse SDK Error" code:AiMouseErrorCode_timeOut userInfo:@{@"NSLocalizedDescriptionKey":@"请求超时"}];
+ if ([sender.sendDict objectForKey:kSetCPI_Key]) {
+ self.setCPIBlock(false, err);
return;
}
- if ([sender.sendDict objectForKey:@"set_deviceSecret"]){
- //设置deviceSecret
- if(self.setDsBlock) self.setDsBlock(false);
- self.setDsBlock = nil;
+ if ([sender.sendDict objectForKey:kSetDeviceSecret_Key]){
+ self.setDsBlock(false);
return;
}
- if ([sender.sendDict objectForKey:@"set_activated_dtate"]){
- //设置是否已鉴权
+ if([sender.sendDict objectForKey:kSetRecordMode_Key]){
+ self.setRecordModeBlock(false, err);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetUrl_Key]){
+ self.setUrlBlock(false, err);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetUrlActive_Key]){
+ self.setUrlActiveBlock(false, err);
+ return;
+ }
+ if([sender.sendDict objectForKey:kSetMouseModel_Key]){
+ self.setMouseModelBlock(false, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"open_record"]){
+ if(self.setOpenRecordBlock) self.setOpenRecordBlock(false, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"close_record"]){
+ if(self.setCloseRecordBlock) self.setCloseRecordBlock(false, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"get_record_mode"]){
+ if(self.getRecordModeBlock) self.getRecordModeBlock(0, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"get_official_url"]){
+ if(self.getUrlBlock) self.getUrlBlock(nil, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"get_official_url_switch"]){
+ if(self.getUrlStateBlock) self.getUrlStateBlock(0, err);
+ return;
+ }
+ if ([cmd isEqualTo:@"get_mouse_mode"]){
+ if(self.getMouseModelBlock) self.getMouseModelBlock(0, err);
return;
}
-
if ([cmd isEqualTo:@"get_rssi"]){
if(self.getRSSIBlock) self.getRSSIBlock(nil, err);
- self.getRSSIBlock = nil;
return;
}
-
+ if ([sender.sendDict objectForKey:kSetAuthState_Key]){
+ //设置是否已鉴权
+ return;
+ }
+
if(self.deviceInfoBlock) self.deviceInfoBlock(nil,err);
self.deviceInfoBlock = nil;
}
if(self.sender){
[self showLog:@"有命令正在执行中.."];
return;
-// [self.sender remove];
-// self.sender = nil;
}
self.sender = [[AiSender alloc] initWithCmd:dict];
self.sender.delegate = self;
-
[self sendCmdToBle:dict];
}
- (void)sendCmdToBle:(NSDictionary *)dict{
-// NSString *str = [AiMouseTools dataToUtf8String:data];
-// NSMutableString *str1 = [NSMutableString stringWithString:str];
-//
-// NSString *sendStr = [NSString stringWithFormat:@"-$$%@$$-\n",str1];
-// NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding];
-// [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]];
-// if (self.delegate) {
-// [self.delegate aiMouseSendDeviceInfoData:sendData];
-// }
-
NSData *data = [AiMouseTools dictionaryToData:dict];
NSString *str = [AiMouseTools dataToUtf8String:data];
NSArray *list = [self splitCMD:str];
}
- (void)sendToBle:(NSString *)cmd{
NSData *data = [cmd dataUsingEncoding:NSUTF8StringEncoding];
- [self showLog:[NSString stringWithFormat:@"send %@",cmd]];
+// [self showLog:[NSString stringWithFormat:@"send %@",cmd]];
if (self.sendToBleBlock) {
self.sendToBleBlock(data);
}
@property (nonatomic, strong) NSString *brand;/// 品牌名称
@property (nonatomic, strong) NSString *sn;/// 设备序列号
@property (nonatomic, strong) NSString *mac;///设备MAC地址
-
@end
+typedef NS_ENUM(NSInteger,AiMouseErrorCode) {
+ AiMouseErrorCode_timeOut = 1001,///请求超时
+ AiMouseErrorCode_busy = 1002,/// 繁忙,有命令未执行完
+ AiMouseErrorCode_unknown = 1003,/// 未知错误
+};
+
+/// 日志等级
typedef NS_ENUM(NSInteger,AiMouseLogLevel) {
AiMouseLogLevel_none = 0,
AiMouseLogLevel_error,
/// - finished: 设置结果回调
- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+/// 设置录音模式
+/// - Parameters:
+/// - value: 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音
+/// - finished: 设置结果回调
+- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置长按滚轮弹出的网页地址
+/// - Parameters:
+/// - url: 最大长度:49字节
+/// - finished: 设置结果回调
+- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置长按滚轮弹出网页开关
+/// - Parameters:
+/// - state: 0关闭,1打开
+/// - finished: 设置结果回调
+- (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 设置鼠标连接模式
+/// - Parameters:
+/// - mode: 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式
+/// - finished: 设置结果回调
+- (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+
+/// 获取录音模式
+/// - Parameter complete: mode 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音 。error为nil才代表获取成功
+- (void)getRecordMode:(void (^)(int mode,NSError *error))complete;
+
+/// 获取长按滚轮弹出的网页地址
+/// - Parameter complete: url地址 。error为nil才代表获取成功
+- (void)getUrl:(void (^)(NSString *url,NSError *error))complete;
+
+/// 获取长按滚轮弹出的网页地址开关状态
+/// - Parameter complete: state 0关闭,1打开。 error为nil才代表获取成功
+- (void)getUrlState:(void (^)(int state,NSError *error))complete;
+
+/// 获取鼠标连接模式
+/// - Parameter complete: mode 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式 。error为nil才代表获取成功
+- (void)getMouseModel:(void (^)(int mode,NSError *error))complete;
+
+/// 打开录音
+/// - finished: 执行结果回调
+- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished;
+/// 关闭录音
+/// - finished: 执行结果回调
+- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished;
@end
#import "AiMouseSdk.h"
#import "AiDeviceInfoManager.h"
-#import "AiFrameManager.h"
#import "AiAuthManager.h"
#import "AiAudioManager.h"
#import "AiMouseTools.h"
#import "AiMouseTools2.h"
#import "AiMouseConfig.h"
#import "AiRecordManager.h"
+#import "AiConnectManager.h"
@interface AiMouseDeviceInfo()
@property (nonatomic, strong) NSString *productKey;/// 品牌key
@end
@implementation AiMouseDeviceInfo
-(NSString *)description{
- NSString *info = [NSString stringWithFormat:@"\n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@",self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret];
+// NSString *info = [NSString stringWithFormat:@"\n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@ \n record_mode = %@ \n mouse_mode = %@ \n url = %@ \n urlActive = %@ ",self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret,self.record_mode,self.mouse_mode,self.url,self.urlActive];
+
+ NSString *info = [NSString stringWithFormat:@"\n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@ ",self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret];
return info;
}
@end
@interface AiMouse()
@property (nonatomic, assign) AiMouseLogLevel logLevel;
-@property (nonatomic, strong) AiFrameManager *frameManager;
@property (nonatomic, strong) AiAuthManager *authManager;
@property (nonatomic, strong) AiAudioManager *audioManager;
@property (nonatomic, strong) AiRecordManager *recordManager;
@property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state);
@property (nonatomic, strong) AiDeviceInfoManager *deviceInfoManager;
@property (nonatomic, strong) NSString *updateDeviceSecret;//更新的deviceSecret
+
+@property (nonatomic, strong) AiConnectManager *connectManager;
+
@end
@implementation AiMouse
}
-(NSString *)version{
- return @"1.0.16";
-}
--(AiFrameManager *)frameManager{
- if (!_frameManager) {
- _frameManager = [[AiFrameManager alloc] init];
- __weak typeof(self) ws = self;
- _frameManager.didReceiveFullData = ^(NSData * _Nonnull data) {
-// [ws.authManager receiveData:data];
- };
- }
- return _frameManager;
+ return @"1.0.18";
}
-(AiDeviceInfoManager *)deviceInfoManager{
__weak typeof(self) ws = self;
_deviceInfoManager.sendToBleBlock = ^(NSData * _Nonnull data) {
if (ws.delegate) {
+ [ws showLog:[NSString stringWithFormat:@"[send] %@",data]];
[ws.delegate aiMouseSendDeviceInfoData:data];
}
};
};
_authManager.authCallBack = ^(BOOL isSuccess) {
[ws authResult:isSuccess];
+// [ws setDeviceSecret:@"" completation:nil];
};
}
return _authManager;
}
return _recordManager;
}
+
+-(AiConnectManager *)connectManager{
+ if (!_connectManager) {
+ _connectManager = [[AiConnectManager alloc] init];
+ }
+ return _connectManager;
+}
#pragma mark - pub Api
- (void)setLogLevel:(AiMouseLogLevel)level{
_logLevel = level;
}];
}
-////接收到设备传过来的数据
-//- (void)sendAuthDataToSdk:(NSData *)data{
-// [self.frameManager didReceiveFrameData:data];
-//}
-
- (void)sendAiDataToSdk:(NSData *)data{
+ [self.connectManager reset];
+
+ [self showLog:[NSString stringWithFormat:@"[receive][Ai] %@",data]];
if(self.connectType == AiMouseConnectType_hid){
// 0AFFFF12BC32
if(data.length == 6){
}
}
+#pragma mark - deviceInfoManager
-(void)sendDeviceDataToSdk:(NSData *)data{
+ [self.connectManager reset];
+ [self showLog:[NSString stringWithFormat:@"[receive][device] %@",data]];
[self.deviceInfoManager receiveData:data];
}
-- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{
- [self.deviceInfoManager getDeviceInfo:complete];
-}
-
-/// 获取信号强度
-/// - Parameter completation: 信号强度回调
-- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete{
- [self.deviceInfoManager getRSSI:complete];
-}
-- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{
- [self.deviceInfoManager setCPI:value completation:finished];
-}
-
- (void)setDeviceSecret:(NSString *)value completation:(AiCmdFinishBlock)complete{
self.updateDeviceSecret = value;
-
__weak typeof(self) ws = self;
[self.deviceInfoManager setDeviceSecret:value completation:^(BOOL isSuccess) {
if (isSuccess) {
}
}];
}
-
-- (void)setDS{
-// NSString *value = @"JXa2HAaXhaw5mnbjqadtMQQoDQOmGGQw";
- NSString *value = @"JXa2HAaXhaw5mnbjqadtMQQoDQOmGGQw";
- [self setDeviceSecret:value completation:^(BOOL isSuccess) {
-// NSLog(@"写入ds成功========");
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{
+ [self.deviceInfoManager getDeviceInfo:complete];
+}
+- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete{
+ [self.deviceInfoManager getRSSI:complete];
+}
+- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+ [self.deviceInfoManager setCPI:value completation:finished];
+}
+/// 设置录音模式
+- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+ [self.deviceInfoManager setRecordMode:mode completation:finished];
+}
+/// 设置长按滚轮弹出的网页地址
+- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+ [self.deviceInfoManager setUrl:url completation:finished];
+}
+/// 设置长按滚轮弹出网页开关
+- (void)setUrlState:(int)state completation:(void (^)(BOOL, NSError *))finished{
+ [self.deviceInfoManager setUrlState:state completation:finished];
+}
+/// 设置鼠标连接模式
+- (void)setMouseMode:(int)mode completation:(void (^)(BOOL, NSError *))finished{
+ [self.deviceInfoManager setMouseMode: mode completation:finished];
+}
+/// 获取录音模式
+- (void)getRecordMode:(void (^)(int mode,NSError *error))complete{
+ [self.deviceInfoManager getRecordMode:complete];
+}
+/// 获取长按滚轮弹出的网页地址
+- (void)getUrl:(void (^)(NSString *url,NSError *error))complete{
+ [self.deviceInfoManager getUrl:complete];
+}
+/// 获取长按滚轮弹出的网页地址开关状态
+- (void)getUrlState:(void (^)(int state,NSError *error))complete{
+ [self.deviceInfoManager getUrlState:complete];
+}
+/// 获取鼠标连接模式
+- (void)getMouseModel:(void (^)(int mode,NSError *error))complete{
+ [self.deviceInfoManager getMouseModel:complete];
+}
+/// 开始录音
+- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{
+ __weak typeof(self) ws = self;
+ [self.deviceInfoManager openRecord:^(BOOL isSuccess, NSError * _Nonnull error) {
+ finished(isSuccess,error);
+ if (isSuccess) {
+ uint8 value = 0x31;
+ NSData *cmd = [NSData dataWithBytes:&value length:1];
+ [ws sendCmdData:cmd];
+
+ if(self.connectType == AiMouseConnectType_hid){
+ [ws startRecord];
+ }
+ }
+ }];
+}
+/// 结束录音
+- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{
+ __weak typeof(self) ws = self;
+ [self.deviceInfoManager closeRecord:^(BOOL isSuccess, NSError * _Nonnull error) {
+ finished(isSuccess,error);
+
+ if (isSuccess) {
+ uint8 value = 0x32;
+ NSData *cmd = [NSData dataWithBytes:&value length:1];
+ [ws sendCmdData:cmd];
+
+ if(self.connectType == AiMouseConnectType_hid){
+ [ws stopRecord];
+ }
+ }
}];
}
-
#pragma mark - other
-
- (void)sendRecordData:(NSData *)data{
if (self.authState != AiMouseAuthState_Success){
[self showLog:@"设备还未鉴权!!!"];
return;
};
+ [self showLog:[NSString stringWithFormat:@"[audio] %@",data]];
if (self.delegate) [self.delegate aiMouseSendRecordData:data];
}
- (void)sendCmdData:(NSData *)data{
[self showLog:@"设备还未鉴权!!!"];
return;
}
+ [self showLog:[NSString stringWithFormat:@"[send] %@",data]];
if (self.delegate) [self.delegate aiMouseSendCmdData:data];
}
}
#pragma mark - deviceInfo
-
- (void)startRecord{
// [self showLog:@"开始录音"];
[self.recordManager start];
[self.recordManager stop];
// [self showLog:@"结束录音"];
}
-
-
@end
#pragma mark - timer
- (void)addSendTimer{
[self removeSendTimer];
-// dispatch_async(dispatch_queue_create("DeviceQueue", DISPATCH_QUEUE_SERIAL), ^{
-// self.number = 0;
-// self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
-// [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
-// [[NSRunLoop currentRunLoop] run];
-// });
self.timer = [NSTimer timerWithTimeInterval:0.2 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)timerAction{
self.number++;
- if (self.number == 5) {
+ if (self.number == 10) {
[self removeSendTimer];
if (self.delegate && [self.delegate respondsToSelector:@selector(aiSenderRecieveTimeOut:)]) {
[self.delegate aiSenderRecieveTimeOut:self];
if(self.didDisConnectDevice){
self.didDisConnectDevice(peripheral);
}
- [self autoConnectDevice];
+// [self autoConnectDevice];
}
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error{
[self showLog:[NSString stringWithFormat:@"连接失败。。。%@",error.description]];
//收到蓝牙数据
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
NSData *data = characteristic.value;
- [self showLog:[NSString stringWithFormat:@"[receive] %@",data]];
+// [self showLog:[NSString stringWithFormat:@"[receive] %@",data]];
if([characteristic.UUID.UUIDString isEqualToString:kAiUUID]){
//AI数据
[[AiMouse shared] sendAiDataToSdk:data];
/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备
/// - Parameter data: 数据
-(void)aiMouseSendDeviceInfoData:(NSData *)data{
- [self showLog:[NSString stringWithFormat:@"[send] %@",data]];
+// [self showLog:[NSString stringWithFormat:@"[send] %@",data]];
[self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];
}
uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey));
if(PrimaryUsagePage == 1 && PrimaryUsage == 0){
- [[HidManager shared] showLog:[NSString stringWithFormat:@"收到device数据 %@",data]];
+// [[HidManager shared] showLog:[NSString stringWithFormat:@"收到device数据 %@",data]];
[[AiMouse shared] sendDeviceDataToSdk:data];
}
else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){
- [[HidManager shared] showLog:[NSString stringWithFormat:@"收到AI数据 %@",data]];
+// [[HidManager shared] showLog:[NSString stringWithFormat:@"收到AI数据 %@",data]];
[[AiMouse shared] sendAiDataToSdk:data];
}
}
[self showLog:@"请先连上设备"];
return;
}
- [self showLog:[NSString stringWithFormat:@"开始发送[send] %@",data]];
+// [self showLog:[NSString stringWithFormat:@"开始发送[send] %@",data]];
IOReturn ret = IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 0, data.bytes, data.length);
if (ret != kIOReturnSuccess) {
- (void)setupUI{
self.title = @"AI SDK";
-// {
-// NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height + 80, 100, 45)];
-// btn.bordered = true;
-// btn.title = @"设置CPI";
-// [btn setTarget:self];
-// [btn setAction:@selector(cpiAction)];
-// btn.state = 1;
-// [self.view addSubview:btn];
-// }
-// {
-// NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height, 100, 45)];
-// btn.bordered = true;
-// btn.title = @"写入deviceScrect";
-// [btn setTarget:self];
-// [btn setAction:@selector(deviceScrectAction)];
-// btn.state = 1;
-// [self.view addSubview:btn];
-// }
+ {
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height + 240, 100, 45)];
+ btn.bordered = true;
+ btn.title = @"openAction";
+ [btn setTarget:self];
+ [btn setAction:@selector(openAction)];
+ btn.state = 1;
+ [self.view addSubview:btn];
+ }
+ {
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height + 160, 100, 45)];
+ btn.bordered = true;
+ btn.title = @"closeAction";
+ [btn setTarget:self];
+ [btn setAction:@selector(closeAction)];
+ 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 = @"set";
+ [btn setTarget:self];
+ [btn setAction:@selector(setAction)];
+ btn.state = 1;
+ [self.view addSubview:btn];
+ }
+ {
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height, 100, 45)];
+ btn.bordered = true;
+ btn.title = @"get";
+ [btn setTarget:self];
+ [btn setAction:@selector(getAction)];
+ 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;
[self presentViewControllerAsModalWindow:vc];
}
-- (void)cpiAction{
- [[AiMouse shared] setCPI:1000 completation:^(BOOL isSuccess, NSError *error) {
- NSLog(@"%@",[NSString stringWithFormat:@"cpi设置结果 = %@",@(isSuccess)]);
+- ( void)openAction{
+ [[AiMouse shared] openRecord:^(BOOL isSuccess, NSError *error) {
+ if(error == nil){
+ NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %@",@(isSuccess)]);
+ }
+ else{
+ NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+ }
+ }];
+}
+- ( void)closeAction{
+ [[AiMouse shared] closeRecord:^(BOOL isSuccess, NSError *error) {
+ if(error == nil){
+ NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %@",@(isSuccess)]);
+ }
+ else{
+ NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+ }
+ }];
+}
+- (void)setAction{
+ [[AiMouse shared] setRecordMode:0 completation:^(BOOL isSuccess, NSError *error) {
+ NSLog(@"%@",[NSString stringWithFormat:@"设置结果 = %@",@(isSuccess)]);
}];
+
+
+// [[AiMouse shared] setUrl:@"https://www.baidu.com" completation:^(BOOL isSuccess, NSError *error) {
+// NSLog(@"%@",[NSString stringWithFormat:@"设置结果 = %@",@(isSuccess)]);
+// }];
+
+// [[AiMouse shared] setUrlState:1 completation:^(BOOL isSuccess, NSError *error) {
+// NSLog(@"%@",[NSString stringWithFormat:@"设置结果 = %@",@(isSuccess)]);
+// }];
+//
+// [[AiMouse shared] setMouseMode:0 completation:^(BOOL isSuccess, NSError *error) {
+// NSLog(@"%@",[NSString stringWithFormat:@"设置结果 = %@",@(isSuccess)]);
+// }];
}
-- (void)deviceScrectAction{
-// [[AiMouse shared] setDS];
+- (void)getAction{
+ [[AiMouse shared] getRecordMode:^(int mode, NSError *error) {
+ if(error == nil){
+ NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %@",@(mode)]);
+ }
+ else{
+ NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+ }
+ }];
+
+
+// [[AiMouse shared] getUrl:^(NSString *url, NSError *error) {
+// if(error == nil){
+// NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %@",url]);
+// }
+// else{
+// NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+// }
+// }];
+
+// [[AiMouse shared] getUrlState:^(int state, NSError *error) {
+// if(error == nil){
+// NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %d",state]);
+// }
+// else{
+// NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+// }
+// }];
+
+// [[AiMouse shared] getMouseModel:^(int state, NSError *error) {
+// if(error == nil){
+// NSLog(@"%@",[NSString stringWithFormat:@"获取结果 = %d",state]);
+// }
+// else{
+// NSLog(@"%@",[NSString stringWithFormat:@"错误 = %@",error.description]);
+// }
+// }];
}
/// 获取设备信息