iOS AILinkBleSDK - 蓝牙SDK
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BroadcastScaleViewController.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // BroadcastScaleViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/9/12.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "BroadcastScaleViewController.h"
  9. #import <AILinkBleSDK/ELBroadcastScaleBleManager.h>
  10. #import <AILinkBleSDK/OEMAlgorithmSDK.h>
  11. #import <AILinkBleSDK/ELBodyFatScaleBleUserModel.h>
  12. #import <AILinkBleSDK/ELWeightAlgorithmusModel.h>
  13. #import "Masonry.h"
  14. @interface BroadcastScaleViewController () <BroadcastScaleBleDelegate>
  15. @property(nonatomic, strong) UITextView *textView;
  16. @property(nonatomic, strong) UILabel *statusLbl;
  17. @property(nonatomic, strong) ELBroadcastScaleDataModel *dataModel;
  18. @end
  19. @implementation BroadcastScaleViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.view.backgroundColor = [UIColor whiteColor];
  23. [ELBroadcastScaleBleManager shareManager].broadcastScaleBleDelegate = self;
  24. [[ELBroadcastScaleBleManager shareManager] startScan];
  25. [self setupUI];
  26. }
  27. - (void)broadcastScaleBleDataModel:(ELBroadcastScaleDataModel *)model {
  28. switch (model.testStatus) {
  29. case BroadcastScaleTestStatusWeightTesting: {
  30. self.statusLbl.text = @"Weight testing";
  31. }
  32. break;
  33. case BroadcastScaleTestStatusADCTesting: {
  34. self.statusLbl.text = @"Impedance testing";
  35. break;
  36. }
  37. case BroadcastScaleTestStatusADCTestSuccess: {
  38. self.statusLbl.text = @"Impedance test success";
  39. break;
  40. }
  41. case BroadcastScaleTestStatusADCTestFailed: {
  42. self.statusLbl.text = @"Impedance test failed";
  43. break;
  44. }
  45. case BroadcastScaleTestStatusTestEnd: {
  46. self.statusLbl.text = @"Test end";
  47. ELBodyFatScaleBleUserModel *user = self.getOneUser;
  48. NSString *weightKg = [ELWeightAlgorithmusModel getKgWithWeightShowStr:model.weight weightUnit:model.weightUnit weightPoint:model.weightPoint];
  49. OEMAlgorithmModel *agModel = [OEMAlgorithmSDK getBodyfatWithWeight:weightKg.floatValue adc:(int) model.adc sex:user.sex age:(int) user.age height:(int) user.height];
  50. NSLog(@"agModel:%@", agModel);
  51. break;
  52. }
  53. }
  54. NSString *testData = [NSString stringWithFormat:@"MAC:%@\ncid = %d--vid=%d--pid=%d\nWeight = %@%@\nADC = %d", model.mac, model.cid - 65535, model.vid, model.pid, model.weight, AiLinkBleWeightUnitDic[@(model.weightUnit)], model.adc];
  55. [self addLog:testData];
  56. }
  57. - (void)broadcastScaleBleUpdateState:(ELBluetoothState)state {
  58. if (state == ELBluetoothStateAvailable) {
  59. self.statusLbl.text = @"Connecting";
  60. } else if (state == ELBluetoothStateUnavailable) {
  61. self.statusLbl.text = @"Bluetooth is disconnected";
  62. }
  63. }
  64. - (void)addLog:(NSString *)log {
  65. self.textView.text = [NSString stringWithFormat:@"%@\n%@", log, self.textView.text];
  66. }
  67. - (void)setupUI {
  68. self.textView = [[UITextView alloc] init];
  69. self.textView.backgroundColor = [UIColor blackColor];
  70. self.textView.text = @"Log";
  71. self.textView.textColor = [UIColor redColor];
  72. [self.view addSubview:self.textView];
  73. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(10);
  75. make.right.bottom.mas_equalTo(-10);
  76. make.height.equalTo(self.view).multipliedBy(0.7);
  77. }];
  78. //
  79. self.statusLbl = [[UILabel alloc] init];
  80. self.statusLbl.text = @"Connecting";
  81. self.statusLbl.adjustsFontSizeToFitWidth = YES;
  82. self.statusLbl.font = [UIFont boldSystemFontOfSize:30];
  83. self.statusLbl.textColor = [UIColor redColor];
  84. self.statusLbl.textAlignment = NSTextAlignmentCenter;
  85. [self.view addSubview:self.statusLbl];
  86. [self.statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.height.mas_equalTo(40);
  88. make.left.right.equalTo(self.textView);
  89. make.bottom.equalTo(self.textView.mas_top).mas_offset(-20);
  90. }];
  91. }
  92. - (void)dealloc {
  93. [[ELBroadcastScaleBleManager shareManager] stopScan];
  94. }
  95. - (ELBodyFatScaleBleUserModel *)getOneUser {
  96. ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
  97. user.createTime = [[NSDate date] timeIntervalSince1970];
  98. user.usrID = 0;
  99. user.role = BodyFatScaleRole_Ordinary;
  100. user.sex = ELBluetoothUserSex_Woman;
  101. user.age = 26;
  102. user.height = 170;
  103. user.weight = 600;
  104. user.adc = 560;
  105. return user;
  106. }
  107. @end