iOS AILinkBleSDK - 蓝牙SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BodyFatScaleConnectViewController.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. //
  2. // BodyFatScaleConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/8.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "BodyFatScaleConnectViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELBodyFatScaleBleManager.h>
  11. #import <AILinkBleSDK/ELBodyFatScaleBleUserModel.h>
  12. #import <AILinkBleSDK/ELBodyFatScaleBleWeightModel.h>
  13. //#import "WiFiSetupViewController.h"
  14. @interface BodyFatScaleConnectViewController ()<ELBluetoothManagerDelegate,ELBodyFatScaleBleDelegate,ElBleWifiDelegate>
  15. @property (nonatomic, strong) UITextView *textView;
  16. @property (nonatomic, copy) NSArray<NSNumber *> *units;
  17. @end
  18. @implementation BodyFatScaleConnectViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = [UIColor whiteColor];
  22. [ELBodyFatScaleBleManager shareManager].bodyFatScaleDelegate = self;
  23. [ELBodyFatScaleBleManager shareManager].delegate =self;
  24. [[ELBodyFatScaleBleManager shareManager] connectPeripheral:self.p];
  25. [ELBodyFatScaleBleManager shareManager].bleWifiDelegate = self;
  26. [self setupUIView];
  27. }
  28. -(void)viewWillDisappear:(BOOL)animated{
  29. [super viewWillDisappear:animated];
  30. [[ELBodyFatScaleBleManager shareManager] disconnectPeripheral];
  31. }
  32. -(void)addLog:(NSString *)log{
  33. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  34. }
  35. -(void)buttonAction:(UIButton *)sender{
  36. if ([ELBodyFatScaleBleManager shareManager].state != ELBluetoothStateDidValidationPass) {
  37. [self addLog:@"Disconnected"];
  38. return;
  39. }
  40. [self addLog:sender.titleLabel.text];
  41. NSInteger tag = sender.tag;
  42. if (tag == 1) {
  43. //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法
  44. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  45. }else if (tag == 2){
  46. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  47. }else if (tag == 3){
  48. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  49. }else if (tag == 4){
  50. [[ELBodyFatScaleBleManager shareManager] setBluetoothName:@"AILink"];
  51. }else if (tag == 5){
  52. if (self.units.count==0) {
  53. [self addLog:@"No units obtained"];
  54. return;
  55. }
  56. // [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:(ELDeviceWeightUnit_KG)];
  57. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
  58. for (int i=0; i<self.units.count; i++) {
  59. UIAlertAction *action = [UIAlertAction actionWithTitle:AiLinkBleWeightUnitDic[self.units[i]] style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
  60. [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:self.units[i].integerValue];
  61. }];
  62. [alert addAction:action];
  63. }
  64. [self presentViewController:alert animated:YES completion:nil];
  65. }else if (tag == 6){
  66. }else if (tag == 7){
  67. }else if (tag == 8){
  68. }else if (tag == 9){
  69. }
  70. }
  71. -(void)setupUIView{
  72. UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  73. [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  74. button1.tag = 1;
  75. button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  76. button1.titleLabel.numberOfLines = 2;
  77. button1.backgroundColor = [UIColor blackColor];
  78. [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  79. [self.view addSubview:button1];
  80. [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.mas_equalTo(10);
  82. make.top.mas_equalTo(80);
  83. make.width.mas_equalTo(100);
  84. make.height.mas_equalTo(40);
  85. }];
  86. UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  87. [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  88. button2.tag = 2;
  89. button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  90. button2.titleLabel.numberOfLines = 2;
  91. button2.backgroundColor = [UIColor blackColor];
  92. [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  93. [self.view addSubview:button2];
  94. [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.equalTo(button1.mas_right).mas_offset(10);
  96. make.top.mas_equalTo(80);
  97. make.width.mas_equalTo(100);
  98. make.height.mas_equalTo(40);
  99. }];
  100. UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  101. [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  102. button3.tag = 3;
  103. button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  104. button3.titleLabel.numberOfLines = 2;
  105. button3.backgroundColor = [UIColor blackColor];
  106. [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  107. [self.view addSubview:button3];
  108. [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.left.equalTo(button2.mas_right).mas_offset(10);
  110. make.top.mas_equalTo(80);
  111. make.width.mas_equalTo(100);
  112. make.height.mas_equalTo(40);
  113. }];
  114. //
  115. UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  116. [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  117. button4.tag = 4;
  118. button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  119. button4.titleLabel.numberOfLines = 2;
  120. button4.backgroundColor = [UIColor blackColor];
  121. [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  122. [self.view addSubview:button4];
  123. [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.mas_equalTo(10);
  125. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  126. make.width.mas_equalTo(100);
  127. make.height.mas_equalTo(40);
  128. }];
  129. //
  130. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  131. [button5 setTitle:@"Change unit" forState:(UIControlStateNormal)];
  132. button5.tag = 5;
  133. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  134. button5.titleLabel.numberOfLines = 2;
  135. button5.backgroundColor = [UIColor blackColor];
  136. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  137. [self.view addSubview:button5];
  138. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.left.equalTo(button4.mas_right).mas_offset(10);
  140. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  141. make.width.mas_equalTo(100);
  142. make.height.mas_equalTo(40);
  143. }];
  144. //
  145. //
  146. // UIButton *button6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  147. // [button6 setTitle:@"" forState:(UIControlStateNormal)];
  148. // button6.tag = 6;
  149. // button6.titleLabel.adjustsFontSizeToFitWidth = YES;
  150. // button6.titleLabel.numberOfLines = 2;
  151. // button6.backgroundColor = [UIColor blackColor];
  152. // [button6 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  153. // [self.view addSubview:button6];
  154. // [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
  155. // make.left.equalTo(button5.mas_right).mas_offset(10);
  156. // make.top.equalTo(button1.mas_bottom).mas_offset(10);
  157. // make.width.mas_equalTo(100);
  158. // make.height.mas_equalTo(40);
  159. // }];
  160. // //
  161. // UIButton *button7 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  162. // [button7 setTitle:@"" forState:(UIControlStateNormal)];
  163. // button7.tag = 7;
  164. // button7.titleLabel.adjustsFontSizeToFitWidth = YES;
  165. // button7.titleLabel.numberOfLines = 2;
  166. // button7.backgroundColor = [UIColor blackColor];
  167. // [button7 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  168. // [self.view addSubview:button7];
  169. // [button7 mas_makeConstraints:^(MASConstraintMaker *make) {
  170. // make.left.mas_equalTo(10);
  171. // make.top.equalTo(button4.mas_bottom).mas_offset(10);
  172. // make.width.mas_equalTo(100);
  173. // make.height.mas_equalTo(40);
  174. // }];
  175. //
  176. // UIButton *button8 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  177. // [button8 setTitle:@"" forState:(UIControlStateNormal)];
  178. // button8.tag = 8;
  179. // button8.titleLabel.adjustsFontSizeToFitWidth = YES;
  180. // button8.titleLabel.numberOfLines = 2;
  181. // button8.backgroundColor = [UIColor blackColor];
  182. // [button8 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  183. // [self.view addSubview:button8];
  184. // [button8 mas_makeConstraints:^(MASConstraintMaker *make) {
  185. // make.left.equalTo(button7.mas_right).mas_offset(10);
  186. // make.top.equalTo(button4.mas_bottom).mas_offset(10);
  187. // make.width.mas_equalTo(100);
  188. // make.height.mas_equalTo(40);
  189. // }];
  190. //
  191. // UIButton *button9 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  192. // [button9 setTitle:@"" forState:(UIControlStateNormal)];
  193. // button9.tag = 9;
  194. // button9.titleLabel.adjustsFontSizeToFitWidth = YES;
  195. // button9.titleLabel.numberOfLines = 2;
  196. // button9.backgroundColor = [UIColor blackColor];
  197. // [button9 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  198. // [self.view addSubview:button9];
  199. // [button9 mas_makeConstraints:^(MASConstraintMaker *make) {
  200. // make.left.equalTo(button8.mas_right).mas_offset(10);
  201. // make.top.equalTo(button4.mas_bottom).mas_offset(10);
  202. // make.width.mas_equalTo(100);
  203. // make.height.mas_equalTo(40);
  204. // }];
  205. //
  206. self.textView = [[UITextView alloc] init];
  207. self.textView.backgroundColor = [UIColor blackColor];
  208. self.textView.text = @"Log";
  209. self.textView.textColor = [UIColor redColor];
  210. [self.view addSubview:self.textView];
  211. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  212. make.left.mas_equalTo(10);
  213. make.right.bottom.mas_equalTo(-10);
  214. make.height.mas_equalTo(200);
  215. }];
  216. }
  217. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  218. if (type == ELInetSetCmdTypeSetName) {
  219. if (result == ELSetBluetoothResponseTypeSuccess) {
  220. [self addLog:@"Set name Success "];
  221. }else if (result == ELSetBluetoothResponseTypeFailure){
  222. [self addLog:@"Set name failure "];
  223. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  224. [self addLog:@"Set name unsupport "];
  225. }
  226. }
  227. }
  228. -(void)bluetoothManagerReceiceName:(NSString *)name{
  229. [self addLog:name];
  230. }
  231. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  232. [self addLog:[NSString stringWithFormat:@"CID = %d,VID = %d,PID = %d",did.deviceType,did.vendorID,did.productID]];
  233. }
  234. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  235. [self addLog:bmVersion];
  236. }
  237. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  238. //这里只要体重数据
  239. self.units = weightArray;
  240. }
  241. -(void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct{
  242. BleWiFiConnectState wifiState = stateStrct.wifiState;
  243. if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {
  244. //蓝牙WiFi体脂秤
  245. //请求会话码
  246. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  247. //MARK:1.WiFi配置提示用户配网
  248. //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接
  249. if (wifiState == BleWiFiConnectStateNoWiFi) {
  250. //1.如果没有配网,则提示用户去配网
  251. //MARK:2.WiFi配置先获取wifi列表
  252. //
  253. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  254. //
  255. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
  256. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"去配网" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
  257. // if ([ELBodyFatScaleBleManager shareManager].state == ELBluetoothStateDidValidationPass) {
  258. // WiFiSetupViewController *vc = [[WiFiSetupViewController alloc] init];
  259. // [self.navigationController pushViewController:vc animated:YES];
  260. // }else{
  261. // [self addLog:@"Disconnected"];
  262. // }
  263. //
  264. // }];
  265. // UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
  266. //
  267. // }];
  268. // [alert addAction:action];
  269. // [alert addAction:action2];
  270. // [self presentViewController:alert animated:YES completion:nil];
  271. }
  272. }
  273. ///MARK:9.wifi配置结果
  274. //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件
  275. if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {
  276. //成功
  277. //MARK:10.获取wifi设备的SN号,即设备id
  278. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeBleWifiGetSNNumber)];
  279. }else{
  280. //失败
  281. }
  282. }
  283. /**
  284. Callback to set unit result(回调设置单位结果)
  285. @param result 结果
  286. */
  287. - (void)bodyFatScaleManagerCallBackSetUnitResult:(ELSetBluetoothResponseType)result{
  288. switch (result) {
  289. case ELSetBluetoothResponseTypeSuccess:
  290. {
  291. [self addLog:@"Change Unit Success"];
  292. }
  293. break;
  294. case ELSetBluetoothResponseTypeFailure:
  295. {
  296. [self addLog:@"Change Unit Failure"];
  297. }
  298. break;
  299. case ELSetBluetoothResponseTypeNoSupport:
  300. {
  301. [self addLog:@"Unsupport Change Unit"];
  302. }
  303. break;
  304. default:
  305. break;
  306. }
  307. }
  308. //MARK:回调Wifi列表
  309. -(void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model{
  310. // MARK:3.WiFi配置得到Wifi列表
  311. //用一个tableview显示喽
  312. [self addLog:[NSString stringWithFormat:@"wifi类型---%lu 名称---%@",(unsigned long)model.wifiState,model.wifiName]];
  313. }
  314. -(void)bleWifiReceiveScanedWifiCount:(int)count {
  315. //MARK:扫描Wifi结束
  316. //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置
  317. //MARK:5.输入wifi密码
  318. //写个“textfield”输入密码
  319. //MARK:6.先发送配置wifi的mac地址的指令
  320. // [[ELBodyFatScaleBleManager shareManager] bleWifiSetConnectWifiMac:[NSData data]];
  321. }
  322. -(void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  323. [self addLog:[NSString stringWithFormat:@"bleWifiReceiceResponseType==%lu----%lu",type,result]];
  324. if (result == ELSetBluetoothResponseTypeSuccess) {
  325. //设置WiFi结果
  326. if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {
  327. //MARK:7.再发送配置wifi的密码的指令
  328. [[ELBodyFatScaleBleManager shareManager] bleWifiSetWifiPwd:@"WiFi密码"];
  329. }else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){
  330. //MARK:8.然后发起连接Wifi
  331. [[ELBodyFatScaleBleManager shareManager] bleWifiSetupWifiConnect:YES];
  332. }else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){
  333. //获取连接状态
  334. }
  335. }
  336. else{
  337. //TODO:Wifi配置过程中失败的情况自行处理
  338. }
  339. }
  340. /**
  341. MCU requests user information( MCU 请求用户信息)
  342. @param status 请求状态
  343. */
  344. - (void)bodyFatScaleManagerMCURequestAppUserInfoType:(BodyFatScaleMCURequestUserInfoStatus)status{
  345. if (status == BodyFatScaleMCURequestUserInfoStatus_Get) {
  346. //下发当前用户给秤
  347. [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
  348. }else if (status == BodyFatScaleMCURequestUserInfoStatus_Success){
  349. [self addLog:@"MCU requests user information success"];
  350. }else if (BodyFatScaleMCURequestUserInfoStatus_Fail){
  351. [self addLog:@"MCU requests user information failure"];
  352. }
  353. }
  354. /**
  355. Return weight and body fat model(返回重量及体脂model)
  356. */
  357. -(void)bodyFatScaleManagerCallBackWeight:(ELBodyFatScaleBleWeightModel *)weightModel state:(BodyFatScaleMeasureStatus)status{
  358. switch (status) {
  359. case BodyFatScaleMeasureStatus_Unstable:
  360. {
  361. [self addLog:[NSString stringWithFormat:@"Unstable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  362. }
  363. break;
  364. case BodyFatScaleMeasureStatus_Stable:
  365. {
  366. [self addLog:[NSString stringWithFormat:@"Stable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  367. }
  368. break;
  369. case BodyFatScaleMeasureStatus_Failed:
  370. {
  371. [self addLog:@"Test failure"];
  372. }
  373. break;
  374. case BodyFatScaleMeasureStatus_Complete:
  375. {
  376. [self addLog:[NSString stringWithFormat:@"Tested weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  377. //更新用户信息给秤
  378. [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
  379. //下发用户列表
  380. [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];
  381. }
  382. break;
  383. default:
  384. break;
  385. }
  386. }
  387. /**
  388. Return temperature (unit: ° C)(返回温度(单位:°C))
  389. @param temp 温度(单位:°C)
  390. */
  391. -(void)bodyFatScaleManagerCallBackTemp:(NSString *)temp{
  392. [self addLog:[NSString stringWithFormat:@"temperature is %@",temp]];
  393. }
  394. /**
  395. Back to impedance measurement(返回阻抗测量)
  396. @param status 阻抗测量状态
  397. @param adc 阻抗
  398. */
  399. -(void)bodyFatScaleManagerCallBackAdcMeasureStatus:(BodyFatScaleAdcMeasureStatus)status adcValue:(NSInteger)adc{
  400. switch (status) {
  401. case BodyFatScaleAdcMeasureStatus_Testing:
  402. {
  403. [self addLog:@"adc testing"];
  404. }
  405. break;
  406. case BodyFatScaleAdcMeasureStatus_Success:
  407. {
  408. [self addLog:[NSString stringWithFormat:@"adc is %ld",adc]];
  409. }
  410. break;
  411. case BodyFatScaleAdcMeasureStatus_Fail:
  412. {
  413. [self addLog:@"adc test failure"];
  414. }
  415. break;
  416. case BodyFatScaleAdcMeasureStatus_SuccessCustom:
  417. {
  418. [self addLog:[NSString stringWithFormat:@"adc is %ld and user app algum",adc]];
  419. }
  420. break;
  421. default:
  422. break;
  423. }
  424. }
  425. /**
  426. Callback heart rate measurement(回调心率测量)
  427. @param status 心率测量状态
  428. @param heartRate 心率
  429. */
  430. -(void)bodyFatScaleManagerCallBackHeartRateMeasureStatus:(BodyFatScaleHeartRateMeasureStatus)status heartRateValue:(NSInteger)heartRate{
  431. switch (status) {
  432. case BodyFatScaleHeartRateMeasureStatus_Testing:
  433. {
  434. [self addLog:@"Heart Rate Testing"];
  435. }
  436. break;
  437. case BodyFatScaleHeartRateMeasureStatus_Success:
  438. {
  439. [self addLog:[NSString stringWithFormat:@"Heart Rate is %ld",heartRate]];
  440. }
  441. break;
  442. case BodyFatScaleHeartRateMeasureStatus_Fail:
  443. {
  444. [self addLog:@"Heart Rate Test failure"];
  445. }
  446. break;
  447. default:
  448. break;
  449. }
  450. }
  451. /**
  452. Return error code(返回错误码)
  453. @param code 错误码
  454. 1:超重
  455. */
  456. -(void)bodyFatScaleManagerCallBackErrorCode:(NSInteger)code{
  457. [self addLog:[NSString stringWithFormat:@"error code = %ld",code]];
  458. }
  459. //MARK:回调A6指令数据
  460. /**
  461. Send success or failure callback for offline user list(发送离线用户列表的成功或失败回调)
  462. @param status 状态
  463. */
  464. -(void)bodyFatScaleManagerCallBackUpdateRecordStatus:(BodyFatScaleUpdateRecordStatus)status{
  465. switch (status) {
  466. case BodyFatScaleUpdateRecordStatus_AllSuccess:
  467. {
  468. [self addLog:@"Update All Users Success"];
  469. }
  470. break;
  471. case BodyFatScaleUpdateRecordStatus_OneSuccess:
  472. {
  473. [self addLog:@"Update A User Success"];
  474. }
  475. break;
  476. case BodyFatScaleUpdateRecordStatus_OneFail:
  477. {
  478. [self addLog:@"Update A User Failure"];
  479. }
  480. break;
  481. case BodyFatScaleUpdateRecordStatus_AllFail:
  482. {
  483. [self addLog:@"Update All Users Failure"];
  484. }
  485. break;
  486. default:
  487. break;
  488. }
  489. }
  490. /**
  491. Request callback for offline history(请求离线历史记录的回调)
  492. @param status 状态
  493. */
  494. -(void)bodyFatScaleManagerCallBackSendHistoryDataStatus:(BodyFatScaleSendHistoryDataStatus)status{
  495. if (status == BodyFatScaleSendHistoryDataStatus_No) {
  496. [self addLog:@"No offline datas"];
  497. }else if (status == BodyFatScaleSendHistoryDataStatus_Begin){
  498. [self addLog:@"Begin receive offline datas"];
  499. }else if (status == BodyFatScaleSendHistoryDataStatus_End){
  500. [self addLog:@"End receive offline datas"];
  501. }
  502. }
  503. /**
  504. APP algorithm-offline history data(APP 算法-离线历史记录数据)
  505. @param user 用户信息
  506. */
  507. -(void)bodyFatScaleManagerCallBackBleUserHistoryDataCustomADCModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
  508. //这里的身体指标等数据由app自定义算法计算得到,请区分bodyModel.algNum来调用算法
  509. [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]];
  510. }
  511. /**
  512. MCU algorithm-offline history data(MCU 算法-离线历史记录数据)
  513. @param user 用户信息
  514. @param bodyModel 体脂数据
  515. */
  516. -(void)bodyFatScaleManagerCallBackBleUserHistoryDataModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
  517. //这里的身体指标数据由秤计算得到
  518. [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]];
  519. }
  520. -(void)bleWifiReceiveWifiSNCode:(int)code{
  521. //MARK:11.根据wifi设备的设备id从服务器获取离线数据(找自己后台要接口)
  522. }
  523. -(void)bodyFatScaleManagerUpdateState:(ELBluetoothState)state{
  524. switch (state) {
  525. case ELBluetoothStateUnavailable:
  526. {
  527. self.title = @"Please open the bluetooth";
  528. }
  529. break;
  530. case ELBluetoothStateAvailable:
  531. {
  532. self.title = @"Bluetooth is open";
  533. }
  534. break;
  535. case ELBluetoothStateScaning:
  536. {
  537. self.title = @"Scaning";
  538. }
  539. break;
  540. case ELBluetoothStateConnectFail:
  541. {
  542. self.title = @"Connect fail";
  543. }
  544. break;
  545. case ELBluetoothStateDidDisconnect:
  546. {
  547. self.title = @"Disconnected";
  548. }
  549. break;
  550. case ELBluetoothStateDidValidationPass:
  551. {
  552. self.title = @"Connected";
  553. //获取设备支持的单位
  554. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  555. //将你自己设置的单位发给秤
  556. ELDeviceWeightUnit unit = ELDeviceWeightUnit_KG;
  557. [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:unit];
  558. //请求历史记录
  559. [[ELBodyFatScaleBleManager shareManager] sendCmd_RequestHistory];
  560. //下发用户列表
  561. [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];
  562. if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {
  563. //获取蓝牙连接状态
  564. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];
  565. }
  566. }
  567. break;
  568. case ELBluetoothStateFailedValidation:
  569. {
  570. self.title = @"Illegal equipment";
  571. }
  572. break;
  573. case ELBluetoothStateWillConnect:
  574. self.title = @"Connecting";
  575. break;
  576. default:
  577. break;
  578. }
  579. }
  580. -(NSArray<ELBodyFatScaleBleUserModel *> *)get8Users{
  581. NSMutableArray *users = [[NSMutableArray alloc] init];
  582. for (int i=0; i<8; i++) {
  583. ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
  584. user.createTime = [[NSDate date] timeIntervalSince1970];
  585. user.usrID = i;
  586. user.role = i%4;
  587. user.sex = i%2;
  588. user.age = 26+i;
  589. user.height = 170+i;
  590. user.weight = 600+i;
  591. user.adc = 560+i;
  592. [users addObject:user];
  593. }
  594. return users.copy;
  595. }
  596. -(ELBodyFatScaleBleUserModel *)getOneUser{
  597. ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
  598. user.createTime = [[NSDate date] timeIntervalSince1970];
  599. user.usrID = 0;
  600. user.role = BodyFatScaleRole_Ordinary;
  601. user.sex = ELBluetoothUserSex_Woman;
  602. user.age = 26;
  603. user.height = 170;
  604. user.weight = 600;
  605. user.adc = 560;
  606. return user;
  607. }
  608. -(void)dealloc{
  609. }
  610. @end