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.

HygrothermographVC.m 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // HygrothermographVC.m
  3. // AILinkBleSDK_Example
  4. //
  5. #import "HygrothermographVC.h"
  6. #import <AILinkBleSDK/ELHygrothermographBleManager.h>
  7. #import <AILinkBleSDK/ELHygrothermographBleRecordData.h>
  8. #import <AILinkBleSDK/ELAILinkBleManager.h>
  9. #import "ELDemoButton.h"
  10. @interface HygrothermographVC () <ELBluetoothManagerDelegate, ELHygrothermographBleDelegate>
  11. @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel;
  12. @property (weak, nonatomic) IBOutlet UITextView *logTextView;
  13. //work mode
  14. @property (weak, nonatomic) IBOutlet ELDemoButton *weightModeButton;
  15. @property (nonatomic, assign) ELBluetoothState state;
  16. @end
  17. @implementation HygrothermographVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view from its nib.
  21. [self bleScan];
  22. }
  23. - (void)dealloc {
  24. [ELHygrothermographBleManager shareManager].delegate = nil;
  25. [ELHygrothermographBleManager shareManager].hygrothermographDelegate = nil;
  26. [[ELHygrothermographBleManager shareManager] disconnectPeripheral];
  27. }
  28. - (void)bleScan {
  29. //创建蓝牙
  30. [ELHygrothermographBleManager shareManager].delegate = self;
  31. [ELHygrothermographBleManager shareManager].hygrothermographDelegate = self;
  32. [[ELHygrothermographBleManager shareManager] startScan];
  33. }
  34. #pragma mark -Actions
  35. - (IBAction)getDevStateAction:(id)sender {
  36. // /** 获取设备状态 */
  37. [[ELHygrothermographBleManager shareManager] getDevStateWithCid:self.per.cid];
  38. }
  39. - (IBAction)getDevHisDataAction:(id)sender {
  40. NSInteger maxDevTime = 0;
  41. [[ELHygrothermographBleManager shareManager] getDevRecordDataWithDevTime:maxDevTime cid:self.per.cid];
  42. }
  43. #pragma mark - addLog
  44. - (IBAction)clearAction:(id)sender {
  45. self.logTextView.text = @"";
  46. }
  47. - (IBAction)shareLogAction:(id)sender {
  48. }
  49. - (void)addLog:(NSString *)log {
  50. [self addLog:log newline:YES];
  51. }
  52. - (void)addWithoutNewlineLog:(NSString *)log {
  53. [self addLog:log newline:NO];
  54. }
  55. - (void)addLog:(NSString *)log newline:(BOOL)newline {
  56. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  57. format.dateFormat = @"HH:mm:ss.SSS";
  58. NSString *time = [format stringFromDate:[NSDate date]];
  59. if (newline) {
  60. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log];
  61. } else {
  62. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@", time, log];
  63. }
  64. [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)];
  65. }
  66. @end
  67. #pragma mark - ble Delegate
  68. @implementation HygrothermographVC (ble)
  69. ///返回设备连接状态
  70. - (void)hygrothermographManagerUpdateState:(ELBluetoothState)state {
  71. NSLog(@"hygrothermograph ManagerUpdateState() state:%@", @(state));
  72. if (state == ELBluetoothStateDidValidationPass) {
  73. [self deviceInit];
  74. }
  75. NSString *text = nil;
  76. if (state == ELBluetoothStateScaning) {
  77. text = @"BLE connecting";
  78. } else if (state == ELBluetoothStateConnectFail) {
  79. text = @"BLE failed";
  80. } else if (state == ELBluetoothStateDidValidationPass) {
  81. text = @"BLE connected";
  82. } else if (state == ELBluetoothStateDidDisconnect) {
  83. text = @"BLE did disconnect";
  84. }
  85. if (text) {
  86. self.bleStatusLabel.text = text;
  87. if (self.state != state) {
  88. [self addLog:text];
  89. }
  90. }
  91. self.state = state;
  92. }
  93. ///回调扫描到的身高体脂秤
  94. - (void)hygrothermographManagerScanDevices:(NSArray<ELPeripheralModel *> *)scanDevices {
  95. for (ELPeripheralModel *model in scanDevices) {
  96. if ([model.macAddress isEqualToString:self.per.macAddressString]) {
  97. [[ELHygrothermographBleManager shareManager] stopScan];
  98. [[ELHygrothermographBleManager shareManager] connectPeripheral:model];
  99. }
  100. }
  101. }
  102. - (void)deviceInit {
  103. //同步时间
  104. [[ELHygrothermographBleManager shareManager] setUnixTime:[[NSDate date] timeIntervalSince1970]];
  105. // 获取设备支持的功能列表
  106. [[ELHygrothermographBleManager shareManager] getDevSupportFeaturesWithCid:self.per.cid];
  107. // APP获取设备报警功能
  108. [[ELHygrothermographBleManager shareManager] getDevAlarmDataInfoWithCid:self.per.cid];
  109. // 查询BM是否支持历史记录
  110. [[ELHygrothermographBleManager shareManager] getSupportRecordDataWithCid:self.per.cid];
  111. }
  112. // 设备返回当前状态
  113. - (void)hygrothermographManagerReturnDevStatePower:(NSInteger)power bootTime:(long long)time tem:(float)tem hum:(float)hum {
  114. NSString *log = [NSString stringWithFormat:@"hygrothermograph power:%ld time:%lld tem:%f hum:%f", power, time, tem, hum];
  115. NSLog(@"%@", log);
  116. [self addLog:log];
  117. }
  118. // BM设备返回设备状态
  119. - (void)newTHManagerReturnDevStatePower:(int)power bootTime:(long long)time tem:(float)tem unit:(enum ELDeviceTemperatureUnit)unit hum:(float)hum devState:(enum TH_DevStateType)state {
  120. NSString *log = [NSString stringWithFormat:@"hygrothermograph power:%d time:%lld tem:%f unit:%ld hum:%f state:%ld", power, time, tem, (long)unit, hum, (long)state];
  121. NSLog(@"%@", log);
  122. [self addLog:log];
  123. }
  124. // 返回历史记录
  125. - (void)hygrothermographManagerReturnRecordDataList:(NSArray<ELHygrothermographBleRecordData *> *)list allListNumber:(long long)allNumber getListNumber:(long long)getNumber {
  126. NSString *log = [NSString stringWithFormat:@"hygrothermograph list:%@ allListNumber:%lld getListNumber:%lld", list, allNumber, getNumber];
  127. NSLog(@"%@", log);
  128. [self addLog:log];
  129. }
  130. // 回应是否支持历史记录
  131. - (void)THManagerSupportRecordData:(BOOL)state {
  132. NSString *log = state ? @"支持历史记录" : @"不支持历史记录";
  133. NSLog(@"hygrothermograph %@", log);
  134. [self addLog:log];
  135. }
  136. // 返回支持的功能列表
  137. - (void)THManagerSuportList:(NSArray<NSNumber *> *)list {
  138. [self addLog:@"返回支持的功能列表"];
  139. for (NSNumber *number in list) {
  140. switch (number.intValue) {
  141. case TH_Dev_SupportFeatures_Calibration: {
  142. // 获取温度校准状态
  143. [[ELHygrothermographBleManager shareManager] setOrGetTemHumCalibrationValueWithSet:false cTem:0 fTem:0 hum:0 cid:self.per.cid];
  144. }
  145. break;
  146. case TH_Dev_SupportFeatures_BuzzerAlarm: {
  147. // 获取蜂鸣器报警状态,暂不支持
  148. }
  149. break;
  150. case TH_Dev_SupportFeatures_AlarmClock: {
  151. // 闹钟功能
  152. [[ELHygrothermographBleManager shareManager] setOrGetAlarmClockWithState:TH_AlarmClockState_Get num:0 mode:TH_AlarmClockMode_Everyday timeStr:@"00:00:00" open:false cid:self.per.cid];
  153. }
  154. break;
  155. case TH_Dev_SupportFeatures_ReportPunctually: {
  156. // 整点报时,暂不支持
  157. }
  158. break;
  159. case TH_Dev_SupportFeatures_NightLight: {
  160. // 获取小夜灯
  161. [[ELHygrothermographBleManager shareManager] setOrGetDevNightLightWithCmd:false open:false cid:self.per.cid];
  162. }
  163. break;
  164. case TH_Dev_SupportFeatures_GroundLight: {
  165. // 获取背光亮度
  166. [[ELHygrothermographBleManager shareManager] setOrGetGroundLightWithCmd:false open:false brightness:0 cid:self.per.cid];
  167. }
  168. break;
  169. case TH_Dev_SupportFeatures_Lost: {
  170. // 寻物功能
  171. }
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177. }
  178. /// 返回蜂鸣器设置结果
  179. - (void)THManagerBuzzerState:(BOOL)open {
  180. NSString *log = open ? @"返回蜂鸣器: 开" : @"返回蜂鸣器: 关";
  181. [self addLog:log];
  182. }
  183. /// 返回闹钟列表
  184. - (void)THManagerAlarmLockState:(enum TH_AlarmClockState)state num:(int)num mode:(enum TH_AlarmClockMode)mode timeStr:(NSString *)timeStr open:(BOOL)open {
  185. NSString *log = [NSString stringWithFormat:@"返回闹钟列表 %ld,%d,%ld,%@,%d", state, num, mode,timeStr, open ? 1 : 0];
  186. [self addLog:log];
  187. }
  188. /// 返回小夜灯
  189. - (void)THManagerNightLightState:(BOOL)open {
  190. NSString *log = open ? @"返回小夜灯: 开" : @"返回小夜灯: 关";
  191. [self addLog:log];
  192. }
  193. /// 返回背光亮度
  194. - (void)THManagerGounrdLightState:(BOOL)open brightness:(int)brightness {
  195. NSString *log = [NSString stringWithFormat:@"返回小夜灯: %@ brightness: %d", open ? @"开" : @"关", brightness];
  196. [self addLog:log];
  197. }
  198. /// 返回整点报时
  199. - (void)THManagerReportPunctuallyState:(BOOL)open {
  200. NSString *log = open ? @"返回整点报时: 开" : @"返回整点报时: 关";
  201. [self addLog:log];
  202. }
  203. /// 设备返回当前单位
  204. - (void)THManagerUnitState:(enum ELDeviceTemperatureUnit)unit {
  205. NSString *log = unit == 0 ? @"设备返回当前单位:℃" : @"设备返回当前单位:℉";
  206. [self addLog:log];
  207. }
  208. /// 设备返回温度校准值
  209. - (void)hygrothermographManagerReturnCalibrationValueWithTem:(float)tem hum:(float)hum {
  210. NSString *log = [NSString stringWithFormat:@"设备返回温度校准值 tem: %f hum: %f", tem, hum];
  211. [self addLog:log];
  212. }
  213. //返回阀值
  214. - (void)hygrothermographManagerReturnThresholdTemThreshold:(float)tem humThreshold:(float)hum {
  215. }
  216. //返回设备信息
  217. - (void)hygrothermographManagerReturnDevType:(enum Hygrothermograph_DevType)type version:(NSString *)version IMEI:(NSString *)IMEI {
  218. }
  219. //返回设备报警值
  220. - (void)hygrothermographManagerReturnTemAlarmSwitch:(BOOL)temAlarm highTemAlarm:(float)highTem lowTemAlarm:(float)lowTem humAlarmSwitch:(BOOL)humAlarm highHumAlarm:(float)highHum lowHumAlarm:(float)lowHum {
  221. NSString *log = [NSString stringWithFormat:@"返回设备报警值 temAlarm:%@ highTem:%f lowTem:%f humAlarm:%@ highHum:%f lowHum:%f", temAlarm ? @"开" : @"关", highTem, lowTem, humAlarm ? @"开" : @"关", highHum, lowHum];
  222. [self addLog:log];
  223. }
  224. @end