// // KeLiAiCenterViewController.m // Ifish // // Created by imac on 16/5/17. // Copyright © 2016年 imac. All rights reserved. // #import "KeLiAiCenterViewController.h" #import "KeLiAiBackMassage.h" #import "KeLiAiBackmassageDataUnity.h" #import "KeLiAiSetViewController.h" #import "KeLiAiLightModel.h" #define KELIAI_ZIWAI 6000 #define KELIAI_LIGHT1 6001 #define KELIAI_LIGHT2 6002 #define KELIAI_PUMP 6003 #define KELIAI_JARE 6004 #define kPlace ([UIScreen mainScreen].bounds.size.width - btnWid*2) /4 #define btnWid 100 #import "XuToWenDuPicview.h" /** * 四控六定时器 */ @interface KeLiAiCenterViewController () { dispatch_queue_t _keLiAiMainQueue; } @property(nonatomic,strong) KeLiAiSetViewController *keLiaAiSetVC; @property(nonatomic,strong) KeLiAiBackMassage * keLiAiBackModel; @property(nonatomic,strong) XuToWenDuPicview *wenduPicview; @end @implementation KeLiAiCenterViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _keLiAiBackModel=[[KeLiAiBackMassage alloc] init]; [Socketsingleton sharedInstance].communiteDelegate=self; _keLiAiMainQueue = dispatch_get_main_queue(); [self initKeLiAiUI]; [self creatFishAnimation]; [self.setbackBtn addTarget:self action:@selector(KeLiAiSetBtnAction:) forControlEvents:UIControlEventTouchUpInside]; UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keLiSetBtnAction:)]; [self.setImag addGestureRecognizer:tapgestureRecognizer]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)KeLiAiSetBtnAction:(UIButton *)btn{ KeLiAiBackMassage*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"KeLiAiBackInfo"]; if (self.binddeviceArr.count ==0) { [self.view makeToast:@"暂未绑定设备"]; }else{ if (backmodel) { [self pushFourSetvc]; }else{ [self.indicatorView stopAnimating]; [self showLableAction:@"设备已离线"]; //[self.XuTohud hidmyHud]; } } } #pragma mark - 设置图片点击事件 -(void)keLiSetBtnAction:(UIGestureRecognizer *)sender{ NSLog(@"keliai*******keLiSetBtnAction"); if (self.binddeviceArr.count ==0) { [self.view makeToast:@"暂未绑定设备"]; }else{ // BackmassegeModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"FourControlMassgeInfo"]; // if (backmodel) { [self pushFourSetvc]; // }else{ // [self showLableAction:@"设备已离线"]; // [self deviceNotOnlineState]; // [self.indicatorView stopAnimating]; // } } } -(void)pushFourSetvc{ _keLiaAiSetVC=[[KeLiAiSetViewController alloc]init]; _keLiaAiSetVC.currentdevice=self.currentDevice; [self.navigationController pushViewController:_keLiaAiSetVC animated:YES]; //self.navigationBarHidden=NO; } -(void)creatFishAnimation{ NSLog(@"keliai*******"); } #pragma mark-初始化按钮 -(void)initKeLiAiUI{ NSArray *nameArr=@[ @"PFkilLlight_off",@"PFLight1_off",@"PFLight1_off",@"ChongLang_off",@"JiaReBang_off"]; CGFloat btnControlWith = 70; CGFloat btnControlPlace = (kScreenSize.width - 3*btnControlWith )/4; for (int i = 0; i < 3; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith),kScreenSize.height - 3*btnControlPlace - 2 *btnControlWith -10 , btnControlWith, btnControlWith +11); [self.button setImage:[UIImage imageNamed:nameArr[i]] forState:UIControlStateNormal]; //self.button.backgroundColor = [UIColor redColor]; self.button.tag=6000+i; [self.button addTarget:self action:@selector(keLiAiBtnClick:) forControlEvents:UIControlEventTouchUpInside]; UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith),kScreenSize.height - 3*btnControlPlace - 2 *btnControlWith -20 + btnControlWith , btnControlWith, btnControlPlace - 5)]; //textLbl.backgroundColor = [UIColor blackColor]; textLbl.textColor = [UIColor colorWithRed:250/255.0f green:255/255.0f blue:255/254.0f alpha:1]; textLbl.textAlignment = NSTextAlignmentCenter; NSArray *arr = @[@"紫外线",@"灯1",@"灯2"]; textLbl.text = arr[i]; textLbl.font = [UIFont boldSystemFontOfSize:14]; [self.tableView addSubview:textLbl]; [self.tableView addSubview:self.button]; if (i==0) { self.keliaUltravioletBtn = self.button; }else if (i==1){ self.keliaLight1Btn = self.button; }else if (i==2){ self.keliaLight2Btn = self.button; } } CGFloat btnControlPlace1 = (kScreenSize.width - 2*btnControlWith )/3; for (int i = 0; i < 2; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace1 +i*(btnControlPlace1 + btnControlWith), kScreenSize.height - 2*btnControlPlace - btnControlWith -25 , btnControlWith, btnControlWith + 11); [self.button setImage:[UIImage imageNamed:nameArr[i+3]]forState:UIControlStateNormal]; //self.button.backgroundColor = [UIColor blueColor]; self.button.tag= 6003+i; [self.button addTarget:self action:@selector(keLiAiBtnClick:) forControlEvents:UIControlEventTouchUpInside]; UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace1 +i*(btnControlPlace1 + btnControlWith), kScreenSize.height - 2*btnControlPlace - btnControlWith -35 + btnControlWith, btnControlWith, btnControlPlace - 5)]; //textLbl.backgroundColor = [UIColor blackColor]; textLbl.textAlignment = NSTextAlignmentCenter; textLbl.textColor = [UIColor colorWithRed:250/255.0f green:255/255.0f blue:255/254.0f alpha:1]; NSArray *arr = @[@"水泵",@"加热棒"]; textLbl.font = [UIFont boldSystemFontOfSize:14]; textLbl.text = arr[i]; [self.tableView addSubview:textLbl]; [self.tableView addSubview:self.button]; if (i==0) { self.keliaPumpBtn = self.button; }else if (i==1){ self.keliaJaReBtn = self.button; } } //重置 self.bubble 的 frame CGFloat animViewHeight= kScreenSize.width/4; if (kScreenSize.height==480) { self.bubble.frame = CGRectMake((kScreenSize.width -(kScreenSize.width - 2 * kPlace)*2/3)/2, kPlace + 60 , (kScreenSize.width - 2 * kPlace)*2/3, (kScreenSize.width - 2 * kPlace)*2/3); self.temperature.frame = CGRectMake(30, 70, (kScreenSize.width - 2 * kPlace - 100)*2/3, (kScreenSize.width - 2 * kPlace - 200)*2/3); self.temperature.font = [UIFont fontWithName:@"Avenir Next Condensed" size:46]; self.dulabel.frame = CGRectMake( (kScreenSize.width - 2 * kPlace - 100)*2/3,74,50, kScreenSize.width - 2 * kPlace - 210); self.dulabel.font = [UIFont fontWithName:@"Avenir Next Condensed" size:20]; self.animView.frame= CGRectMake(0, kPlace + 80 + (kScreenSize.width - 2 * kPlace) -animViewHeight/2 - 15-80, kScreenSize.width, animViewHeight); self.notOnLineLabel.frame = CGRectMake(40, 60, kScreenSize.width - 2 * kPlace - 100, kScreenSize.width - 2 * kPlace - 200); self.notOnLineLabel .font = [UIFont fontWithName:@"Avenir Next Condensed" size:15]; }else{ self.temperature.frame = CGRectMake(10, 80, kScreenSize.width - 2 * kPlace - 100, kScreenSize.width - 2 * kPlace - 200); self.temperature.font = [UIFont fontWithName:@"Avenir Next Condensed" size:70]; self.bubble.frame = CGRectMake((kScreenSize.width -(kScreenSize.width - 3 * kPlace ))/2, kPlace + 80 , kScreenSize.width - 3 * kPlace, kScreenSize.width - 3 * kPlace); self.dulabel.frame = CGRectMake((kScreenSize.width - 2 * kPlace)/3*2 -30 , 90 ,50, kScreenSize.width - 2 * kPlace - 210); self.dulabel.font = [UIFont fontWithName:@"Avenir Next Condensed" size:40]; self.animView.frame= CGRectMake(0, kPlace + 40 + (kScreenSize.width - 2 * kPlace) -animViewHeight/2 - 15, kScreenSize.width, animViewHeight); CGFloat bubH=kScreenSize.width - 3 * kPlace; self.notOnLineLabel.frame = CGRectMake(0,bubH/2-15, bubH, 30); self.notOnLineLabel .font = [UIFont fontWithName:@"Avenir Next Condensed" size:20]; } } #pragma mark -按钮点击事件 -(void)keLiAiBtnClick:(UIButton*)btn{ KeLiAiBackMassage*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"KeLiAiBackInfo"]; if (backmodel) { }else{ [self showLableAction:@"设备已离线"]; } KeLiAiLightModel * lightModel=[[KeLiAiLightModel alloc] init]; lightModel.sendmacId =self.currentDevice.macAddress; lightModel.resavemacId = self.currentDevice.macAddress; NSString*switchString1=lightModel.description; if (btn.selected) {//开 lightModel.switchBtn=@"00"; btn.selected=NO; }else {// 关 lightModel.switchBtn=@"01"; btn.selected=YES; } lightModel.crc16Str=@"0000";// CRC16验证码 switch (btn.tag) { case KELIAI_ZIWAI: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFkilLlight_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber =@"03"; NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightModel.lightNumber,lightModel.switchBtn,lightModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [[Socketsingleton sharedInstance] soketWriteData:manulData]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self creatkeliindicaterView]; [self.myhud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case KELIAI_LIGHT1: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber =@"01";// 01 --灯1 NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightModel.lightNumber,lightModel.switchBtn,lightModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [ [Socketsingleton sharedInstance].clientSocket writeData:manulData withTimeout:-1 tag:0]; [[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self creatkeliindicaterView]; [self.myhud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case KELIAI_LIGHT2: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber=@"02";// NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightModel.lightNumber,lightModel.switchBtn,lightModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [[Socketsingleton sharedInstance] soketWriteData:manulData]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self creatkeliindicaterView]; [self.myhud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case KELIAI_PUMP: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"ChongLang_on.png"] forState:UIControlStateNormal]; lightModel.lightNumber=@"04";// NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightModel.lightNumber,lightModel.switchBtn,lightModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [[Socketsingleton sharedInstance] soketWriteData:manulData]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self creatkeliindicaterView]; [self.myhud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case KELIAI_JARE: { if (backmodel) { _wenduPicview=[[XuToWenDuPicview alloc] init]; _wenduPicview.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); [_wenduPicview.sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view.window addSubview:_wenduPicview]; [self keLiAiJiaReMianQue]; }else{ [self showLableAction:@"设备已离线"]; } } default: break; } } //加热温度选择 -(void)sureBtnClick:(UIButton *)btn{ NSLog(@"%@******** _wenduPicview.picViewResultString",_wenduPicview.picViewResultString); if (_wenduPicview.picViewResultString ==nil) { [_wenduPicview removeFromSuperview]; }else{ JiaReWenDuModel *model=[[JiaReWenDuModel alloc] init]; model.resavemacId = self.currentDevice.macAddress; model.sendmacId = self.currentDevice.macAddress; int intlowString = [_wenduPicview.picViewResultString intValue]; int newIntlowString=intlowString*10; NSLog(@"%d******** newIntlowString",newIntlowString); // 转四位16进制 model.JiaReWenDu=[dataContorl tpIntStringToFourHex:newIntlowString]; model.crc16Code =@"0000"; NSString * hexstring=[NSString stringWithFormat:@"%@%@%@",model.description,model.JiaReWenDu,model.crc16Code]; NSData*data=[dataContorl stringToHexData:hexstring]; [ [Socketsingleton sharedInstance] soketWriteData:data]; } [_wenduPicview removeFromSuperview]; } -(void)keLiAiJiaReMianQue{ KeLiAiBackMassage*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"KeLiAiBackInfo"]; UInt64 mac=[dataContorl hexToTen:backmodel.heatTemperature]; NSLog(@"%llu",mac); //float TPlabel=mac/10+(mac%10)*0.1; float TPlabel=mac/10; int temp= (int)(TPlabel+0.5); NSString *stringFloat = [NSString stringWithFormat:@"%d",temp]; NSLog(@"%@",stringFloat); NSArray*wenDuArr=[_wenduPicview.picArr objectAtIndex:0]; dispatch_async(_keLiAiMainQueue, ^{ for (NSInteger i=0; i