iOS AILinkBleSDK - 蓝牙SDK
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BroadcastNutritionScaleViewController.m 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // BroadcastNutritionScaleViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by LarryZhang on 2021/12/14.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "BroadcastNutritionScaleViewController.h"
  9. #import <AILinkBleSDK/ELBroadcastNutritionFoodScaleBleManager.h>
  10. #import <AILinkBleSDK/ELBroadcastNutritionFoodScaleDataModel.h>
  11. #import "Masonry.h"
  12. @interface BroadcastNutritionScaleViewController () <BroadcastNutritionFoodScaleBleDelegate>
  13. @property(nonatomic, strong) UITextView *textView;
  14. @property(nonatomic, strong) UILabel *statusLbl;
  15. @end
  16. @implementation BroadcastNutritionScaleViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.view.backgroundColor = [UIColor whiteColor];
  20. [ELBroadcastNutritionFoodScaleBleManager shareManager].broadcastNutritionFoodScaleBleDelegate = self;
  21. [[ELBroadcastNutritionFoodScaleBleManager shareManager] startScan];
  22. [self setupUI];
  23. }
  24. - (void)broadcastNutritionFoodScaleBleDataModel:(ELBroadcastNutritionFoodScaleDataModel *_Nonnull)model {
  25. static Byte serialNumber = 0xFF;
  26. if (serialNumber == model.serialNumber) {
  27. return;
  28. }
  29. serialNumber = model.serialNumber;
  30. NSString *testData = [NSString stringWithFormat:@"MAC:%@ cid:%d vid:%d pid:%d weight:%@ weightPoint:%@ weightUnit:%@ sn:%d",
  31. model.mac, model.cid - 65535, model.vid, model.pid, @(model.weight), @(model.weightPoint), @(model.weightUnit), model.serialNumber];
  32. [self addLog:testData];
  33. }
  34. - (void)broadcastNutritionFoodScaleBleUpdateState:(ELBluetoothState)state {
  35. if (state == ELBluetoothStateAvailable) {
  36. self.statusLbl.text = @"Connecting";
  37. } else if (state == ELBluetoothStateUnavailable) {
  38. self.statusLbl.text = @"Bluetooth is disconnected";
  39. }
  40. }
  41. - (void)addLog:(NSString *)log {
  42. self.textView.text = [NSString stringWithFormat:@"%@\n%@", log, self.textView.text];
  43. }
  44. - (void)setupUI {
  45. self.textView = [[UITextView alloc] init];
  46. self.textView.backgroundColor = [UIColor blackColor];
  47. self.textView.text = @"Log";
  48. self.textView.textColor = [UIColor redColor];
  49. [self.view addSubview:self.textView];
  50. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(10);
  52. make.right.bottom.mas_equalTo(-10);
  53. make.height.equalTo(self.view).multipliedBy(0.7);
  54. }];
  55. //
  56. self.statusLbl = [[UILabel alloc] init];
  57. self.statusLbl.text = @"Connecting";
  58. self.statusLbl.adjustsFontSizeToFitWidth = YES;
  59. self.statusLbl.font = [UIFont boldSystemFontOfSize:30];
  60. self.statusLbl.textColor = [UIColor redColor];
  61. self.statusLbl.textAlignment = NSTextAlignmentCenter;
  62. [self.view addSubview:self.statusLbl];
  63. [self.statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.height.mas_equalTo(40);
  65. make.left.right.equalTo(self.textView);
  66. make.bottom.equalTo(self.textView.mas_top).mas_offset(-20);
  67. }];
  68. }
  69. - (void)dealloc {
  70. [[ELBroadcastNutritionFoodScaleBleManager shareManager] stopScan];
  71. }
  72. @end