// // EightScaleConnectionViewController.m // AILinkBleSDKSourceCode // // Created by iot_user on 2020/9/12. // Copyright © 2020 IOT. All rights reserved. // #import "EightScaleConnectionViewController.h" #import "Masonry.h" #import #import #import #import "ELEightScaleAlgorithmTool.h" @interface EightScaleConnectionViewController () @property (nonatomic, strong) UITextView *textView; @property (nonatomic, copy) NSArray *units; @end @implementation EightScaleConnectionViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [ELEightScaleBleManager shareManager].eightScaleDelegate = self; [ELEightScaleBleManager shareManager].delegate =self; [[ELEightScaleBleManager shareManager] connectPeripheral:self.p]; [self setupUIView]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [[ELEightScaleBleManager shareManager] disconnectPeripheral]; } -(void)addLog:(NSString *)log{ self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text]; } -(void)buttonAction:(UIButton *)sender{ if ([ELEightScaleBleManager shareManager].state != ELBluetoothStateDidValidationPass) { [self addLog:@"Disconnected"]; return; } [self addLog:sender.titleLabel.text]; NSInteger tag = sender.tag; if (tag == 1) { //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法 [[ELEightScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; }else if (tag == 2){ [[ELEightScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)]; }else if (tag == 3){ [[ELEightScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)]; }else if (tag == 4){ [[ELEightScaleBleManager shareManager] setBluetoothName:@"AILink"]; }else if (tag == 5){ if (self.units.count==0) { [self addLog:@"No units obtained"]; return; } // [[ELEightScaleBleManager shareManager] changeBodyFatScaleUnit:(ELDeviceWeightUnit_KG)]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)]; for (int i=0; i *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{ //这里只要体重数据 self.units = weightArray; } -(void)eightScaleBleReceiveAdcData:(EightScaleAdcStruct)adcStruct{ [self addLog:[NSString stringWithFormat:@"Impedance type = %lu adc = %d",adcStruct.adcType,adcStruct.adc]]; } -(void)eightScaleBleReceiveHeartRateTestStep:(EightScaleHeartRateTestStep)testStep heartRate:(int)heartRate{ [self addLog:[NSString stringWithFormat:@"HeartRate = %d",heartRate]]; } /** Callback to set unit result(回调设置单位结果) @param result 结果 */ - (void)eightScaleBleReceiveSwitchWeightUnitResult:(EightScaleSwitchUnitResult)result{ switch (result) { case EightScaleSwitchUnitResultSuccess: { [self addLog:@"Change Unit Success"]; } break; case EightScaleSwitchUnitResultFailure: { [self addLog:@"Change Unit Failure"]; } break; case EightScaleSwitchUnitResultOperation: { [self addLog:@"Operationing"]; } break; default: break; } } /** Return weight and body fat model(返回重量及体脂model) */ -(void)eightScaleBleReceiveWeightData:(EightScaleWeightStruct)weightStruct{ switch (weightStruct.weightType) { case EightScaleWeightTypeAuto: { [self addLog:[NSString stringWithFormat:@"Unstable data weight = %d unit = %@ point = %d adc = %ld",weightStruct.weight,AiLinkBleWeightUnitDic[@(weightStruct.unit)],weightStruct.point,weightStruct.weightType]]; } break; case EightScaleWeightTypeStable: { [self addLog:[NSString stringWithFormat:@"Unstable data weight = %d unit = %@ point = %d adc = %ld",weightStruct.weight,AiLinkBleWeightUnitDic[@(weightStruct.unit)],weightStruct.point,weightStruct.weightType]]; } break; default: break; } } -(void)eightScaleBleReceiveTestComplete{ [self addLog:@"Measurn Complete"]; } #pragma mark ============ get all body fat data ============== -(void)eightScaleBleReceiveTestData:(ELEightScaleBleDataModel *)dataModel{ [self addLog:[NSString stringWithFormat:@"weight = %@%@",dataModel.weight,AiLinkBleWeightUnitDic[@(dataModel.weightUnit)]]]; //Please input the correct height, age, gender of your app user ELEightScaleRecordModel *bodyInfo = [ELEightScaleAlgorithmTool getRecordModelWithBleDataModel:dataModel withUserSex:1 height:175 age:25]; [self addLog:[NSString stringWithFormat:@"---bodyInfo:%@",bodyInfo]]; } -(void)eightScaleBleReceiveErrorCode:(int)errorCode{ [self addLog:[NSString stringWithFormat:@"Error Code is %d",errorCode]]; } -(void)eightScaleBleReceiveTempData:(EightScaleTempStruct)tempStruct{ [self addLog:[NSString stringWithFormat:@"temperature is %d ",tempStruct.temp]]; } -(void)eightScaleBleReceiveState:(ELBluetoothState)state{ switch (state) { case ELBluetoothStateUnavailable: { self.title = @"Please open the bluetooth"; } break; case ELBluetoothStateAvailable: { self.title = @"Bluetooth is open"; } break; case ELBluetoothStateScaning: { self.title = @"Scaning"; } break; case ELBluetoothStateConnectFail: { self.title = @"Connect fail"; } break; case ELBluetoothStateDidDisconnect: { self.title = @"Disconnected"; } break; case ELBluetoothStateDidValidationPass: { self.title = @"Connected"; //获取设备支持的单位 [[ELEightScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)]; //将你自己设置的单位发给秤 ELDeviceWeightUnit unit = ELDeviceWeightUnit_KG; [[ELEightScaleBleManager shareManager] eightScaleSwitchWeightUnit:unit]; if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) { //获取蓝牙连接状态 [[ELEightScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)]; } } break; case ELBluetoothStateFailedValidation: { self.title = @"Illegal equipment"; } break; case ELBluetoothStateWillConnect: self.title = @"Connecting"; break; default: break; } } -(void)dealloc{ } @end