iOS AILinkBleSDK - 蓝牙SDK
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BloodConnectViewController.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //
  2. // BloodConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "BloodConnectViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELBloodBleManager.h>
  11. #import <AILinkBleSDK/ELBluetoothManager+Settings.h>
  12. @interface BloodConnectViewController ()<ELBluetoothManagerDelegate,ELBloodBleManagerDelegate>
  13. @property (nonatomic, strong) UITextView *textView;
  14. @end
  15. @implementation BloodConnectViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. [ELBloodBleManager shareManager].bloodDelegate = self;
  20. [ELBloodBleManager shareManager].delegate =self;
  21. [[ELBloodBleManager shareManager] connectPeripheral:self.p];
  22. [self setupUIView];
  23. }
  24. -(void)viewWillDisappear:(BOOL)animated{
  25. [super viewWillDisappear:animated];
  26. [[ELBloodBleManager 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 ([ELBloodBleManager 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. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  41. }else if (tag == 2){
  42. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  43. }else if (tag == 3){
  44. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  45. }else if (tag == 4){
  46. [[ELBloodBleManager shareManager] setBluetoothName:@"AILink"];
  47. }else if (tag == 5){
  48. [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStartTest)];
  49. }else if (tag == 6){
  50. [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStopTest)];
  51. }else if (tag == 7){
  52. [[ELBloodBleManager shareManager] changeUnit:(ELDeviceBloodPressureUnit_mmhg)];
  53. }else if (tag == 8){
  54. [[ELBloodBleManager shareManager] sendSwitchVoice:(ELBloodBleSwitchVoiceTypeOff)];
  55. }else if (tag == 9){
  56. [[ELBloodBleManager shareManager] sendSwitchVoice:(ELBloodBleSwitchVoiceTypeOn)];
  57. }
  58. }
  59. -(void)setupUIView{
  60. UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  61. [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  62. button1.tag = 1;
  63. button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  64. button1.titleLabel.numberOfLines = 2;
  65. button1.backgroundColor = [UIColor blackColor];
  66. [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  67. [self.view addSubview:button1];
  68. [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(10);
  70. make.top.mas_equalTo(80);
  71. make.width.mas_equalTo(100);
  72. make.height.mas_equalTo(40);
  73. }];
  74. UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  75. [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  76. button2.tag = 2;
  77. button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  78. button2.titleLabel.numberOfLines = 2;
  79. button2.backgroundColor = [UIColor blackColor];
  80. [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  81. [self.view addSubview:button2];
  82. [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(button1.mas_right).mas_offset(10);
  84. make.top.mas_equalTo(80);
  85. make.width.mas_equalTo(100);
  86. make.height.mas_equalTo(40);
  87. }];
  88. UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  89. [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  90. button3.tag = 3;
  91. button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  92. button3.titleLabel.numberOfLines = 2;
  93. button3.backgroundColor = [UIColor blackColor];
  94. [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  95. [self.view addSubview:button3];
  96. [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.equalTo(button2.mas_right).mas_offset(10);
  98. make.top.mas_equalTo(80);
  99. make.width.mas_equalTo(100);
  100. make.height.mas_equalTo(40);
  101. }];
  102. //
  103. UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  104. [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  105. button4.tag = 4;
  106. button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  107. button4.titleLabel.numberOfLines = 2;
  108. button4.backgroundColor = [UIColor blackColor];
  109. [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  110. [self.view addSubview:button4];
  111. [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.mas_equalTo(10);
  113. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  114. make.width.mas_equalTo(100);
  115. make.height.mas_equalTo(40);
  116. }];
  117. //
  118. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  119. [button5 setTitle:@"Start Test" forState:(UIControlStateNormal)];
  120. button5.tag = 5;
  121. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  122. button5.titleLabel.numberOfLines = 2;
  123. button5.backgroundColor = [UIColor blackColor];
  124. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  125. [self.view addSubview:button5];
  126. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.equalTo(button4.mas_right).mas_offset(10);
  128. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  129. make.width.mas_equalTo(100);
  130. make.height.mas_equalTo(40);
  131. }];
  132. //
  133. //
  134. UIButton *button6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  135. [button6 setTitle:@"Stop Test" forState:(UIControlStateNormal)];
  136. button6.tag = 6;
  137. button6.titleLabel.adjustsFontSizeToFitWidth = YES;
  138. button6.titleLabel.numberOfLines = 2;
  139. button6.backgroundColor = [UIColor blackColor];
  140. [button6 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  141. [self.view addSubview:button6];
  142. [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.left.equalTo(button5.mas_right).mas_offset(10);
  144. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  145. make.width.mas_equalTo(100);
  146. make.height.mas_equalTo(40);
  147. }];
  148. //
  149. UIButton *button7 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  150. [button7 setTitle:@"Change Unit" forState:(UIControlStateNormal)];
  151. button7.tag = 7;
  152. button7.titleLabel.adjustsFontSizeToFitWidth = YES;
  153. button7.titleLabel.numberOfLines = 2;
  154. button7.backgroundColor = [UIColor blackColor];
  155. [button7 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  156. [self.view addSubview:button7];
  157. [button7 mas_makeConstraints:^(MASConstraintMaker *make) {
  158. make.left.mas_equalTo(10);
  159. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  160. make.width.mas_equalTo(100);
  161. make.height.mas_equalTo(40);
  162. }];
  163. UIButton *button8 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  164. [button8 setTitle:@"Close Voice" forState:(UIControlStateNormal)];
  165. button8.tag = 8;
  166. button8.titleLabel.adjustsFontSizeToFitWidth = YES;
  167. button8.titleLabel.numberOfLines = 2;
  168. button8.backgroundColor = [UIColor blackColor];
  169. [button8 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  170. [self.view addSubview:button8];
  171. [button8 mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.left.mas_equalTo(10);
  173. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  174. make.width.mas_equalTo(100);
  175. make.height.mas_equalTo(40);
  176. }];
  177. UIButton *button9 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  178. [button9 setTitle:@"Open Voice" forState:(UIControlStateNormal)];
  179. button9.tag = 9;
  180. button9.titleLabel.adjustsFontSizeToFitWidth = YES;
  181. button9.titleLabel.numberOfLines = 2;
  182. button9.backgroundColor = [UIColor blackColor];
  183. [button9 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  184. [self.view addSubview:button9];
  185. [button9 mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.left.equalTo(button8.mas_right).mas_offset(10);
  187. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  188. make.width.mas_equalTo(100);
  189. make.height.mas_equalTo(40);
  190. }];
  191. //
  192. self.textView = [[UITextView alloc] init];
  193. self.textView.backgroundColor = [UIColor blackColor];
  194. self.textView.text = @"Log";
  195. self.textView.textColor = [UIColor redColor];
  196. [self.view addSubview:self.textView];
  197. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  198. make.left.mas_equalTo(10);
  199. make.right.bottom.mas_equalTo(-10);
  200. make.height.mas_equalTo(200);
  201. }];
  202. }
  203. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  204. if (type == ELInetSetCmdTypeSetName) {
  205. if (result == ELSetBluetoothResponseTypeSuccess) {
  206. [self addLog:@"Set name Success "];
  207. }else if (result == ELSetBluetoothResponseTypeFailure){
  208. [self addLog:@"Set name failure "];
  209. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  210. [self addLog:@"Set name unsupport "];
  211. }
  212. }
  213. }
  214. -(void)bluetoothManagerReceiceName:(NSString *)name{
  215. [self addLog:name];
  216. }
  217. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  218. [self addLog:[NSString stringWithFormat:@"CID = %lu,VID = %d,PID = %d",(unsigned long)did.deviceType,did.vendorID,did.productID]];
  219. }
  220. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  221. [self addLog:bmVersion];
  222. }
  223. //MARK:获取设备支持的单位
  224. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  225. //这里要血压单位
  226. //设置单位时,要设置设备支持的单位
  227. }
  228. -(void)bloodBleManagerReceiceTestData:(ELBloodBleDataModel *)model type:(ELBloodBleDataModelType)type{
  229. [self addLog:[NSString stringWithFormat:@"dia = %@--sys=%@ unit = %zd point = %d",model.dia,model.sys,model.unit,model.point]];
  230. }
  231. -(void)bloodBleManagerReceiveSetSwitchVoiceOperationType:(ELBloodBleSwitchVoiceType)type result:(ELSetBluetoothResponseType)result{
  232. if (type == ELBloodBleSwitchVoiceTypeOff) {
  233. [self addLog:[NSString stringWithFormat:@"close voice result = %ld",result]];
  234. }else{
  235. [self addLog:[NSString stringWithFormat:@"open voice result = %ld",result]];
  236. }
  237. }
  238. -(void)bloodBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{
  239. [self addLog:[NSString stringWithFormat:@"change unit result = %ld",type]];
  240. }
  241. -(void)bloodBleManagerReceiveFailCode:(ELBloodFailCode)code{
  242. [self addLog:[NSString stringWithFormat:@"error code = %ld",code]];
  243. }
  244. -(void)bloodBleManagerUpdateBleState:(ELBluetoothState)state{
  245. switch (state) {
  246. case ELBluetoothStateUnavailable:
  247. {
  248. self.title = @"Please open the bluetooth";
  249. }
  250. break;
  251. case ELBluetoothStateAvailable:
  252. {
  253. self.title = @"Bluetooth is open";
  254. }
  255. break;
  256. case ELBluetoothStateScaning:
  257. {
  258. self.title = @"Scaning";
  259. }
  260. break;
  261. case ELBluetoothStateConnectFail:
  262. {
  263. self.title = @"Connect fail";
  264. }
  265. break;
  266. case ELBluetoothStateDidDisconnect:
  267. {
  268. self.title = @"Disconnected";
  269. }
  270. break;
  271. case ELBluetoothStateDidValidationPass:
  272. {
  273. self.title = @"Connected";
  274. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  275. }
  276. break;
  277. case ELBluetoothStateFailedValidation:
  278. {
  279. self.title = @"Illegal equipment";
  280. }
  281. break;
  282. case ELBluetoothStateWillConnect:
  283. self.title = @"Connecting";
  284. break;
  285. default:
  286. break;
  287. }
  288. }
  289. -(void)dealloc{
  290. }
  291. @end