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.

HomeViewController.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // HomeViewController.m
  3. // iFreshDemo
  4. //
  5. // Created by steven wu on 2021/6/23.
  6. // Copyright © 2021 taolei. All rights reserved.
  7. //
  8. #import "HomeViewController.h"
  9. #import "SearchDeviceVC.h"
  10. #import <iFreshSDK/iFreshSDK.h>
  11. @interface HomeViewController ()<BleReturnValueDelegate>
  12. @property (weak, nonatomic) IBOutlet UIButton *topButton;
  13. @property (weak, nonatomic) IBOutlet UILabel *weightLabel;
  14. @property (nonatomic, strong) iFreshDevice *connDevice;
  15. @end
  16. @implementation HomeViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. }
  20. - (IBAction)topButtonClick:(id)sender {
  21. SearchDeviceVC *vc = [[SearchDeviceVC alloc] init];
  22. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  23. __weak typeof(self) weakSelf = self;
  24. vc.didSelectDeviceBlock = ^(iFreshDevice *device) {
  25. weakSelf.connDevice = device;
  26. [weakSelf.topButton setTitle:device.mac forState:(UIControlStateNormal)];
  27. //begin to connect device
  28. [weakSelf startToConnect];
  29. };
  30. [self presentViewController:vc animated:YES completion:nil];
  31. }
  32. - (void)startToConnect {
  33. [[iFreshSDK shareManager] setbleReturnValueDelegate:self];
  34. [[iFreshSDK shareManager] connectDevice:self.connDevice];
  35. }
  36. - (IBAction)changeUnitAction:(UIButton *)sender {
  37. NSArray *unitArr = @[
  38. @(UNIT_g),@(UNIT_ml),@(UNIT_lb),@(UNIT_oz),@(UNIT_kg),@(UNIT_jin),@(UNIT_LB)
  39. ];
  40. GN_UnitEnum unit = [unitArr[arc4random_uniform(unitArr.count)] intValue];
  41. [[iFreshSDK shareManager] insertTheUnit:unit];
  42. }
  43. /**
  44. * Model model: value ble returns the value (model模型:value ble返还数值)
  45. *
  46. * @param model Global Bluetooth model data(全局蓝牙模型数据)
  47. */
  48. - (void)bleReturnValueModel:(iFreshModel*)model {
  49. self.weightLabel.text = model.value;
  50. NSLog(@"model.gValue = %ld",(long)model.gValue);//gValue为以“g”为单位的数据
  51. NSLog(@"value == %@",model.value);
  52. }
  53. /**
  54. * Proxy method triggered by end switching unit(称端切换单位触发的代理方法)
  55. * GN_UnitEnum Unit enumeration(单位枚举)
  56. * unitChang Switched unit(切换后的单位)
  57. */
  58. - (void)changeUnitWithBle:(GN_UnitEnum)unitChange{
  59. NSLog(@"unitChange == %ld",unitChange);
  60. }
  61. /**
  62. * Proxy method for changing Bluetooth connection status(蓝牙连接状态改变的代理方法)
  63. * GN_BleStatus Bluetooth status enumeration(蓝牙状态枚举)
  64. * bleStatus Current Bluetooth status(当前蓝牙状态)
  65. */
  66. - (void)bleStatusupdate:(GN_BleStatus)bleStatus{
  67. if ( bleStatus == bleOpen || bleStatus == bleBreak) {
  68. NSLog(@"蓝牙未连接");
  69. }else if (bleStatus == bleOff){
  70. NSLog(@"蓝牙未打开");
  71. }else if (bleStatus == bleConnect){
  72. NSLog(@"蓝牙已连接");
  73. }
  74. }
  75. @end