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.

SkipConnectionViewController.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // FaceMaskConnectionViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by LarryZhang on 2021/12/13.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "SkipConnectionViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELSkipBleDataModel.h>
  11. #import <AILinkBleSDK/ELSkipBleManager.h>
  12. @interface SkipConnectionViewController () <ELSkipBleDelegate, ELBluetoothManagerDelegate>
  13. @property(nonatomic, strong) UITextView *textView;
  14. @property(nonatomic, copy) NSArray<NSNumber *> *units;
  15. @property(nonatomic, strong) UIButton *connectButton;
  16. @end
  17. @implementation SkipConnectionViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.view.backgroundColor = [UIColor whiteColor];
  22. [ELSkipBleManager shareManager].skipDelegate = self;
  23. [ELSkipBleManager shareManager].delegate = self;
  24. [[ELSkipBleManager shareManager] connectPeripheral:self.p];
  25. [self setupUIView];
  26. }
  27. - (void)viewWillDisappear:(BOOL)animated {
  28. [[ELSkipBleManager shareManager] disconnectPeripheral];
  29. }
  30. - (void)addLog:(NSString *)log {
  31. self.textView.text = [NSString stringWithFormat:@"%@\n\n%@", log, self.textView.text];
  32. }
  33. //- (void)connectDevice {
  34. // [[ELSkipBleManager shareManager] startScan];
  35. //}
  36. - (void)setupUIView {
  37. // self.connectButton = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100) / 2, 88, 100, 40)];
  38. // [self.connectButton setTitle:@"点击重连" forState:UIControlStateNormal];
  39. // [self.connectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  40. // [self.view addSubview:self.connectButton];
  41. // [self.connectButton addTarget:self action:@selector(connectDevice) forControlEvents:UIControlEventTouchUpInside];
  42. // self.connectButton.hidden = YES;
  43. self.textView = [[UITextView alloc] init];
  44. self.textView.backgroundColor = [UIColor blackColor];
  45. self.textView.text = @"Log";
  46. self.textView.textColor = [UIColor redColor];
  47. [self.view addSubview:self.textView];
  48. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(10);
  50. make.right.mas_equalTo(-10);
  51. make.bottom.offset(-44);
  52. // make.height.mas_equalTo(350);
  53. make.top.offset(80);
  54. }];
  55. }
  56. #pragma mark - ble Delegate
  57. //- (void)skipManagerScanDevices:(nonnull NSArray<ELPeripheralModel *> *)scanDevices {
  58. // //reconnect
  59. //}
  60. /// 蓝牙连接状态
  61. /// @param state 连接状态
  62. - (void)skipManagerUpdateState:(ELBluetoothState)state {
  63. switch (state) {
  64. case ELBluetoothStateUnavailable: {
  65. self.title = @"Please open the bluetooth";
  66. }
  67. break;
  68. case ELBluetoothStateAvailable: {
  69. self.title = @"Bluetooth is open";
  70. }
  71. break;
  72. case ELBluetoothStateScaning: {
  73. self.title = @"Scanning";
  74. }
  75. break;
  76. case ELBluetoothStateConnectFail: {
  77. self.title = @"Connect fail";
  78. }
  79. break;
  80. case ELBluetoothStateDidDisconnect: {
  81. self.title = @"Disconnected";
  82. self.connectButton.hidden = NO;
  83. }
  84. break;
  85. case ELBluetoothStateDidValidationPass: {
  86. self.connectButton.hidden = YES;
  87. self.title = @"Connected";
  88. //获取版本号
  89. [[ELSkipBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeGetBMVersion];
  90. //发送绑定命令(如果设备不支持绑定确认,也可以不发)
  91. [[ELSkipBleManager shareManager] bindDeviceWithType:Skip_BindDeviceType_KeyBinding];
  92. //弹出提示框
  93. //[self showPopupView];
  94. }
  95. break;
  96. case ELBluetoothStateFailedValidation: {
  97. self.title = @"Illegal equipment";
  98. }
  99. break;
  100. case ELBluetoothStateWillConnect:
  101. self.title = @"Connecting";
  102. break;
  103. case ELBluetoothStateUnauthorized:
  104. self.title = @"BLE Unauthorized";
  105. default:
  106. break;
  107. }
  108. }
  109. //返回绑定结果
  110. - (void)skipManagerResult:(enum Skip_ResultType)result bleHeaderType:(enum Skip_BleHeadType)type {
  111. if (type == Skip_BleHeadType_BindDevice) {
  112. if (result == Skip_ResultType_Success) {
  113. [self addLog:@"绑定成功"];
  114. //通过验证,同步设备时间
  115. [[ELSkipBleManager shareManager] syncDevTimeStamp:[[NSDate date] timeIntervalSince1970]];
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. //获取离线历史记录
  118. [[ELSkipBleManager shareManager] getOfflineHistory];
  119. });
  120. } else {
  121. [self addLog:@"绑定失败"];
  122. }
  123. }
  124. }
  125. //返回版本号
  126. - (void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion {
  127. [self addLog:[NSString stringWithFormat:@"ble version:%@", bmVersion]];
  128. }
  129. - (void)skipManagerRealtimeDataWithState:(enum Skip_ReadyStateType)readyState skipModel:(nonnull ELSkipBleDataModel *)model power:(NSUInteger)power {
  130. [self addLog:[NSString stringWithFormat:@"skip state:%zd num:%zd",readyState, model.sportNum]];
  131. }
  132. - (void)skipManagerReportOfflineHistoryWithHistoryModelList:(nonnull NSArray<ELSkipHistoryDataModel *> *)modelList {
  133. [self addLog:[NSString stringWithFormat:@"skip history num:%zd",modelList.count]];
  134. }
  135. - (void)skipManagerSportEndReportDataWithHistoryModel:(nonnull ELSkipHistoryDataModel *)model {
  136. [self addLog:[NSString stringWithFormat:@"skip end, result:%zd",model.dataModel.sportNum]];
  137. }
  138. @end