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

ForeheadConnectViewController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. //
  2. // ForeheadConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/8.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "ForeheadConnectViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELForeHeadBleManager.h>
  11. @interface ForeheadConnectViewController ()<ELBluetoothManagerDelegate,ELForeheadBleManagerDelegate>
  12. @property (nonatomic, strong) UITextView *textView;
  13. @end
  14. @implementation ForeheadConnectViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.view.backgroundColor = [UIColor whiteColor];
  18. [ELForeHeadBleManager shareManager].foreheadDelegate = self;
  19. [ELForeHeadBleManager shareManager].delegate =self;
  20. [[ELForeHeadBleManager shareManager] connectPeripheral:self.p];
  21. [self setupUIView];
  22. }
  23. -(void)viewWillDisappear:(BOOL)animated{
  24. [super viewWillDisappear:animated];
  25. [[ELForeHeadBleManager 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 ([ELForeHeadBleManager 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. [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  40. }else if (tag == 2){
  41. [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  42. }else if (tag == 3){
  43. [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  44. }else if (tag == 4){
  45. [[ELForeHeadBleManager shareManager] setBluetoothName:@"AILink"];
  46. }else if (tag == 5){
  47. [[ELForeHeadBleManager shareManager] changeUnit:(ELDeviceTemperatureUnit_C)];
  48. }else if (tag == 6){
  49. [[ELForeHeadBleManager shareManager] changeUnit:(ELDeviceTemperatureUnit_F)];
  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 To C" 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. UIButton *button6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  130. [button6 setTitle:@"Change Unit To F" forState:(UIControlStateNormal)];
  131. button6.tag = 6;
  132. button6.titleLabel.adjustsFontSizeToFitWidth = YES;
  133. button6.titleLabel.numberOfLines = 2;
  134. button6.backgroundColor = [UIColor blackColor];
  135. [button6 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  136. [self.view addSubview:button6];
  137. [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.left.equalTo(button5.mas_right).mas_offset(10);
  139. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  140. make.width.mas_equalTo(100);
  141. make.height.mas_equalTo(40);
  142. }];
  143. //
  144. self.textView = [[UITextView alloc] init];
  145. self.textView.backgroundColor = [UIColor blackColor];
  146. self.textView.text = @"Log";
  147. self.textView.textColor = [UIColor redColor];
  148. [self.view addSubview:self.textView];
  149. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.left.mas_equalTo(10);
  151. make.right.bottom.mas_equalTo(-10);
  152. make.height.mas_equalTo(200);
  153. }];
  154. }
  155. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  156. if (type == ELInetSetCmdTypeSetName) {
  157. if (result == ELSetBluetoothResponseTypeSuccess) {
  158. [self addLog:@"Set name Success "];
  159. }else if (result == ELSetBluetoothResponseTypeFailure){
  160. [self addLog:@"Set name failure "];
  161. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  162. [self addLog:@"Set name unsupport "];
  163. }
  164. }
  165. }
  166. -(void)bluetoothManagerReceiceName:(NSString *)name{
  167. [self addLog:name];
  168. }
  169. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  170. [self addLog:[NSString stringWithFormat:@"CID = %d,VID = %d,PID = %d",did.deviceType,did.vendorID,did.productID]];
  171. }
  172. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  173. [self addLog:bmVersion];
  174. }
  175. //MARK:获取设备支持的单位
  176. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  177. //这里要压力和温度单位
  178. //设置单位时,要设置设备支持的单位
  179. }
  180. /**
  181. Callback temperature(回调温度)
  182. @param model ELForeheadBleDataModel
  183. */
  184. -(void)foreheadBleManagerReceiveTemperature:(ELForeheadBleDataModel *_Nonnull)model dataType:(ForeheadBleDataType)dataType{
  185. [self addLog:[NSString stringWithFormat:@"temperature = %@ unit = %@ point = %ld",model.temperature,AiLinkBleTempUnitDic[@(model.unit)],model.point]];
  186. }
  187. /**
  188. Set unit callback( 设置单位回调)
  189. @param type 结果
  190. */
  191. -(void)foreheadBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{
  192. [self addLog:[NSString stringWithFormat:@"Change Unit result = %lu",(unsigned long)type]];
  193. }
  194. /**
  195. Error code sent on the device(设备上发错误码)
  196. @param code 错误码
  197. */
  198. -(void)foreheadBleManagerReceiveFailCode:(ForeheadFailCode)code{
  199. [self addLog:[NSString stringWithFormat:@"error code = %lu",(unsigned long)code]];
  200. }
  201. -(void)foreheadBleManagerUpdateBleState:(ELBluetoothState)state{
  202. switch (state) {
  203. case ELBluetoothStateUnavailable:
  204. {
  205. self.title = @"Please open the bluetooth";
  206. }
  207. break;
  208. case ELBluetoothStateAvailable:
  209. {
  210. self.title = @"Bluetooth is open";
  211. }
  212. break;
  213. case ELBluetoothStateScaning:
  214. {
  215. self.title = @"Scaning";
  216. }
  217. break;
  218. case ELBluetoothStateConnectFail:
  219. {
  220. self.title = @"Connect fail";
  221. }
  222. break;
  223. case ELBluetoothStateDidDisconnect:
  224. {
  225. self.title = @"Disconnected";
  226. }
  227. break;
  228. case ELBluetoothStateDidValidationPass:
  229. {
  230. self.title = @"Connected";
  231. [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  232. }
  233. break;
  234. case ELBluetoothStateFailedValidation:
  235. {
  236. self.title = @"Illegal equipment";
  237. }
  238. break;
  239. case ELBluetoothStateWillConnect:
  240. self.title = @"Connecting";
  241. break;
  242. default:
  243. break;
  244. }
  245. }
  246. -(void)dealloc{
  247. }
  248. @end