| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- #import "SensorPlugin.h"
- #import <sys/utsname.h>
- #import "AppEventChannel.h"
- #import<CoreMotion/CoreMotion.h>
- #import <CoreBluetooth/CoreBluetooth.h>
- #import <CoreLocation/CoreLocation.h>
- #import <CoreLocation/CLLocationManager.h>
- @interface SensorPlugin()<FLTSensorApi, CLLocationManagerDelegate, CBCentralManagerDelegate, BLEManagerDelegate, BLEDeviceDelegate> {
- FlutterEventSink flutterEventSink;
- FlutterEventChannel* flutterEventChannel;
- // CBCM对象
- CBCentralManager* CM;
- // 位置服务对象
- CLLocationManager * locationManager;
- UInt64 isOpenLastTime;
- bool isOpen;
- // 当前位置
- FLTPosition *fltPosition;
- // 陀螺仪传感器
- CMMotionManager *motionManager;
- // 返回的陀螺仪数据
- FLTOrientation *newOriention;
- // 蓝牙是否打开
- bool isBLOpen;
- // bleManager 对象
- HeartBLEManager *bleManager;
- // 扫描出的设备
- NSArray *ListPeripheral;
- // 当前连接设备
- HeartBLEDevice *BleDevice;
- // 心率交换池数组
- NSMutableArray *ListFLTHr;
- AppEventChannel *channelLocation;
- AppEventChannel *channelOriention;
- }
- @property (nonatomic, strong) FlutterEventSink eventSink;
- @property (nonatomic, strong) FlutterEventChannel *eventChannel ;
- @end
- @implementation SensorPlugin
- + (instancetype)sharedInstance {
- static SensorPlugin *instance = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- instance = [[self alloc] init];
- });
- return instance;
- }
- + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
- //注册methodChannel
- FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"sensor" binaryMessenger:[registrar messenger]];
- [registrar addMethodCallDelegate:SensorPlugin.sharedInstance channel:channel];
-
-
- //初始化streamChannel
- AppEventChannel *evenChannal = [[AppEventChannel alloc]initWithNameMessge:registrar :@"com.beswell.sensor.event/location"];
- SensorPlugin.sharedInstance -> channelLocation = evenChannal;
-
- AppEventChannel *channelOri = [[AppEventChannel alloc]initWithNameMessge:registrar :@"com.beswell.sensor.event/orientation"];
- SensorPlugin.sharedInstance -> channelOriention = channelOri;
-
- AppEventChannel *channelHrm = [[AppEventChannel alloc]initWithNameMessge:registrar :@"com.beswell.sensor.event/HRM"];
-
- AppEventChannel *channelWearScan = [[AppEventChannel alloc]initWithNameMessge:registrar :@"com.beswell.sensor.event/SportWearScanResult"];
-
- AppEventChannel *channelWearConn = [[AppEventChannel alloc]initWithNameMessge:registrar :@"com.beswell.sensor.event/SportWearConnected"];
-
-
- //初始化SensorApi
- FLTSensorApiSetup(registrar.messenger, SensorPlugin.sharedInstance);
- }
- // 构造函数,初始化一些变量
- -(id) init {
- NSLog(@"init struct");
- if (self=[super init]) {
- NSLog(@"init page obj");
- //初始化
- motionManager = [[CMMotionManager alloc] init];
- //设置更新间隔每秒60次
- motionManager.deviceMotionUpdateInterval = 1.0 / 60.0;
- //开启陀螺仪
- if (motionManager.isDeviceMotionAvailable) {
- [motionManager startDeviceMotionUpdates];
- }
- [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) {
-
- if(self->newOriention == nil){
- self->newOriention = [[FLTOrientation alloc]init];
- }
-
- // Gravity 获取手机的重力值在各个方向上的分量,根据这个就可以获得手机的空间位置,倾斜角度等
- double gravityX = motion.gravity.x;
- double gravityY = motion.gravity.y;
- double gravityZ = motion.gravity.z;
-
- // 获取手机的倾斜角度(zTheta是手机与水平面的夹角, xyTheta是手机绕自身旋转的角度):
- double zTheta = atan2(gravityZ,sqrtf(gravityX * gravityX + gravityY * gravityY)) / M_PI * 180.0;
- double xyTheta = atan2(gravityX, gravityY) / M_PI * 180.0;
- // NSLog(@"手机与水平面的夹角 --- %.4f, 手机绕自身旋转的角度为 --- %.4f", zTheta, xyTheta);
-
- [self->newOriention setX:[[NSNumber alloc] initWithDouble:motion.gravity.x]];
- [self->newOriention setY:[[NSNumber alloc] initWithDouble:motion.gravity.y]];
-
-
- if(self->channelOriention != nil){
- [self->channelOriention success: @[
- (self->newOriention.x ?: [NSNull null]),
- (self->newOriention.y ?: [NSNull null]),
- (self->newOriention.z ?: [NSNull null]),
- ]
- ];
- }
-
- }];
- // 实例化bleManager
- bleManager = [HeartBLEManager sharedInstance];
- // 设置蓝牙代理
- [bleManager setDelegate:self];
- // 初始化心率数组
- ListFLTHr = [[NSMutableArray alloc]initWithCapacity:64];
- // 初始化蓝牙协议对象
- CM = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
- // 初始化位置对象
- fltPosition = [[FLTPosition alloc]init];
- }
- return self;
- }
- //StreamLocation
- /**
-
- */
- - (void)locationStartMinTimeMs:(NSNumber *)minTimeMs minDistanceM:(NSNumber *)minDistanceM error:(FlutterError * _Nullable __autoreleasing *)error{
- int isOpenTime = [[NSDate date] timeIntervalSince1970];
-
- if(isOpenTime - isOpenLastTime > 5){
- // NSLog(@"isLocationServiceOpenWithError%llu",(isOpenTime - isOpenLastTime));
-
- if ([CLLocationManager locationServicesEnabled]) {
- isOpen = true;
-
- if (locationManager == nil) {
- locationManager = [[CLLocationManager alloc] init];
- locationManager.delegate = self;
- [locationManager startUpdatingHeading];// 请求方向
- [locationManager requestAlwaysAuthorization];// 请求前台和后台定位权限 ios >= 8.0
- // [locationManager startUpdatingLocation];// 请求前台定位权限
- NSLog(@"init locationManager");
- }
-
- }else {
- isOpen = false;
- }
-
- isOpenLastTime = isOpenTime;
- }
-
- }
- - (void)locationStopWithError:(FlutterError * _Nullable __autoreleasing *)error{
- // 停止更新
- [ locationManager stopUpdatingLocation];
- }
- //
- - (void)toGenAllClassOrientation:(FLTOrientation *)orientation hrm:(FLTHeartRateMeasurement *)hrm position:(FLTPosition *)position error:(FlutterError *_Nullable *_Nonnull)error{
- }
- // 获取屏幕x向DPI
- - (nullable NSNumber *)getXDPIWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- // NSLog(@"getXDPIWithError %@",[self getDpiOnPhone]);
- return [self getDpiOnPhone];
- }
- // 获取屏幕y向DPI
- - (nullable NSNumber *)getYDPIWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- // NSLog(@"getYDPIWithError");
- return [self getDpiOnPhone];
- }
- // 获取设备当前朝向
- - (nullable FLTOrientation *)getOrientationWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- // NSLog(@"getOrientationWithError%@ - %@ - %@",newOriention.x,newOriention.y,newOriention.z);
-
- return newOriention;
- }
- // 位置服务是否开启
- - (nullable NSNumber *)isLocationServiceOpenWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
-
- NSNumber *isLocationOpen = [[NSNumber alloc]initWithBool:isOpen];
- return isLocationOpen;
- }
- // 强制获取当前位置
- - (void)getCurrentPositionForce:(nonnull NSNumber *)force completion:(nonnull void (^)(FLTPosition * _Nullable, FlutterError * _Nullable))completion {
- // NSLog(@"getCurrentPositionForce");
-
- if (locationManager == nil) {
- locationManager = [[CLLocationManager alloc] init];
- locationManager.delegate = self;
- [locationManager startUpdatingHeading];// 请求方向
- [locationManager requestAlwaysAuthorization];// 请求前台和后台定位权限 ios >= 8.0
- // [locationManager startUpdatingLocation];// 请求前台定位权限
- }
- completion(fltPosition,NULL);
- }
- // 询问蓝牙是否开启
- - (void)askEnableBluetoothWithCompletion:(void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion{
- // NSLog(@"askEnableBluetoothWithCompletion");
- NSNumber *blueToothOpen = [[NSNumber alloc]initWithBool:isBLOpen];
- completion(blueToothOpen,NULL);
- }
- // 开始扫描心率带
- - (void)sportWearScanStartWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- NSLog(@"sportWearScanStartWithError");
- [bleManager StartScanDevice];
- }
- // 停止扫描心率带
- - (void)sportWearScanStopWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- NSLog(@"sportWearScanStopWithError");
- [bleManager stopScan];
- }
- // 获取心率带扫描结果
- - (nullable NSArray<FLTSportWear *> *)getSportWearScanResultWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- NSMutableArray *resultArr = [[NSMutableArray alloc]initWithCapacity:ListPeripheral.count];
-
- for(int i =0;i<ListPeripheral.count;i++){
- HeartBLEDevice *tempDev = ListPeripheral[i];
- FLTSportWear *bandWear = [FLTSportWear new];
- bandWear.name = tempDev.DeviceName;
- bandWear.address = tempDev.UUIDStr;
- bandWear.rssi = [[NSNumber alloc]initWithInt:[tempDev.RSSI intValue]];
-
- [resultArr addObject:bandWear];
- }
-
- NSArray *resultFLT = [resultArr mutableCopy];
- return resultFLT;
- }
- // 连接心率带
- - (void)sportWearConnectWear:(nonnull FLTSportWear *)wear completion:(nonnull void (^)(FlutterError * _Nullable))completion {
- NSLog(@"sportWearConnectWear");
-
- for(int i =0;i<ListPeripheral.count;i++){
- HeartBLEDevice *tempDev = ListPeripheral[i];
- if([tempDev.UUIDStr isEqual:wear.address]){
- NSLog(@"尝试连接%@",BleDevice.UUIDStr);
- [tempDev connect];
- break;
- }
- }
-
- // 填充回调
- completion(NULL);
- }
- // 断开心率带
- - (void)sportWearDisconnectWear:(nonnull FLTSportWear *)wear completion:(nonnull void (^)(FlutterError * _Nullable))completion {
- NSLog(@"sportWearDisconnectWear");
-
- for(int i =0;i<ListPeripheral.count;i++){
- HeartBLEDevice *tempDev = ListPeripheral[i];
- NSLog(@"%@ - %@",tempDev.UUIDStr,BleDevice.UUIDStr);
-
- if([tempDev.UUIDStr isEqual:wear.address]){
- NSLog(@"尝试断开%@",BleDevice.UUIDStr);
- [tempDev disconncet];
- BleDevice = tempDev;
- }
- }
-
- // 填充回调
- completion(NULL);
- }
- // 获取已连接心率带信息
- - (nullable NSArray<FLTSportWear *> *)getSportWearConnectedWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- NSArray *bandArr;
- if(BleDevice){
- FLTSportWear *bandWear = [FLTSportWear new];
- bandWear.name = BleDevice.DeviceName;
- bandWear.address = BleDevice.UUIDStr;
- bandWear.rssi = [[NSNumber alloc]initWithInt:[BleDevice.RSSI intValue]];
- bandArr = [[NSArray alloc] initWithObjects:bandWear, nil];
- }else{
- bandArr = [[NSArray alloc] init];
- }
- return bandArr;
- }
- // 获取心率
- - (nullable NSArray<FLTHeartRateMeasurement *> *)getSportWearHeartRateMeasurementWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
- NSArray *hrArr = [NSArray arrayWithArray:ListFLTHr];
- [ListFLTHr removeAllObjects];
- return hrArr;
- }
- /**
- 屏幕相关
- */
- - (NSNumber *)getDpiOnPhone {
- //需要导入头文件:#import <sys/utsname.h>
- struct utsname systemInfo;
- uname(&systemInfo);
-
- NSString *platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
-
- // iPhone 6 Plus
- if([platform isEqualToString:@"iPhone7,1"]) return [[NSNumber alloc]initWithDouble:401];
- // iPhone 6
- if([platform isEqualToString:@"iPhone7,2"]) return [[NSNumber alloc]initWithDouble:326];
- // iPhone 6s
- if([platform isEqualToString:@"iPhone8,1"]) return [[NSNumber alloc]initWithDouble:326];
- // iPhone 6s Plus
- if([platform isEqualToString:@"iPhone8,2"]) return [[NSNumber alloc]initWithDouble:401];
- // iPhone SE
- if([platform isEqualToString:@"iPhone8,4"]) return [[NSNumber alloc]initWithDouble:401];
- // iPhone 7
- if([platform isEqualToString:@"iPhone9,1"]) return [[NSNumber alloc]initWithDouble:326];
- // iPhone 7 Plus
- if([platform isEqualToString:@"iPhone9,2"]) return [[NSNumber alloc]initWithDouble:401];
- // iPhone 8
- if([platform isEqualToString:@"iPhone10,1"])return [[NSNumber alloc]initWithDouble:326];
- // iPhone 8
- if([platform isEqualToString:@"iPhone10,4"])return [[NSNumber alloc]initWithDouble:326];
- // iPhone 8 Plus
- if([platform isEqualToString:@"iPhone10,2"])return [[NSNumber alloc]initWithDouble:401];
- // iPhone 8 Plus
- if([platform isEqualToString:@"iPhone10,5"])return [[NSNumber alloc]initWithDouble:401];
- // iPhone X
- if([platform isEqualToString:@"iPhone10,3"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone X
- if([platform isEqualToString:@"iPhone10,6"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone XS
- if([platform isEqualToString:@"iPhone11,2"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone XS Max
- if([platform isEqualToString:@"iPhone11,4"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone XS Max
- if([platform isEqualToString:@"iPhone11,6"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone XR
- if([platform isEqualToString:@"iPhone11,8"])return [[NSNumber alloc]initWithDouble:326];
- // iPhone 11
- if([platform isEqualToString:@"iPhone12,1"])return [[NSNumber alloc]initWithDouble:326];
-
- // iPhone 11 Pro Max
- if([platform isEqualToString:@"iPhone12,3"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone 11
- if([platform isEqualToString:@"iPhone12,5"])return [[NSNumber alloc]initWithDouble:326];
- // iPhone SE 2
- if([platform isEqualToString:@"iPhone12,8"])return [[NSNumber alloc]initWithDouble:326];
- // iPhone 12 mini
- if([platform isEqualToString:@"iPhone13,1"])return [[NSNumber alloc]initWithDouble:476];
-
- // iPhone 12
- if([platform isEqualToString:@"iPhone13,2"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 12 Pro
- if([platform isEqualToString:@"iPhone13,3"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 12 Pro Max
- if([platform isEqualToString:@"iPhone13,4"])return [[NSNumber alloc]initWithDouble:458];
-
- //2021年新款iPhone 13 mini、13、13 Pro、13 Pro Max发布
- // iPhone 13 mini
- if([platform isEqualToString:@"iPhone14,4"])return [[NSNumber alloc]initWithDouble:476];
- // iPhone 13
- if([platform isEqualToString:@"iPhone14,5"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 13 Pro
- if([platform isEqualToString:@"iPhone14,2"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 13 Pro Max
- if([platform isEqualToString:@"iPhone14,3"])return [[NSNumber alloc]initWithDouble:458];
-
- //2022年新款iPhone 14、14Plus、14 Pro、14 Pro Max发布
- // iPhone 14
- if([platform isEqualToString:@"iPhone14,7"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 14 Plus
- if([platform isEqualToString:@"iPhone14,8"])return [[NSNumber alloc]initWithDouble:458];
- // iPhone 14 Pro
- if([platform isEqualToString:@"iPhone15,2"])return [[NSNumber alloc]initWithDouble:460];
- // iPhone 14 Pro Max
- if([platform isEqualToString:@"iPhone15,3"])return [[NSNumber alloc]initWithDouble:460];
-
-
- return [[NSNumber alloc]initWithDouble:460];
- }
- /**
- locationManager相关
- */
- // 当获取到用户方向时就会调用
- - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
- {
- // NSLog(@"%s", __func__);
- /*
- magneticHeading 设备与磁北的相对角度
- trueHeading 设置与真北的相对角度, 必须和定位一起使用, iOS需要设置的位置来计算真北
- 真北始终指向地理北极点
- */
- // NSLog(@"%f", newHeading.magneticHeading);
-
- // 1.将获取到的角度转为弧度 = (角度 * π) / 180;
- CGFloat angle = newHeading.magneticHeading * M_PI / 180;
-
- [self->newOriention setZ:[[NSNumber alloc] initWithFloat:angle]];
-
- [self->channelOriention success: @[
- (newOriention.x ?: [NSNull null]),
- (newOriention.y ?: [NSNull null]),
- (newOriention.z ?: [NSNull null]),
- ]
- ];
- // NSLog(@"locationManager %f - newHeading.magneticHeading %f",angle,newHeading.magneticHeading);
- // 2.旋转图片
- /*
- 顺时针 正
- 逆时针 负数
- */
- // self.compasspointer.transform = CGAffineTransformIdentity;
- // self.compasspointer.transform = CGAffineTransformMakeRotation(-angle);
-
- }
- -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
- // CLAuthorizationStatus
- /*
- 用户从未选择过权限
- kCLAuthorizationStatusNotDetermined
- 无法使用定位服务,该状态用户无法改变
- kCLAuthorizationStatusRestricted
- 用户拒绝该应用使用定位服务,或是定位服务总开关处于关闭状态
- kCLAuthorizationStatusDenied
- 已经授权(废弃)
- kCLAuthorizationStatusAuthorized
- 用户允许该程序无论何时都可以使用地理信息
- kCLAuthorizationStatusAuthorizedAlways
- 用户同意程序在可见时使用地理位置
- kCLAuthorizationStatusAuthorizedWhenInUse*/
- // 允许授权
- if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
- NSLog(@"授权成功");
- [locationManager startUpdatingLocation];
- } else if(status == kCLAuthorizationStatusNotDetermined) { // 用户从未选择过权限
- NSLog(@"等待用户授权");
- }
- else{
- NSLog(@"授权失败");
- }
- }
- /**
- * 获取到位置信息之后就会去调用(如果不做控制会频繁调用,浪费电量)
- *
- * @param manager 调用者
- * @param locations 获取到的地理位置信息
- */
- - ( void ) locationManager: ( CLLocationManager * ) manager didUpdateToLocation: ( CLLocation * ) newLocation fromLocation: ( CLLocation * ) oldLocation
- {
- //打印经纬度
- // NSLog(@"latitude:%f - longitude:%f - altitude:%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude, newLocation.altitude);
- [fltPosition setAltitude:[[NSNumber alloc] initWithFloat:newLocation.altitude]];
- [fltPosition setLatitude:[[NSNumber alloc] initWithFloat:newLocation.coordinate.latitude]];
- [fltPosition setLongitude:[[NSNumber alloc] initWithFloat:newLocation.coordinate.longitude]];
-
-
- //发送数据 @[ result ?: [NSNull null] ]
- [channelLocation success:@[
- (fltPosition.latitude ?: [NSNull null]),
- (fltPosition.longitude ?: [NSNull null]),
- (fltPosition.altitude ?: [NSNull null]),
- (fltPosition.bearing ?: [NSNull null]),
- (fltPosition.accuracy ?: [NSNull null]),
- (fltPosition.speed ?: [NSNull null]),
- ]];
- }
- /**
- CoreBluetooth协议
- */
- - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
-
- NSString *message = nil;
- switch (central.state) {
- case 1:
- message = @"该设备不支持蓝牙功能,请检查系统设置";
- break;
- case 2:
- message = @"该设备蓝牙未授权,请检查系统设置";
- break;
- case 3:
- message = @"该设备蓝牙未授权,请检查系统设置";
- break;
- case 4:
- isBLOpen = false;
- message = @"该设备尚未打开蓝牙,请在设置中打开";
- break;
- case 5:
- isBLOpen = true;
- message = @"蓝牙已经成功开启,请稍后再试";
- break;
- default:
- break;
- }
-
- if(message!=nil&&message.length!=0) {
- NSLog(@"message == %@",message);
- }
- }
- /**
- 心率SDK相关 PROTOCAL
- */
- // 心率带是否连接
- - (void)isConnected:(BOOL)isConnected withDevice:(nonnull HeartBLEDevice *)device {
- // NSLog(@"isConnected%@ ",device.DeviceName);
- // 给连接成功的心率带设置代理
- [device setDelegate:self];
- // 赋值BLEDevice引用
- BleDevice = device;
- }
- // 断开心率带
- - (void)disconnected:(nonnull HeartBLEDevice *)device {
- // NSLog(@"disconnected");
- BleDevice = NULL;
- }
- // 设备扫描回调
- - (void)onDeviceFound:(nonnull NSArray *)deviceArray {
-
- // NSLog(@"onDeviceFound:%lu",(unsigned long)deviceArray.count);
- ListPeripheral = [NSArray arrayWithArray:deviceArray];
-
- for(int i =0;i<ListPeripheral.count;i++){
- HeartBLEDevice *tempDev = ListPeripheral[i];
- // NSLog(@"onDeviceFound%@ - %@",tempDev.UUIDStr,tempDev.DeviceName);
- }
- }
- // HeartStr:实时心率值 RRIs:对应的RRI值,Array存储的NSNumber类型
- - (void)SDKFitHeartParamter:(NSString *)HeartStr RRIs:(NSArray *)RRIs {
- // HeartStr = [NSString stringWithFormat:@"%d", (arc4random() % 80) + 85];//开启随机心率
- UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
- // NSLog(@"时间戳:%llu",recordTime);
- // NSLog(@"心率值:%@",HeartStr);
-
- FLTHeartRateMeasurement *realHr = [[FLTHeartRateMeasurement alloc]init];
- realHr.timestampMill = [[NSNumber alloc]initWithLong:recordTime];
- realHr.heartRate = [[NSNumber alloc]initWithInt:[HeartStr intValue]];
- realHr.rrIntervals = RRIs;
- realHr.deviceMac = BleDevice.UUIDStr;
-
-
- // NSLog(@"心率池数据容量:%lu",ListFLTHr.count);
-
- // 缓存达一定数量后清空心率池
- if(ListFLTHr.count > 10){
- [ListFLTHr removeAllObjects];
- }
-
- [ListFLTHr addObject:realHr];
-
- }
- //设备电量回调
- - (void)SDKDianciStr:(NSString *_Nullable)DianStr {
- // NSLog(@"SDKDianciStr:%@",[[NSString alloc] initWithFormat:@"%@已连接 电量 %@%%", BleDevice.DeviceName,DianStr]);
- BleDevice.PowerLevel = DianStr;
- }
- @end
|