From 2197e837490f5083d18d9fdb97265d1e0f04832a Mon Sep 17 00:00:00 2001 From: 单军华 <WindShan@danjunhuas-MacBook-Pro.local> Date: Fri, 20 Apr 2018 12:01:38 +0800 Subject: [PATCH] no message --- pregnancy_guard/BaseProject/Controller/Home/RadiaDetectionPage.m | 331 +++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 260 insertions(+), 71 deletions(-) diff --git a/pregnancy_guard/BaseProject/Controller/Home/RadiaDetectionPage.m b/pregnancy_guard/BaseProject/Controller/Home/RadiaDetectionPage.m index 0f32fa4..d0cf052 100644 --- a/pregnancy_guard/BaseProject/Controller/Home/RadiaDetectionPage.m +++ b/pregnancy_guard/BaseProject/Controller/Home/RadiaDetectionPage.m @@ -27,7 +27,7 @@ #import <BaiduMapAPI_Location/BMKLocationComponent.h> #import<BaiduMapAPI_Search/BMKPoiSearchType.h> #import "DataModel.h" - +#import "UIImage+animatedGIF.h" @interface RadiaDetectionPage ()<ASValueTrackingSliderDelegate,ASValueTrackingSliderDataSource,cbCharacteristicManagerDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate> { ZZCircleProgress *circle3; @@ -72,14 +72,17 @@ CLLocationDegrees longitude; NSMutableArray * dataModelArr; - NSTimer * myTimer; + NSTimer * myTimer; // ��������������������� NSString * myTimeInterval; NSString * is_open_upload; // 1 ������ 0 ������ + + NSTimer * myScanTimer; // ��������������������� GloriaLabel* _AnquanStatustLabel; UIImageView * icon_anquan; UIImageView * ic_zhishu_bk; UIImageView * ic_weixin_tips; + UIImageView * ic_dianyuan; } @end @@ -197,6 +200,17 @@ } } + +-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error +{ + if (error) + { + [Utilities logDataWithService:[ResourceHandler getServiceNameForUUID:descriptor.characteristic.service.UUID] characteristic:[ResourceHandler getCharacteristicNameForUUID:descriptor.characteristic.UUID] descriptor:[Utilities getDiscriptorNameForUUID:descriptor.UUID] operation:[NSString stringWithFormat:@"%@- %@%@",READ_RESPONSE,READ_ERROR,[error.userInfo objectForKey:NSLocalizedDescriptionKey]]]; + } + +} + + /*! *@Method Notify Read Indicate options result return * ������������������������ @@ -208,71 +222,171 @@ if( receiveHexValue.length == 40 ) { - //16���������10������ - NSString * shishiStr = [receiveHexValue substringWithRange:NSMakeRange(24,4)]; - NSString * leijiStr = [receiveHexValue substringWithRange:NSMakeRange(28,8)]; - - NSString * shishiValue = [NSString stringWithFormat:@"%lu",strtoul([shishiStr UTF8String],0,16)]; - NSString * leijiValue = [NSString stringWithFormat:@"%lu",strtoul([leijiStr UTF8String],0,16)]; - - if( leijiValue.length >= 6) - { - _JiliangNumLabel.text = [NSString stringWithFormat:@"%.1f",[leijiValue floatValue]*0.10]; - } - else - _JiliangNumLabel.text = [NSString stringWithFormat:@"%.3f",[leijiValue floatValue]*0.10]; - - _BiaozhunJiliangNumLabel.text = [NSString stringWithFormat:@"%.3f",([shishiValue floatValue]-45)/10.0*0.10]; - - - //dataModelArr - DataModel * model = [[DataModel alloc]init]; - model.value = _BiaozhunJiliangNumLabel.text; - model.time = [DateUtil stringFromDateYMD:[NSDate date]]; - [dataModelArr addObject:model]; - - circle3.progress = ([leijiValue floatValue]/FUSHE_MAX_VALUE)*100; - [_trackingSlider setValue:circle3.progress]; - [self setGaugeValue:circle3.progress animation:NO]; - + // ������������������ + NSString * baoTouStr = [receiveHexValue substringWithRange:NSMakeRange(0,2)]; + if( [baoTouStr isEqualToString: @"5A"]) + { + //������������������ 0 ������������ 1 ��������� 2������ + NSString * chargeStatusStr = [receiveHexValue substringWithRange:NSMakeRange(6,2)]; + //������������ 4���4������ 3���3������ 2���2������ 1���1������ 0��������������� + NSString * dianLiangStr = [receiveHexValue substringWithRange:NSMakeRange(12,2)]; + // 16���������10������ + NSString * chargeStatusValue = [NSString stringWithFormat:@"%lu",strtoul([chargeStatusStr UTF8String],0,16)]; + NSString * dianLiangValue = [NSString stringWithFormat:@"%lu",strtoul([dianLiangStr UTF8String],0,16)]; + + // ������������������ + [ic_dianyuan setHidden:NO]; + switch ([chargeStatusValue intValue]) { + case 0: + { + NSString * imageName = [NSString stringWithFormat:@"icon_b0%d",[dianLiangValue intValue] ]; + ic_dianyuan.image = [UIImage imageNamed:imageName]; + } + break; + case 1: + [ic_dianyuan setImage:[UIImage animatedImageWithAnimatedGIFURL:[[NSBundle mainBundle] URLForResource:@"icon_chong" withExtension:@"gif"]]]; + break; + case 2: + ic_dianyuan.image = [UIImage imageNamed:@"icon_full"]; + break; + default: + break; + } + + //16���������10������ + NSString * shishiStr = [receiveHexValue substringWithRange:NSMakeRange(24,4)]; + NSString * leijiStr = [receiveHexValue substringWithRange:NSMakeRange(28,8)]; + + + NSString * shishiValue = [NSString stringWithFormat:@"%lu",strtoul([shishiStr UTF8String],0,16)]; + NSString * leijiValue = [NSString stringWithFormat:@"%lu",strtoul([leijiStr UTF8String],0,16)]; + + if( leijiValue.length >= 6) + { + _JiliangNumLabel.text = [NSString stringWithFormat:@"%.1f",[leijiValue floatValue]*0.001]; + } + else + _JiliangNumLabel.text = [NSString stringWithFormat:@"%.3f",[leijiValue floatValue]*0.001]; + + _BiaozhunJiliangNumLabel.text = [NSString stringWithFormat:@"%.3f",[shishiValue floatValue]*0.001]; + + + //dataModelArr + DataModel * model = [[DataModel alloc]init]; + model.value = [_BiaozhunJiliangNumLabel.text floatValue]; + model.time = [DateUtil stringFromDateYMD:[NSDate date]]; + model.type = 0; + model.is_warn = 0; + + if(model.value < 0.16) + { + // 100 + circle3.progress = model.value*100; + _currentShuziTipsLabel.text = @"������������������"; + _currentTipsLabel.textColor = RgbColor(64, 159, 252); + _currentTipsLabel.text = @"������������������������������\n ������������������������������������������������"; + +// _AnquanStatustLabel.text = @"������"; +// _AnquanStatustLabel.textColor = kUIColorFromRGB(0x07cb5a); +// icon_anquan.image = [UIImage imageNamed:@"icon_anquan"]; +// ic_anquan_status.image = [UIImage imageNamed:@"ic_anquan_bk"]; +// ic_weixin_tips.image = [UIImage imageNamed:@"ic_anquan_tips"]; +// ic_zhishu_bk.image = [UIImage imageNamed:@"bt_green"]; +// _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); - if( [shishiValue intValue] < FUSHE_SAFE_VALUE ) - { - _currentShuziTipsLabel.text = @"������������������"; - _currentTipsLabel.textColor = RgbColor(64, 159, 252); - _currentTipsLabel.text = @"������������������������������\n ������������������������������������������������"; + } + else if(model.value >= 0.16 && model.value < 0.8) + { + // 100 + float tempValue = model.value; + if(tempValue > 0.50) + tempValue = 0.50; + + circle3.progress = tempValue*100; + _currentShuziTipsLabel.text = @"���������������������������"; + _currentTipsLabel.textColor = RgbColor(64, 159, 252); + _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; + model.is_warn = 1; + + _AnquanStatustLabel.text = @"������"; + _AnquanStatustLabel.textColor = kUIColorFromRGB(0x0d95fe); + icon_anquan.image = [UIImage imageNamed:@"icon_head_qingwei"]; + ic_anquan_status.image = [UIImage imageNamed:@"bg_corner_blue"]; + ic_weixin_tips.image = [UIImage imageNamed:@"icon_qingwei"]; + ic_zhishu_bk.image = [UIImage imageNamed:@"ic_zhishu_bk"]; + _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); + } + else if(model.value >= 0.8 && model.value < 2) + { + // 264 + float tempValue = (model.value*100)/266; + if(tempValue <= 0.50) + tempValue = 0.51; + + circle3.progress = tempValue*100; + _currentShuziTipsLabel.text = @"���������������������������"; + _currentTipsLabel.textColor = RgbColor(252, 80, 84); + _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; + model.is_warn = 1; + + _AnquanStatustLabel.text = @"������"; + _AnquanStatustLabel.textColor = kUIColorFromRGB(0xc240ff); + icon_anquan.image = [UIImage imageNamed:@"icon_head_zhongfu"]; + ic_anquan_status.image = [UIImage imageNamed:@"bg_corner_zise"]; + ic_weixin_tips.image = [UIImage imageNamed:@"icon_zhongdu"]; + ic_zhishu_bk.image = [UIImage imageNamed:@"bt_zise"]; + _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); + } + else if(model.value >2) + { + // 400 + + float tempValue = (model.value*100)/400; + if(tempValue <= 0.75) + tempValue = 0.76; + + circle3.progress = tempValue*100; + + _currentShuziTipsLabel.text = @"������������������������������"; + _currentTipsLabel.textColor = RgbColor(252, 80, 84); + _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; + model.is_warn = 1; + + _AnquanStatustLabel.text = @"������"; + _AnquanStatustLabel.textColor = kUIColorFromRGB(0xff4e63); + icon_anquan.image = [UIImage imageNamed:@"icon_weixian"]; + ic_anquan_status.image = [UIImage imageNamed:@"ic_weixian_bk"]; + ic_weixin_tips.image = [UIImage imageNamed:@"icon_yanzhong"]; + ic_zhishu_bk.image = [UIImage imageNamed:@"ic_yanzhong_tips"]; + _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); + } + + [_trackingSlider setValue:circle3.progress]; + [self setGaugeValue:circle3.progress animation:NO]; + + [dataModelArr addObject:model]; } - else if ( [shishiValue intValue] < FUSHE_GOOD_VALUE) + } + else if(receiveHexValue.length == 16 ) + { + // ������������������ + NSString * baoTouStr = [receiveHexValue substringWithRange:NSMakeRange(0,2)]; + if( [baoTouStr isEqualToString: @"7A"]) { - _currentShuziTipsLabel.text = @"���������������������������"; - _currentTipsLabel.textColor = RgbColor(64, 159, 252); - _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; + NSString * timeValueStr = [receiveHexValue substringWithRange:NSMakeRange(2,8)]; + //dataModelArr + DataModel * model = [[DataModel alloc]init]; + model.value = [timeValueStr floatValue]; + model.time = [DateUtil stringFromDateYMD:[NSDate date]]; + model.type = 1; + model.is_warn = 0; + + [dataModelArr addObject:model]; } - else if ( [shishiValue intValue] < FUSHE_CHA_VALUE) - { - _currentShuziTipsLabel.text = @"������������������������"; - _currentTipsLabel.textColor = RgbColor(252, 80, 84); - _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; - } - else if ( [shishiValue intValue] < FUSHE_DANGER_VALUE) - { - _currentShuziTipsLabel.text = @"���������������������������"; - _currentTipsLabel.textColor = RgbColor(252, 80, 84); - _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; - } - else if ( [shishiValue intValue] < FUSHE_MAX_VALUE) - { - _currentShuziTipsLabel.text = @"���������������������������"; - _currentTipsLabel.textColor = RgbColor(252, 80, 84); - _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; - } - else - { - _currentShuziTipsLabel.text = @"���������������������������"; - _currentTipsLabel.textColor = RgbColor(252, 80, 84); - _currentTipsLabel.text = @"������������������������������\n ���������������������������������������������������"; - } - + } + else + { + //NSString * shishiStr = [receiveHexValue substringWithRange:NSMakeRange(0,4)]; } //NSString *ASCIIValue = [[NSString alloc]initWithData:characteristic.value encoding:NSASCIIStringEncoding]; @@ -434,6 +548,10 @@ //��������������� if(myTimer) [myTimer setFireDate:[NSDate distantFuture]]; + + //��������������� + if(myScanTimer) + [myScanTimer setFireDate:[NSDate distantFuture]]; } -(void)viewWillAppear:(BOOL)animated @@ -485,15 +603,37 @@ //[[CBMoralManager sharedManager] disconnectPeripheral:[[CBMoralManager sharedManager] myPeripheral]]; [[CBMoralManager sharedManager] setCbDiscoveryDelegate:self]; [[CBMoralManager sharedManager] startScanning]; - [self performSelector:@selector(stopScanning) withObject:nil afterDelay:3.0f]; + [self performSelector:@selector(stopScanning2) withObject:nil afterDelay:3.0f]; } } } +-(void)stopScanning2 +{ + [[CBMoralManager sharedManager]stopScanning]; + + // ������������������������������ + if(_bConnectSuccess == NO) + { + if (myScanTimer == nil) + myScanTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(continueScanning) userInfo:nil repeats:YES]; + else + //��������������� + [myScanTimer setFireDate:[NSDate distantPast]]; + } +} + + -(void)stopScanning { [[CBMoralManager sharedManager]stopScanning]; +} + +-(void)continueScanning +{ + [[CBMoralManager sharedManager] startScanning]; + [self performSelector:@selector(stopScanning) withObject:nil afterDelay:3.0f]; } #pragma mark - BlueTooth Turned Off Delegate @@ -510,7 +650,32 @@ isBluetoothON = state; // ������������������������ - + if(isBluetoothON == NO) + { + [Global alertMessageEx:@"���������������������������������������������!" title:@"������������" okTtitle:nil cancelTitle:@"OK" delegate:self]; + // ������������������������������ + if(_bConnectSuccess == YES) + { + //��������������������������� + if(myTimer) + [myTimer setFireDate:[NSDate distantFuture]]; + + [self offLineSet]; + } + + } + else + { + // ������������������������������ + if(_bConnectSuccess == NO) + { + if (myScanTimer == nil) + myScanTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(continueScanning) userInfo:nil repeats:YES]; + else + //��������������� + [myScanTimer setFireDate:[NSDate distantPast]]; + } + } } @@ -537,6 +702,12 @@ { if(success) { + //��������������� ������������ + if(myScanTimer) + [myScanTimer setFireDate:[NSDate distantFuture]]; + + [self onLineSet]; + deviceStstaus = 1; deviceStatusLabel.text = @"���������"; @@ -702,6 +873,12 @@ ic_anquan_status.image = [UIImage imageNamed:@"ic_anquan_bk"]; [ic_head_bg addSubview:ic_anquan_status]; + ic_dianyuan = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40-ic_anquan_status.frame.size.width/2, 44*scale + 40, 40, 40)]; + //ic_dianyuan.image = [UIImage imageNamed:@"icon_b04"]; + [ic_dianyuan setImage:[UIImage animatedImageWithAnimatedGIFURL:[[NSBundle mainBundle] URLForResource:@"icon_chong" withExtension:@"gif"]]]; + [ic_dianyuan setHidden:YES]; + [self.view addSubview:ic_dianyuan]; + UIImageView * ic_line = [[UIImageView alloc] initWithFrame:CGRectMake(ic_head_bg.frame.size.width/2, 13*scale, 1, 40*scale)]; ic_line.image = [UIImage imageNamed:@"ic_line"]; [ic_head_bg addSubview:ic_line]; @@ -745,7 +922,7 @@ [ic_head_bg addSubview:_BiaozhunJiliangNumLabel]; - UIImageView * icon_anquan = [[UIImageView alloc] initWithFrame:CGRectMake(19*scale, 10*scale, 22*scale, 22*scale)]; + icon_anquan = [[UIImageView alloc] initWithFrame:CGRectMake(19*scale, 10*scale, 22*scale, 22*scale)]; icon_anquan.image = [UIImage imageNamed:@"icon_head_offline"]; [ic_anquan_status addSubview:icon_anquan]; @@ -798,8 +975,8 @@ circle3.reduceValue = 72; circle3.increaseFromLast = YES; circle3.pointImage = [UIImage imageNamed:@"test_point"]; - circle3.progress = ((float)850/FUSHE_MAX_VALUE); - //circle3.progress = 0; + //circle3.progress = ((float)850/FUSHE_MAX_VALUE); + circle3.progress = 0; circle3.showProgressText = NO; circle3.userInteractionEnabled = NO; [ic_zhuanpan_bkBtn addSubview:circle3]; @@ -830,10 +1007,9 @@ { self.navigationController.navigationBar.translucent = NO; } - _locService = [[BMKLocationService alloc]init]; - _locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; - + //_locService = [[BMKLocationService alloc]init]; + //_locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; //[self startLocation]; dataModelArr = [[NSMutableArray alloc] init]; @@ -860,6 +1036,19 @@ _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); } +-(void)onLineSet +{ + deviceStatusLabel.textColor = RgbColor(64, 159, 252); + _AnquanStatustLabel.text = @"������"; + _AnquanStatustLabel.textColor = kUIColorFromRGB(0x07cb5a); + icon_anquan.image = [UIImage imageNamed:@"icon_anquan"]; + ic_anquan_status.image = [UIImage imageNamed:@"ic_anquan_bk"]; + ic_weixin_tips.image = [UIImage imageNamed:@"ic_anquan_tips"]; + ic_zhishu_bk.image = [UIImage imageNamed:@"bt_green"]; + _currentTipsLabel.textColor = kUIColorFromRGB(0x848787); + +} + -(void)connectAction { SearchDevicePage* page = [[SearchDevicePage alloc] initIsFirstPage:NO]; -- Gitblit v1.8.0