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.

BroadcastScaleViewController.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "Masonry.h"
  11. @interface BroadcastScaleViewController ()<BroadcastScaleBleDelegate>
  12. @property (nonatomic, strong) UITextView *textView;
  13. @property (nonatomic, strong) UILabel *statusLbl;
  14. @end
  15. @implementation BroadcastScaleViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. [ELBroadcastScaleBleManager shareManager].broadcastScaleBleDelegate = self;
  20. [[ELBroadcastScaleBleManager shareManager] startScan];
  21. [self setupUI];
  22. }
  23. -(void)broadcastScaleBleDataModel:(ELBroadcastScaleDataModel *)model{
  24. switch (model.testStatus) {
  25. case BroadcastScaleTestStatusWeightTesting:
  26. {
  27. self.statusLbl.text = @"Weight testing";
  28. }
  29. break;
  30. case BroadcastScaleTestStatusADCTesting: {
  31. self.statusLbl.text = @"Impedance testing";
  32. break;
  33. }
  34. case BroadcastScaleTestStatusADCTestSuccess: {
  35. self.statusLbl.text = @"Impedance test success";
  36. break;
  37. }
  38. case BroadcastScaleTestStatusADCTestFailed: {
  39. self.statusLbl.text = @"Impedance test failed";
  40. break;
  41. }
  42. case BroadcastScaleTestStatusTestEnd: {
  43. self.statusLbl.text = @"Test end";
  44. break;
  45. }
  46. }
  47. 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];
  48. [self addLog:testData];
  49. }
  50. -(void)broadcastScaleBleUpdateState:(ELBluetoothState)state{
  51. if (state == ELBluetoothStateAvailable) {
  52. self.statusLbl.text = @"Connecting";
  53. }else if (state == ELBluetoothStateUnavailable){
  54. self.statusLbl.text = @"Bluetooth is disconnected";
  55. }
  56. }
  57. -(void)addLog:(NSString *)log{
  58. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  59. }
  60. -(void)setupUI{
  61. self.textView = [[UITextView alloc] init];
  62. self.textView.backgroundColor = [UIColor blackColor];
  63. self.textView.text = @"Log";
  64. self.textView.textColor = [UIColor redColor];
  65. [self.view addSubview:self.textView];
  66. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(10);
  68. make.right.bottom.mas_equalTo(-10);
  69. make.height.equalTo(self.view).multipliedBy(0.7);
  70. }];
  71. //
  72. self.statusLbl = [[UILabel alloc] init];
  73. self.statusLbl.text = @"Connecting";
  74. self.statusLbl.adjustsFontSizeToFitWidth = YES;
  75. self.statusLbl.font = [UIFont boldSystemFontOfSize:30];
  76. self.statusLbl.textColor = [UIColor redColor];
  77. self.statusLbl.textAlignment = NSTextAlignmentCenter;
  78. [self.view addSubview:self.statusLbl];
  79. [self.statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.height.mas_equalTo(40);
  81. make.left.right.equalTo(self.textView);
  82. make.bottom.equalTo(self.textView.mas_top).mas_offset(-20);
  83. }];
  84. }
  85. -(void)dealloc{
  86. [[ELBroadcastScaleBleManager shareManager] stopScan];
  87. }
  88. @end