1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // HomeViewController.m
- // iFreshDemo
- //
- // Created by steven wu on 2021/6/23.
- // Copyright © 2021 taolei. All rights reserved.
- //
-
- #import "HomeViewController.h"
- #import "SearchDeviceVC.h"
- #import <iFreshSDK/iFreshSDK.h>
-
- @interface HomeViewController ()<BleReturnValueDelegate>
-
- @property (weak, nonatomic) IBOutlet UIButton *topButton;
- @property (weak, nonatomic) IBOutlet UILabel *weightLabel;
-
- @property (nonatomic, strong) iFreshDevice *connDevice;
-
- @end
-
- @implementation HomeViewController
-
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- }
-
-
- - (IBAction)topButtonClick:(id)sender {
- SearchDeviceVC *vc = [[SearchDeviceVC alloc] init];
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- __weak typeof(self) weakSelf = self;
- vc.didSelectDeviceBlock = ^(iFreshDevice *device) {
- weakSelf.connDevice = device;
- [weakSelf.topButton setTitle:device.mac forState:(UIControlStateNormal)];
- //begin to connect device
- [weakSelf startToConnect];
- };
- [self presentViewController:vc animated:YES completion:nil];
- }
-
- - (void)startToConnect {
- [[iFreshSDK shareManager] setbleReturnValueDelegate:self];
- [[iFreshSDK shareManager] connectDevice:self.connDevice];
- }
-
-
- - (IBAction)changeUnitAction:(UIButton *)sender {
- NSArray *unitArr = @[
- @(UNIT_g),@(UNIT_ml),@(UNIT_lb),@(UNIT_oz),@(UNIT_kg),@(UNIT_jin),@(UNIT_LB)
- ];
-
- GN_UnitEnum unit = [unitArr[arc4random_uniform(unitArr.count)] intValue];
- [[iFreshSDK shareManager] insertTheUnit:unit];
- }
-
-
-
-
- /**
- * Model model: value ble returns the value (model模型:value ble返还数值)
- *
- * @param model Global Bluetooth model data(全局蓝牙模型数据)
- */
- - (void)bleReturnValueModel:(iFreshModel*)model {
- self.weightLabel.text = model.value;
- NSLog(@"model.gValue = %ld",(long)model.gValue);//gValue为以“g”为单位的数据
- NSLog(@"value == %@",model.value);
- }
-
- /**
- * Proxy method triggered by end switching unit(称端切换单位触发的代理方法)
- * GN_UnitEnum Unit enumeration(单位枚举)
- * unitChang Switched unit(切换后的单位)
- */
- - (void)changeUnitWithBle:(GN_UnitEnum)unitChange{
- NSLog(@"unitChange == %ld",unitChange);
- }
-
- /**
- * Proxy method for changing Bluetooth connection status(蓝牙连接状态改变的代理方法)
- * GN_BleStatus Bluetooth status enumeration(蓝牙状态枚举)
- * bleStatus Current Bluetooth status(当前蓝牙状态)
- */
- - (void)bleStatusupdate:(GN_BleStatus)bleStatus{
- if ( bleStatus == bleOpen || bleStatus == bleBreak) {
- NSLog(@"蓝牙未连接");
- }else if (bleStatus == bleOff){
- NSLog(@"蓝牙未打开");
- }else if (bleStatus == bleConnect){
- NSLog(@"蓝牙已连接");
- }
- }
-
-
-
- @end
|