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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 testStatus:%@ negative:%@ weight:%@ weightPoint:%@ weightUnit:%@ sn:%d", model.mac, model.cid - 65535, model.vid, model.pid, @(model.testStatus), @(model.negative), @(model.weight), @(model.weightPoint), @(model.weightUnit), model.serialNumber];
  31. [self addLog:testData];
  32. }
  33. - (void)broadcastNutritionFoodScaleBleUpdateState:(ELBluetoothState)state {
  34. if (state == ELBluetoothStateAvailable) {
  35. self.statusLbl.text = @"Connecting";
  36. } else if (state == ELBluetoothStateUnavailable) {
  37. self.statusLbl.text = @"Bluetooth is disconnected";
  38. }
  39. }
  40. - (void)addLog:(NSString *)log {
  41. self.textView.text = [NSString stringWithFormat:@"%@\n%@", log, self.textView.text];
  42. }
  43. - (void)setupUI {
  44. self.textView = [[UITextView alloc] init];
  45. self.textView.backgroundColor = [UIColor blackColor];
  46. self.textView.text = @"Log";
  47. self.textView.textColor = [UIColor redColor];
  48. [self.view addSubview:self.textView];
  49. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_equalTo(10);
  51. make.right.bottom.mas_equalTo(-10);
  52. make.height.equalTo(self.view).multipliedBy(0.7);
  53. }];
  54. //
  55. self.statusLbl = [[UILabel alloc] init];
  56. self.statusLbl.text = @"Connecting";
  57. self.statusLbl.adjustsFontSizeToFitWidth = YES;
  58. self.statusLbl.font = [UIFont boldSystemFontOfSize:30];
  59. self.statusLbl.textColor = [UIColor redColor];
  60. self.statusLbl.textAlignment = NSTextAlignmentCenter;
  61. [self.view addSubview:self.statusLbl];
  62. [self.statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.height.mas_equalTo(40);
  64. make.left.right.equalTo(self.textView);
  65. make.bottom.equalTo(self.textView.mas_top).mas_offset(-20);
  66. }];
  67. }
  68. - (void)dealloc {
  69. [[ELBroadcastNutritionFoodScaleBleManager shareManager] stopScan];
  70. }
  71. @end