123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- //
- // BodyFatScaleConnectViewController.m
- // AILinkBleSDKSourceCode
- //
- // Created by iot_user on 2020/4/8.
- // Copyright © 2020 IOT. All rights reserved.
- //
-
- #import "BodyFatScaleConnectViewController.h"
- #import "Masonry.h"
- #import <AILinkBleSDK/ELBodyFatScaleBleManager.h>
- #import <AILinkBleSDK/ELBodyFatScaleBleUserModel.h>
- #import <AILinkBleSDK/ELBodyFatScaleBleWeightModel.h>
- //#import "WiFiSetupViewController.h"
-
- @interface BodyFatScaleConnectViewController ()<ELBluetoothManagerDelegate,ELBodyFatScaleBleDelegate,ElBleWifiDelegate>
- @property (nonatomic, strong) UITextView *textView;
-
- @property (nonatomic, copy) NSArray<NSNumber *> *units;
-
-
- @end
-
- @implementation BodyFatScaleConnectViewController
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
-
- [ELBodyFatScaleBleManager shareManager].bodyFatScaleDelegate = self;
- [ELBodyFatScaleBleManager shareManager].delegate =self;
- [[ELBodyFatScaleBleManager shareManager] connectPeripheral:self.p];
- [ELBodyFatScaleBleManager shareManager].bleWifiDelegate = self;
-
- [self setupUIView];
- }
- -(void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [[ELBodyFatScaleBleManager shareManager] disconnectPeripheral];
- }
- -(void)addLog:(NSString *)log{
- self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
- }
- -(void)buttonAction:(UIButton *)sender{
- if ([ELBodyFatScaleBleManager shareManager].state != ELBluetoothStateDidValidationPass) {
- [self addLog:@"Disconnected"];
- return;
- }
- [self addLog:sender.titleLabel.text];
- NSInteger tag = sender.tag;
- if (tag == 1) {
- //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
- }else if (tag == 2){
-
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
- }else if (tag == 3){
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
- }else if (tag == 4){
- [[ELBodyFatScaleBleManager shareManager] setBluetoothName:@"AILink"];
- }else if (tag == 5){
- if (self.units.count==0) {
- [self addLog:@"No units obtained"];
- return;
- }
-
- // [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:(ELDeviceWeightUnit_KG)];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
- for (int i=0; i<self.units.count; i++) {
-
- UIAlertAction *action = [UIAlertAction actionWithTitle:AiLinkBleWeightUnitDic[self.units[i]] style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
- [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:self.units[i].integerValue];
- }];
- [alert addAction:action];
- }
- [self presentViewController:alert animated:YES completion:nil];
- }else if (tag == 6){
-
- }else if (tag == 7){
-
- }else if (tag == 8){
-
- }else if (tag == 9){
-
- }
-
- }
- -(void)setupUIView{
- UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
- button1.tag = 1;
- button1.titleLabel.adjustsFontSizeToFitWidth = YES;
- button1.titleLabel.numberOfLines = 2;
- button1.backgroundColor = [UIColor blackColor];
- [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:button1];
- [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(80);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(40);
- }];
-
- UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
- button2.tag = 2;
- button2.titleLabel.adjustsFontSizeToFitWidth = YES;
- button2.titleLabel.numberOfLines = 2;
- button2.backgroundColor = [UIColor blackColor];
- [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:button2];
- [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(button1.mas_right).mas_offset(10);
- make.top.mas_equalTo(80);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(40);
- }];
-
- UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
- button3.tag = 3;
- button3.titleLabel.adjustsFontSizeToFitWidth = YES;
- button3.titleLabel.numberOfLines = 2;
- button3.backgroundColor = [UIColor blackColor];
- [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:button3];
- [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(button2.mas_right).mas_offset(10);
- make.top.mas_equalTo(80);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(40);
- }];
- //
- UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
- button4.tag = 4;
- button4.titleLabel.adjustsFontSizeToFitWidth = YES;
- button4.titleLabel.numberOfLines = 2;
- button4.backgroundColor = [UIColor blackColor];
- [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:button4];
- [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.equalTo(button1.mas_bottom).mas_offset(10);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(40);
- }];
- //
- UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [button5 setTitle:@"Change unit" forState:(UIControlStateNormal)];
- button5.tag = 5;
- button5.titleLabel.adjustsFontSizeToFitWidth = YES;
- button5.titleLabel.numberOfLines = 2;
- button5.backgroundColor = [UIColor blackColor];
- [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:button5];
- [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(button4.mas_right).mas_offset(10);
- make.top.equalTo(button1.mas_bottom).mas_offset(10);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(40);
- }];
- //
- //
- // UIButton *button6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- // [button6 setTitle:@"" forState:(UIControlStateNormal)];
- // button6.tag = 6;
- // button6.titleLabel.adjustsFontSizeToFitWidth = YES;
- // button6.titleLabel.numberOfLines = 2;
- // button6.backgroundColor = [UIColor blackColor];
- // [button6 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.view addSubview:button6];
- // [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.equalTo(button5.mas_right).mas_offset(10);
- // make.top.equalTo(button1.mas_bottom).mas_offset(10);
- // make.width.mas_equalTo(100);
- // make.height.mas_equalTo(40);
- // }];
- // //
- // UIButton *button7 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- // [button7 setTitle:@"" forState:(UIControlStateNormal)];
- // button7.tag = 7;
- // button7.titleLabel.adjustsFontSizeToFitWidth = YES;
- // button7.titleLabel.numberOfLines = 2;
- // button7.backgroundColor = [UIColor blackColor];
- // [button7 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.view addSubview:button7];
- // [button7 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(10);
- // make.top.equalTo(button4.mas_bottom).mas_offset(10);
- // make.width.mas_equalTo(100);
- // make.height.mas_equalTo(40);
- // }];
- //
- // UIButton *button8 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- // [button8 setTitle:@"" forState:(UIControlStateNormal)];
- // button8.tag = 8;
- // button8.titleLabel.adjustsFontSizeToFitWidth = YES;
- // button8.titleLabel.numberOfLines = 2;
- // button8.backgroundColor = [UIColor blackColor];
- // [button8 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.view addSubview:button8];
- // [button8 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.equalTo(button7.mas_right).mas_offset(10);
- // make.top.equalTo(button4.mas_bottom).mas_offset(10);
- // make.width.mas_equalTo(100);
- // make.height.mas_equalTo(40);
- // }];
- //
- // UIButton *button9 = [UIButton buttonWithType:(UIButtonTypeCustom)];
- // [button9 setTitle:@"" forState:(UIControlStateNormal)];
- // button9.tag = 9;
- // button9.titleLabel.adjustsFontSizeToFitWidth = YES;
- // button9.titleLabel.numberOfLines = 2;
- // button9.backgroundColor = [UIColor blackColor];
- // [button9 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.view addSubview:button9];
- // [button9 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.equalTo(button8.mas_right).mas_offset(10);
- // make.top.equalTo(button4.mas_bottom).mas_offset(10);
- // make.width.mas_equalTo(100);
- // make.height.mas_equalTo(40);
- // }];
- //
- self.textView = [[UITextView alloc] init];
- self.textView.backgroundColor = [UIColor blackColor];
- self.textView.text = @"Log";
- self.textView.textColor = [UIColor redColor];
- [self.view addSubview:self.textView];
- [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.right.bottom.mas_equalTo(-10);
- make.height.mas_equalTo(200);
- }];
- }
-
- -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
- if (type == ELInetSetCmdTypeSetName) {
- if (result == ELSetBluetoothResponseTypeSuccess) {
- [self addLog:@"Set name Success "];
- }else if (result == ELSetBluetoothResponseTypeFailure){
- [self addLog:@"Set name failure "];
- }else if (result == ELSetBluetoothResponseTypeNoSupport){
- [self addLog:@"Set name unsupport "];
- }
-
- }
-
- }
- -(void)bluetoothManagerReceiceName:(NSString *)name{
- [self addLog:name];
- }
- -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
- [self addLog:[NSString stringWithFormat:@"CID = %d,VID = %d,PID = %d",did.deviceType,did.vendorID,did.productID]];
- }
-
- -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
- [self addLog:bmVersion];
- }
-
- -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
- //这里只要体重数据
- self.units = weightArray;
- }
-
- -(void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct{
-
- BleWiFiConnectState wifiState = stateStrct.wifiState;
-
-
- if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {
- //蓝牙WiFi体脂秤
- //请求会话码
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
- //MARK:1.WiFi配置提示用户配网
- //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接
- if (wifiState == BleWiFiConnectStateNoWiFi) {
- //1.如果没有配网,则提示用户去配网
- //MARK:2.WiFi配置先获取wifi列表
- //
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
- //
- // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
- // UIAlertAction *action = [UIAlertAction actionWithTitle:@"去配网" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
- // if ([ELBodyFatScaleBleManager shareManager].state == ELBluetoothStateDidValidationPass) {
- // WiFiSetupViewController *vc = [[WiFiSetupViewController alloc] init];
- // [self.navigationController pushViewController:vc animated:YES];
- // }else{
- // [self addLog:@"Disconnected"];
- // }
- //
- // }];
- // UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- // [alert addAction:action];
- // [alert addAction:action2];
- // [self presentViewController:alert animated:YES completion:nil];
- }
- }
- ///MARK:9.wifi配置结果
- //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件
- if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {
- //成功
- //MARK:10.获取wifi设备的SN号,即设备id
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeBleWifiGetSNNumber)];
- }else{
- //失败
- }
-
- }
-
- /**
- Callback to set unit result(回调设置单位结果)
-
- @param result 结果
- */
- - (void)bodyFatScaleManagerCallBackSetUnitResult:(ELSetBluetoothResponseType)result{
- switch (result) {
- case ELSetBluetoothResponseTypeSuccess:
- {
- [self addLog:@"Change Unit Success"];
- }
- break;
- case ELSetBluetoothResponseTypeFailure:
- {
- [self addLog:@"Change Unit Failure"];
- }
- break;
- case ELSetBluetoothResponseTypeNoSupport:
- {
- [self addLog:@"Unsupport Change Unit"];
- }
- break;
- default:
- break;
- }
- }
- //MARK:回调Wifi列表
- -(void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model{
- // MARK:3.WiFi配置得到Wifi列表
- //用一个tableview显示喽
- [self addLog:[NSString stringWithFormat:@"wifi类型---%lu 名称---%@",(unsigned long)model.wifiState,model.wifiName]];
-
- }
- -(void)bleWifiReceiveScanedWifiCount:(int)count {
- //MARK:扫描Wifi结束
- //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置
- //MARK:5.输入wifi密码
- //写个“textfield”输入密码
- //MARK:6.先发送配置wifi的mac地址的指令
- // [[ELBodyFatScaleBleManager shareManager] bleWifiSetConnectWifiMac:[NSData data]];
- }
- -(void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
-
- [self addLog:[NSString stringWithFormat:@"bleWifiReceiceResponseType==%lu----%lu",type,result]];
- if (result == ELSetBluetoothResponseTypeSuccess) {
- //设置WiFi结果
- if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {
- //MARK:7.再发送配置wifi的密码的指令
- [[ELBodyFatScaleBleManager shareManager] bleWifiSetWifiPwd:@"WiFi密码"];
- }else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){
- //MARK:8.然后发起连接Wifi
- [[ELBodyFatScaleBleManager shareManager] bleWifiSetupWifiConnect:YES];
- }else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){
- //获取连接状态
- }
- }
- else{
- //TODO:Wifi配置过程中失败的情况自行处理
- }
-
- }
- /**
- MCU requests user information( MCU 请求用户信息)
-
- @param status 请求状态
- */
- - (void)bodyFatScaleManagerMCURequestAppUserInfoType:(BodyFatScaleMCURequestUserInfoStatus)status{
- if (status == BodyFatScaleMCURequestUserInfoStatus_Get) {
- //下发当前用户给秤
- [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
- }else if (status == BodyFatScaleMCURequestUserInfoStatus_Success){
- [self addLog:@"MCU requests user information success"];
- }else if (BodyFatScaleMCURequestUserInfoStatus_Fail){
- [self addLog:@"MCU requests user information failure"];
- }
-
- }
-
-
- /**
- Return weight and body fat model(返回重量及体脂model)
- */
- -(void)bodyFatScaleManagerCallBackWeight:(ELBodyFatScaleBleWeightModel *)weightModel state:(BodyFatScaleMeasureStatus)status{
- switch (status) {
- case BodyFatScaleMeasureStatus_Unstable:
- {
- [self addLog:[NSString stringWithFormat:@"Unstable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
- }
- break;
- case BodyFatScaleMeasureStatus_Stable:
- {
- [self addLog:[NSString stringWithFormat:@"Stable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
- }
- break;
- case BodyFatScaleMeasureStatus_Failed:
- {
- [self addLog:@"Test failure"];
- }
- break;
- case BodyFatScaleMeasureStatus_Complete:
- {
- [self addLog:[NSString stringWithFormat:@"Tested weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
-
- //更新用户信息给秤
- [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
- //下发用户列表
- [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];
- }
- break;
- default:
- break;
- }
- }
-
-
- /**
- Return temperature (unit: ° C)(返回温度(单位:°C))
-
- @param temp 温度(单位:°C)
- */
- -(void)bodyFatScaleManagerCallBackTemp:(NSString *)temp{
- [self addLog:[NSString stringWithFormat:@"temperature is %@",temp]];
- }
-
- /**
- Back to impedance measurement(返回阻抗测量)
-
- @param status 阻抗测量状态
- @param adc 阻抗
- */
- -(void)bodyFatScaleManagerCallBackAdcMeasureStatus:(BodyFatScaleAdcMeasureStatus)status adcValue:(NSInteger)adc{
- switch (status) {
- case BodyFatScaleAdcMeasureStatus_Testing:
- {
- [self addLog:@"adc testing"];
- }
- break;
- case BodyFatScaleAdcMeasureStatus_Success:
- {
- [self addLog:[NSString stringWithFormat:@"adc is %ld",adc]];
- }
- break;
- case BodyFatScaleAdcMeasureStatus_Fail:
- {
- [self addLog:@"adc test failure"];
- }
- break;
- case BodyFatScaleAdcMeasureStatus_SuccessCustom:
- {
- [self addLog:[NSString stringWithFormat:@"adc is %ld and user app algum",adc]];
- }
- break;
- default:
- break;
- }
- }
-
- /**
- Callback heart rate measurement(回调心率测量)
-
- @param status 心率测量状态
- @param heartRate 心率
- */
- -(void)bodyFatScaleManagerCallBackHeartRateMeasureStatus:(BodyFatScaleHeartRateMeasureStatus)status heartRateValue:(NSInteger)heartRate{
- switch (status) {
- case BodyFatScaleHeartRateMeasureStatus_Testing:
- {
- [self addLog:@"Heart Rate Testing"];
- }
- break;
- case BodyFatScaleHeartRateMeasureStatus_Success:
- {
- [self addLog:[NSString stringWithFormat:@"Heart Rate is %ld",heartRate]];
- }
- break;
- case BodyFatScaleHeartRateMeasureStatus_Fail:
- {
- [self addLog:@"Heart Rate Test failure"];
- }
- break;
- default:
- break;
- }
- }
-
- /**
- Return error code(返回错误码)
-
- @param code 错误码
- 1:超重
- */
- -(void)bodyFatScaleManagerCallBackErrorCode:(NSInteger)code{
- [self addLog:[NSString stringWithFormat:@"error code = %ld",code]];
- }
- //MARK:回调A6指令数据
-
- /**
- Send success or failure callback for offline user list(发送离线用户列表的成功或失败回调)
-
- @param status 状态
- */
- -(void)bodyFatScaleManagerCallBackUpdateRecordStatus:(BodyFatScaleUpdateRecordStatus)status{
- switch (status) {
- case BodyFatScaleUpdateRecordStatus_AllSuccess:
- {
- [self addLog:@"Update All Users Success"];
- }
- break;
- case BodyFatScaleUpdateRecordStatus_OneSuccess:
- {
- [self addLog:@"Update A User Success"];
- }
- break;
- case BodyFatScaleUpdateRecordStatus_OneFail:
- {
- [self addLog:@"Update A User Failure"];
- }
- break;
- case BodyFatScaleUpdateRecordStatus_AllFail:
- {
- [self addLog:@"Update All Users Failure"];
- }
- break;
- default:
- break;
- }
- }
-
- /**
- Request callback for offline history(请求离线历史记录的回调)
-
- @param status 状态
- */
- -(void)bodyFatScaleManagerCallBackSendHistoryDataStatus:(BodyFatScaleSendHistoryDataStatus)status{
- if (status == BodyFatScaleSendHistoryDataStatus_No) {
- [self addLog:@"No offline datas"];
- }else if (status == BodyFatScaleSendHistoryDataStatus_Begin){
- [self addLog:@"Begin receive offline datas"];
- }else if (status == BodyFatScaleSendHistoryDataStatus_End){
- [self addLog:@"End receive offline datas"];
- }
-
- }
-
- /**
- APP algorithm-offline history data(APP 算法-离线历史记录数据)
-
- @param user 用户信息
- */
- -(void)bodyFatScaleManagerCallBackBleUserHistoryDataCustomADCModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
- //这里的身体指标等数据由app自定义算法计算得到,请区分bodyModel.algNum来调用算法
- [self addLog:[NSString stringWithFormat:@"App algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]];
- }
-
- /**
- MCU algorithm-offline history data(MCU 算法-离线历史记录数据)
-
- @param user 用户信息
- @param bodyModel 体脂数据
- */
- -(void)bodyFatScaleManagerCallBackBleUserHistoryDataModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
- //这里的身体指标数据由秤计算得到
- [self addLog:[NSString stringWithFormat:@"MCU algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]];
- }
-
- -(void)bleWifiReceiveWifiSNCode:(int)code{
- //MARK:11.根据wifi设备的设备id从服务器获取离线数据(找自己后台要接口)
- }
-
- -(void)bodyFatScaleManagerUpdateState:(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";
- //获取设备支持的单位
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
- //将你自己设置的单位发给秤
- ELDeviceWeightUnit unit = ELDeviceWeightUnit_KG;
- [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:unit];
- //请求历史记录
- [[ELBodyFatScaleBleManager shareManager] sendCmd_RequestHistory];
-
- //下发用户列表
- [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];
-
- if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {
- //获取蓝牙连接状态
- [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];
- }
- }
- break;
- case ELBluetoothStateFailedValidation:
- {
- self.title = @"Illegal equipment";
- }
- break;
- case ELBluetoothStateWillConnect:
- self.title = @"Connecting";
- break;
- default:
- break;
- }
- }
- -(NSArray<ELBodyFatScaleBleUserModel *> *)get8Users{
- NSMutableArray *users = [[NSMutableArray alloc] init];
- for (int i=0; i<8; i++) {
- ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
- user.createTime = [[NSDate date] timeIntervalSince1970];
- user.usrID = i;
- user.role = i%4;
- user.sex = i%2;
- user.age = 26+i;
- user.height = 170+i;
- user.weight = 600+i;
- user.adc = 560+i;
- [users addObject:user];
- }
-
- return users.copy;
- }
-
- -(ELBodyFatScaleBleUserModel *)getOneUser{
- ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
- user.createTime = [[NSDate date] timeIntervalSince1970];
- user.usrID = 0;
- user.role = BodyFatScaleRole_Ordinary;
- user.sex = ELBluetoothUserSex_Woman;
- user.age = 26;
- user.height = 170;
- user.weight = 600;
- user.adc = 560;
- return user;
- }
- -(void)dealloc{
-
-
- }
-
- @end
|