| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 | //
//  ViewController.m
//  AILinkBleSDKSourceCode
//
//  Created by iot_user on 2020/4/7.
//  Copyright © 2020 IOT. All rights reserved.
//
#import "ViewController.h"
#import "Masonry.h"
#import <AILinkBleSDK/ELAILinkBleManager.h>
#import <AILinkBleSDK/ELBluetoothManager.h>
#import "ELDemoDeviceModel.h"
#import "ELDeviceTypeCell.h"
#import "ELDemoScanVC.h"
#import "AiLinkSuperViewController.h"
#import "InheritScanViewController.h"
#import "BabyScaleViewController.h"
#import "BloodScanViewController.h"
#import "HeightGuageScanViewController.h"
#import "RemoteControlScanViewController.h"
#import "ForeheadScanViewController.h"
#import "ThermometerScanViewController.h"
#import "WheelMonitorScanViewController.h"
#import "BodyFatScaleScanViewController.h"
#import "BroadcastScaleViewController.h"
#import "EightScaleScanViewController.h"
#import "ToothbrushScanViewController.h"
#import "ELBfsWifiScanVC.h"
#import "OximeterScanViewController.h"
#import "BloodSugarScanViewController.h"
#import "CoffeeScaleScanViewController.h"
#import "FoodThermometerScanViewController.h"
#import "BroadcastNutritionScaleViewController.h"
#import "NutritionScaleScanViewController.h"
#import "AiFreshNutritionScaleScanViewController.h"
#import "FaceMaskScanViewController.h"
#import "SkipScanViewController.h"
#import "HeightBodyFatScaleVC.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray<ELDemoDeviceModel *> *deviceArray;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = [NSString stringWithFormat:@"%@(v%@)", [self.class appName],[ self.class appVersion]];
    
    self.deviceArray = @[
        
        [ELDemoDeviceModel modelWithIndex:@"-" imageName:@"ailink_connected_ic" title:@"Parse data yourself" subtitle:@"有AILink协议自己解析数据" entryVCName:NSStringFromClass(InheritScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"04" imageName:@"type_baby_scale_ic" title:@"Baby Scale" subtitle:@"婴儿秤" entryVCName:NSStringFromClass(BabyScaleViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"05" imageName:@"type_sphygmomanometer_ic" title:@"Sphygmomanometer" subtitle:@"血压计" entryVCName:NSStringFromClass(BloodScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"06" imageName:@"type_height_measuring_instrument" title:@"Height Guage" subtitle:@"身高仪" entryVCName:NSStringFromClass(HeightGuageScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"07" imageName:@"type_control_vision_ic" title:@"Remote Control" subtitle:@"遥控器" entryVCName:NSStringFromClass(RemoteControlScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"08" imageName:@"type_temperature_gun_ic" title:@"Forehead thermometer" subtitle:@"额温枪" entryVCName:NSStringFromClass(ForeheadScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"09" imageName:@"type_thermometer_ic" title:@"Digital thermometer" subtitle:@"温度计" entryVCName:NSStringFromClass(ThermometerScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"10" imageName:@"type_tpms_ic" title:@"TPMS" subtitle:@"胎压监测" entryVCName:NSStringFromClass(WheelMonitorScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"11" imageName:@"type_body_fat_ic" title:@"Bluetooth BodyfatScale" subtitle:@"体脂秤" entryVCName:NSStringFromClass(BodyFatScaleScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"12" imageName:@"type_body_fat_ic" title:@"Bluetooth BroadcastScale" subtitle:@"广播秤" entryVCName:NSStringFromClass(BroadcastScaleViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"13" imageName:@"8_electrode_measurement_type" title:@"Eight-electrode scale" subtitle:@"八电极体脂秤" entryVCName:NSStringFromClass(EightScaleScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"14" imageName:@"type_brush" title:@"wifi-ble toothbrush" subtitle:@"WiFi-ble牙刷" entryVCName:NSStringFromClass(ToothbrushScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"15" imageName:@"type_body_fat_ic" title:@"wifi-ble bodyfatScale" subtitle:@"WiFi-ble体脂秤" entryVCName:NSStringFromClass(ELBfsWifiScanVC.class)],
        [ELDemoDeviceModel modelWithIndex:@"16" imageName:@"oximeter_search_icon1" title:@"Bluetooth Oximeter" subtitle:@"血氧仪" entryVCName:NSStringFromClass(OximeterScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"17" imageName:@"type_blood_sugar" title:@"Bluetooth BloodGlucoseMeter" subtitle:@"血糖仪" entryVCName:NSStringFromClass(BloodSugarScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"18" imageName:@"type_coffee_scale_ic" title:@"CoffeeScale" subtitle:@"咖啡秤" entryVCName:NSStringFromClass(CoffeeScaleScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"19" imageName:@"foodtem_icon_100" title:@"FoodThermometer" subtitle:@"食物温度计" entryVCName:NSStringFromClass(FoodThermometerScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"20" imageName:@"ailink_nutrition_scale_scale_connect" title:@"BrodcastNutritionScale" subtitle:@"广播营养秤" entryVCName:NSStringFromClass(BroadcastNutritionScaleViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"21" imageName:@"ailink_nutrition_scale_scale_connect" title:@"NutritionScale" subtitle:@"连接营养秤" entryVCName:NSStringFromClass(NutritionScaleScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"22" imageName:@"ailink_nutrition_scale_scale_connect" title:@"AiFreshNutritionScale" subtitle:@"好营养营养秤" entryVCName:NSStringFromClass(AiFreshNutritionScaleScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"23" imageName:@"type_smart_mask" title:@"FaceMask" subtitle:@"智能口罩" entryVCName:NSStringFromClass(FaceMaskScanViewController.class)],
        [ELDemoDeviceModel modelWithIndex:@"24" imageName:@"ailink_smart_skip_rope_device_ic" title:@"SkippingRope" subtitle:@"跳绳" entryVCName:NSStringFromClass(SkipScanViewController.class)],
        
        [ELDemoDeviceModel modelWithIndex:@"25" imageName:@"height_body_fat_scale_type_ic" title:@"HeightBodyFatScale" subtitle:@"身高体脂秤" entryVCName:NSStringFromClass(HeightBodyFatScaleVC.class) cids:@[@(ELSupportDeviceTypeHeightBodyFatScale)]],
        
    ];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(8);
        make.right.bottom.mas_equalTo(-8);
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.deviceArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 88;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ELDemoDeviceModel *model = self.deviceArray[indexPath.row];
    
    ELDeviceTypeCell *cell = [ELDeviceTypeCell subsribeCell:tableView];
    cell.indexLabel.text = model.index;
    cell.titleLabel.text = model.titleText;
    cell.subtitleLabel.text = model.subtitleText;
    cell.iconImageView.image = [UIImage imageNamed:model.imageName];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ELDemoDeviceModel *device = self.deviceArray[indexPath.row];
    if (device.newType) {
        ELDemoScanVC *vc = [[ELDemoScanVC alloc] init];
        vc.cids = @[@(ELSupportDeviceTypeHeightBodyFatScale)];
        [self.navigationController presentViewController:vc animated:YES completion:^{
            NSLog(@"");
        }];
        
        __weak typeof(self) weakSelf = self;
        vc.selectedBlock = ^(ELAILinkPeripheral * _Nonnull per) {
            UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init];
            vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText];
            [vc setValue:per forKey:@"per"];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        };
    } else {
        UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init];
        vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
+ (NSString *)appName {
    NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
    NSString *appName = [dic objectForKey:@"CFBundleDisplayName"];
    return appName;
}
+ (NSString *)appVersion {
    NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
    NSString * version = [dic objectForKey:@"CFBundleShortVersionString"];
    return version;
}
@end
 |