123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // ELDemoScanVC.m
- // AILinkBleSDK_Example
- //
- // Created by LarryZhang on 2022/12/12.
- // Copyright © 2022 zhengzida. All rights reserved.
- //
-
- #import "ELDemoScanVC.h"
- #import "ELDeviceScanCell.h"
- #import "ELDemoDeviceModel.h"
- #import <AICareComponentRingBleSDK/ELSmartRingManager.h>
- #import <AICareComponentRingBleSDK/NELBleManagerHeader.h>
-
-
- @interface ELDemoScanVC () <UITableViewDelegate, UITableViewDataSource,ELSmartRingManagerDelegate>
-
- @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel;
-
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
-
- @property (nonatomic, strong) ELSmartRingManager *smartRingManager;
-
-
-
- @property (nonatomic, strong) NSMutableArray<ELAILinkPeripheral *> *peripheralArray;
-
- @end
-
- @implementation ELDemoScanVC
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- self.bleStatusLabel.text = @"";
- [self initBle];
- }
-
- - (void)dealloc {
- [self deinitBle];
- }
-
- - (IBAction)closeAction:(id)sender {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
-
- #pragma mark - UITableViewDelegate, UITableViewDataSource
-
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
-
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.peripheralArray.count;
- }
-
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 88;
- }
-
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- ELDeviceScanCell *cell = [ELDeviceScanCell subsribeCell];
-
- ELAILinkPeripheral *per = self.peripheralArray[indexPath.row];
-
- cell.iconImageView.image = [UIImage imageNamed:self.demoDeviceModel.imageName];
- cell.cidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.cid];
- cell.vidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.vid];
- cell.pidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.pid];
- cell.macValueLabel.text = per.macAddressString;
- cell.rssiValueLabel.text = [NSString stringWithFormat:@"%@", per.RSSI];
-
- return cell;
-
- }
-
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- ELAILinkPeripheral *per = self.peripheralArray[indexPath.row];
-
- if (self.selectedBlock) {
- self.selectedBlock(per);
- }
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }
-
- #pragma mark - ELAILinkBleManagerDelegate
-
- - (void)initBle {
- [ELSmartRingManager sharedManager].delegate = self;
- [self scanBle];
- // self.bleManager = [[ELAILinkBleManager alloc] init];
- // self.bleManager.ailinkDelegate = self;
- }
-
- - (void)scanBle {
- self.peripheralArray = [NSMutableArray array];
- [[ELSmartRingManager sharedManager] scanFilterWithCidArray:self.cids];
- }
-
- - (void)deinitBle {
- }
-
- -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidUpdateState:(CBCentralManager *)central
- {
- NSLog(@"%s state:%@", __func__, @(central.state));
- if (central.state == CBManagerStatePoweredOn) {
- [self scanBle];
- } else if (central.state == CBManagerStatePoweredOff) {
- }
- }
-
- -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidDiscoverPeripheral:(ELAILinkPeripheral *)peripheral
- {
- NSLog(@"managerDidDiscoverPeripheral cid:%02x vid:%02x pid:%02x mac:%@", peripheral.cid, peripheral.vid, peripheral.pid, peripheral.macAddressString);
- for (int i=0; i<self.peripheralArray.count; i++) {
- ELAILinkPeripheral *per = self.peripheralArray[i];
- if ([per.macData isEqualToData:peripheral.macData]) {
- self.peripheralArray[i] = per;
- [self.tableView reloadData];
- return;
- }
- }
- [self.peripheralArray addObject:peripheral];
- [self.peripheralArray sortUsingComparator:^NSComparisonResult(ELAILinkPeripheral * _Nonnull obj1, ELAILinkPeripheral * _Nonnull obj2) {
- if (obj1.RSSI.integerValue < obj2.RSSI.integerValue) return NSOrderedDescending;
- else if (obj1.RSSI.integerValue > obj2.RSSI.integerValue) return NSOrderedAscending;
- return NSOrderedSame;
- }];
- [self.tableView reloadData];
- }
- -(void)smartRingManager:(ELSmartRingManager *)smartRingManager ConnectState:(NELBleManagerConnectState)bleConnectState
- {
-
- }
-
-
-
- @end
|