iOS AILinkBleSDK - 蓝牙SDK
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

HeightGuageConnectViewController.m 9.2KB

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