iOS AILinkBleSDK - 蓝牙SDK
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

HeightGuageConnectViewController.m 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // HeightGuageConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "HeightGuageConnectViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELHeightGaugeBleManager.h>
  11. #import <AILinkBleSDK/ELBluetoothManager+Settings.h>
  12. @interface HeightGuageConnectViewController ()<ELBluetoothManagerDelegate,ELHeightGaugeBleManagerDelegate>
  13. @property (nonatomic, strong) UITextView *textView;
  14. @end
  15. @implementation HeightGuageConnectViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. [ELHeightGaugeBleManager shareManager].heightGaugeDelegate = self;
  20. [ELHeightGaugeBleManager shareManager].delegate =self;
  21. [[ELHeightGaugeBleManager shareManager] connectPeripheral:self.p];
  22. [self setupUIView];
  23. }
  24. -(void)viewWillDisappear:(BOOL)animated{
  25. [super viewWillDisappear:animated];
  26. [[ELHeightGaugeBleManager shareManager] disconnectPeripheral];
  27. }
  28. -(void)addLog:(NSString *)log{
  29. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  30. }
  31. -(void)buttonAction:(UIButton *)sender{
  32. if ([ELHeightGaugeBleManager shareManager].state != ELBluetoothStateDidValidationPass) {
  33. [self addLog:@"Disconnected"];
  34. return;
  35. }
  36. [self addLog:sender.titleLabel.text];
  37. NSInteger tag = sender.tag;
  38. if (tag == 1) {
  39. //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法
  40. [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  41. }else if (tag == 2){
  42. [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  43. }else if (tag == 3){
  44. [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  45. }else if (tag == 4){
  46. [[ELHeightGaugeBleManager shareManager] setBluetoothName:@"AILink"];
  47. }else if (tag == 5){
  48. [[ELHeightGaugeBleManager shareManager] changeUnit:(ELDeviceHeightUnit_CM)];
  49. }else if (tag == 6){
  50. }else if (tag == 7){
  51. }else if (tag == 8){
  52. }else if (tag == 9){
  53. }
  54. }
  55. -(void)setupUIView{
  56. UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  57. [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  58. button1.tag = 1;
  59. button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  60. button1.titleLabel.numberOfLines = 2;
  61. button1.backgroundColor = [UIColor blackColor];
  62. [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  63. [self.view addSubview:button1];
  64. [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(10);
  66. make.top.mas_equalTo(80);
  67. make.width.mas_equalTo(100);
  68. make.height.mas_equalTo(40);
  69. }];
  70. UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  71. [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  72. button2.tag = 2;
  73. button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  74. button2.titleLabel.numberOfLines = 2;
  75. button2.backgroundColor = [UIColor blackColor];
  76. [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  77. [self.view addSubview:button2];
  78. [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.equalTo(button1.mas_right).mas_offset(10);
  80. make.top.mas_equalTo(80);
  81. make.width.mas_equalTo(100);
  82. make.height.mas_equalTo(40);
  83. }];
  84. UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  85. [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  86. button3.tag = 3;
  87. button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  88. button3.titleLabel.numberOfLines = 2;
  89. button3.backgroundColor = [UIColor blackColor];
  90. [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  91. [self.view addSubview:button3];
  92. [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.equalTo(button2.mas_right).mas_offset(10);
  94. make.top.mas_equalTo(80);
  95. make.width.mas_equalTo(100);
  96. make.height.mas_equalTo(40);
  97. }];
  98. //
  99. UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  100. [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  101. button4.tag = 4;
  102. button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  103. button4.titleLabel.numberOfLines = 2;
  104. button4.backgroundColor = [UIColor blackColor];
  105. [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  106. [self.view addSubview:button4];
  107. [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(10);
  109. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  110. make.width.mas_equalTo(100);
  111. make.height.mas_equalTo(40);
  112. }];
  113. //
  114. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  115. [button5 setTitle:@"Change Unit" forState:(UIControlStateNormal)];
  116. button5.tag = 5;
  117. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  118. button5.titleLabel.numberOfLines = 2;
  119. button5.backgroundColor = [UIColor blackColor];
  120. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  121. [self.view addSubview:button5];
  122. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.equalTo(button4.mas_right).mas_offset(10);
  124. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  125. make.width.mas_equalTo(100);
  126. make.height.mas_equalTo(40);
  127. }];
  128. //
  129. self.textView = [[UITextView alloc] init];
  130. self.textView.backgroundColor = [UIColor blackColor];
  131. self.textView.text = @"Log";
  132. self.textView.textColor = [UIColor redColor];
  133. [self.view addSubview:self.textView];
  134. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.mas_equalTo(10);
  136. make.right.bottom.mas_equalTo(-10);
  137. make.height.mas_equalTo(200);
  138. }];
  139. }
  140. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  141. if (type == ELInetSetCmdTypeSetName) {
  142. if (result == ELSetBluetoothResponseTypeSuccess) {
  143. [self addLog:@"Set name Success "];
  144. }else if (result == ELSetBluetoothResponseTypeFailure){
  145. [self addLog:@"Set name failure "];
  146. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  147. [self addLog:@"Set name unsupport "];
  148. }
  149. }
  150. }
  151. -(void)bluetoothManagerReceiceName:(NSString *)name{
  152. [self addLog:name];
  153. }
  154. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  155. [self addLog:[NSString stringWithFormat:@"CID = %d,VID = %d,PID = %d",did.deviceType,did.vendorID,did.productID]];
  156. }
  157. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  158. [self addLog:bmVersion];
  159. }
  160. //MARK:获取设备支持的单位
  161. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  162. //这里要身高单位
  163. //设置单位时,要设置设备支持的单位
  164. }
  165. /**
  166. call back ELHeightGaugeBleDataModel
  167. */
  168. -(void)heightGaugeBleManagerReceiceTestData:(ELHeightGaugeBleDataModel *_Nonnull)model{
  169. [self addLog:[NSString stringWithFormat:@"height = %ld unit = %@ point = %ld",model.height,AiLinkBleHeightUnitDic[@(model.heightUnit)],model.heightPoint]];
  170. }
  171. /**
  172. call back the result of set unit
  173. */
  174. -(void)heightGaugeBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{
  175. [self addLog:[NSString stringWithFormat:@"change unit result = %lu",(unsigned long)type]];
  176. }
  177. /**
  178. call back fail code
  179. */
  180. -(void)heightGaugeBleManagerReceiveFailCode:(ELHeightGaugeFailCode)code{
  181. [self addLog:[NSString stringWithFormat:@"error code = %lu",(unsigned long)code]];
  182. }
  183. -(void)heightGaugeBleManagerUpdateBleState:(ELBluetoothState)state{
  184. switch (state) {
  185. case ELBluetoothStateUnavailable:
  186. {
  187. self.title = @"Please open the bluetooth";
  188. }
  189. break;
  190. case ELBluetoothStateAvailable:
  191. {
  192. self.title = @"Bluetooth is open";
  193. }
  194. break;
  195. case ELBluetoothStateScaning:
  196. {
  197. self.title = @"Scaning";
  198. }
  199. break;
  200. case ELBluetoothStateConnectFail:
  201. {
  202. self.title = @"Connect fail";
  203. }
  204. break;
  205. case ELBluetoothStateDidDisconnect:
  206. {
  207. self.title = @"Disconnected";
  208. }
  209. break;
  210. case ELBluetoothStateDidValidationPass:
  211. {
  212. self.title = @"Connected";
  213. [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  214. }
  215. break;
  216. case ELBluetoothStateFailedValidation:
  217. {
  218. self.title = @"Illegal equipment";
  219. }
  220. break;
  221. case ELBluetoothStateWillConnect:
  222. self.title = @"Connecting";
  223. break;
  224. default:
  225. break;
  226. }
  227. }
  228. -(void)dealloc{
  229. }
  230. @end