泰凌微DPI修改
authorliangzhenying <867174124@qq.com>
Thu, 5 Sep 2024 02:22:08 +0000 (10:22 +0800)
committerliangzhenying <867174124@qq.com>
Thu, 5 Sep 2024 02:22:08 +0000 (10:22 +0800)
MouseSdk/AiMouseSdk/Manager/DeviceManger.m
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.h
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk/ViewController.m

index fde7184..529e8bc 100644 (file)
 /// 设置CPI
 - (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{
     if (self.productType == AiMouseProductType_tlw) {
-        NSDictionary *dict = @{
-            @"800":@"0",
-            @"1200":@"1",
-            @"1600":@"2",
-            @"2400":@"3",
-        };
-        
-        if (dict[[NSString stringWithFormat:@"%ld",value]]) {
-            int num = [dict[[NSString stringWithFormat:@"%ld",value]] intValue];
-            [self.tlwSdk setDPI:num completation:finished];
-        }
-        else{
-            [self showLog:[NSString stringWithFormat:@"CPI值设置错误 %ld",value]];
-            [self.tlwSdk setDPI:0 completation:finished];
-        }
+        [self.tlwSdk setDPI:value completation:finished];
     }
     else{
         [self.frkSdk setCPI:value completation:finished];
index 005d5ef..4f38ca2 100644 (file)
@@ -9,7 +9,7 @@
 #import "AiMouseSdk.h"
 
 @interface TlwDeviceInfo : NSObject
-@property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应 800 1200 1800 2400)
+@property (nonatomic, assign) int DPI;/// DPI值 数值1 ~ 4 (分别对应1200,1600,2400,4800)
 @property (nonatomic, assign) int version;///软件版本
 @property (nonatomic, assign) int batteryState;/// 电池状态
 @property (nonatomic, assign) int batteryValue;/// 电池百分百电量,0-100
@@ -100,9 +100,8 @@ typedef NS_ENUM(NSInteger,TlwMouseLogLevel) {
 
 /// 设置DPI
 /// - Parameters:
-///   - value: 数值1 ~ 4 (分别对应 800 1200 1800 2400)
 ///   - finished: 设置结果回调
-- (void)setDPI:(uint8_t)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;
+- (void)setDPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;
 
 /// 打开录音
 /// - finished: 执行结果回调
index d5ab773..786d336 100644 (file)
     
 }
 
-- (void)setDPI:(uint8_t)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+- (void)setDPI:(NSInteger)num completation:(void (^)(BOOL isSuccess,NSError *error))finished{
+    NSDictionary *dict = @{
+        @"1200":@"1",
+        @"1600":@"2",
+        @"2400":@"3",
+        @"4800":@"4",
+    };
+    NSString *valueString = dict[[NSString stringWithFormat:@"%ld",num]];
+    if (valueString == nil) {
+        valueString = @"1";
+        [self showLog:[NSString stringWithFormat:@"CPI值设置错误 %ld",num]];
+    }
+    uint8_t value = [valueString intValue];
+    if (value < 1 || value > 4) {
+        value = 1;
+    }
+    
     if(self.connectType == AiMouseConnectType_hid){
         self.setDpiCallBack  = finished;
         uint8_t type = 0x06;
     __weak typeof(self) ws = self;
     [self getDeviceInfo:^(TlwDeviceInfo *deviceInfo, NSError *error) {
         if(deviceInfo != nil){
-            NSString *CPI_list = @"800,1200,1600,2400";// 0-3,800 1200 1600 2400
-            NSString *cpi = @"0";
+            NSDictionary *dict = @{
+                @"1200":@"1",
+                @"1600":@"2",
+                @"2400":@"3",
+                @"4800":@"4",
+            };
             
-            if ([CPI_list componentsSeparatedByString:@","].count - 1 >= deviceInfo.DPI) {
-                cpi = [[CPI_list componentsSeparatedByString:@","] objectAtIndex:deviceInfo.DPI];
+            NSString *CPI_list = [[dict allKeys] componentsJoinedByString:@","];
+            NSString *level = [NSString stringWithFormat:@"%d",deviceInfo.DPI];
+            NSString *dpiValue = @"1200";
+            
+            for (NSString *key in dict) {
+                if ([dict[key] isEqualToString:level]) {
+                    dpiValue = key;
+                    break;;
+                }
             }
             
             AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init];
             info.battery_power = [NSString stringWithFormat:@"%d",deviceInfo.batteryValue] ;
             info.version = [NSString stringWithFormat:@"%d",deviceInfo.version];
             info.CPI_list = CPI_list;
-            info.CPI = cpi;
+            info.CPI = dpiValue;
             ws.fullInfo = info;
             
             [ws getSnInfo:^(TlwSnInfo *snInfo, NSError *error) {
index 9f0e1a7..c7d5c48 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index 8bda9cd..4f1c465 100644 (file)
@@ -2,6 +2,7 @@
 #import "ViewController.h"
 #import "ScanVC.h"
 #import "DeviceManger.h"
+#import "Config.h"
 @interface ViewController ()
 @property(nonatomic,strong)NSTextField *typeLabel;///当前模式状态
 @property(nonatomic,strong)NSTextField *connectLabel;///连接状态
@@ -94,6 +95,9 @@
 //    [AiHidManager shared];
     DeviceManger *manager = [DeviceManger shared];
     __weak typeof(self) ws = self;
+    manager.aiMouseAddLogCallBack = ^(NSString * _Nonnull log) {
+        NSLog(@"%@",log);
+    };
     manager.authCallBack = ^(BOOL isSuccess) {
         dispatch_async(dispatch_get_main_queue(), ^{
             ws.authLabel.stringValue = isSuccess?@"鉴权状态:鉴权成功":@"鉴权状态:鉴权失败";
     }];
 }
 - (void)setDPI:(NSMenuItem*)sender {
-    [[DeviceManger shared] setCPI:800 completation:^(BOOL isSuccess, NSError * _Nonnull error) {
+    [[DeviceManger shared] setCPI:1600 completation:^(BOOL isSuccess, NSError * _Nonnull error) {
         
     }];
 }