// // RunSun84biteCenterViewController.m // Ifish // // Created by imac on 2017/6/2. // Copyright © 2017年 lianlian. All rights reserved. // #import "RunSun84biteCenterViewController.h" #import "RunSun84Protocol.h" #define kPlace ([UIScreen mainScreen].bounds.size.width - btnWid*2) /4 #define RUNSUN_CH1 6000 #define RUNSUN_CH2 6001 #define RUNSUN_CH3 6002 #define RUNSUN_CH4 6003 #define RUNSUN_GUIDENG 6004 #define RUNSUN_JARE 6005 #define btnWid 100 #import "XuToWenDuPicview.h" #import "RuSunLightOrder.h" #import "RuSunGuiDeng.h" #import "RunSun84CHSetViewController.h" #import "RuSun84BackMsgUtils.h" #import "RunSunCHNameCustom.h" #import "RunSunChangeNameViewController.h" #import "RunSunCHControl.h" #import "RuSunInpdViewController.h" #import "HaveHotCoolWenDuPicview.h" @interface RunSun84biteCenterViewController () { dispatch_queue_t _ruSunMainQueue; } @property(nonatomic,strong) RunSun84Protocol *backmodel; @property(nonatomic,strong) HaveHotCoolWenDuPicview *wenduPicview; @property(nonatomic,strong) RunSun84CHSetViewController *rusunHaveHeatSetVC; //@property(nonatomic,strong) RunSunChangeNameViewController *changenameVC; @property(nonatomic,strong) RuSunInpdViewController *changenameVC; @end @implementation RunSun84biteCenterViewController - (void)viewDidLoad { [super viewDidLoad]; _backmodel=[[RunSun84Protocol alloc] init]; [Socketsingleton sharedInstance].communiteDelegate=self; _ruSunMainQueue = dispatch_get_main_queue(); // Do any additional setup after loading the view. UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(RuSunCenterViewSetTap)]; [self.setImag addGestureRecognizer:tapgestureRecognizer]; [self.setbackBtn addTarget:self action:@selector(RuSunCenterViewSetAction:) forControlEvents:UIControlEventTouchUpInside]; [self.SetTimeButton addTarget:self action:@selector(RuSunCenterViewSetAction:) forControlEvents:UIControlEventTouchUpInside]; [self initControlNormalBtn]; } -(void)RuSunCenterViewSetTap { RunSun84Protocol*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"RuSunBackMessage84bite"]; if (backmodel) { [self pushSetTimeVC]; }else{ [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; [self.indicatorView stopAnimating]; } } #pragma mark -转跳设置界面 -(void)RuSunCenterViewSetAction:(UIButton*)btn { RunSun84Protocol*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"RuSunBackMessage84bite"]; if (backmodel) { [self pushSetTimeVC]; }else{ [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; [self.indicatorView stopAnimating]; } } -(void)pushSetTimeVC{ _rusunHaveHeatSetVC=[[RunSun84CHSetViewController alloc]init]; _rusunHaveHeatSetVC.currentdevice=self.currentDevice; [self.navigationController pushViewController:_rusunHaveHeatSetVC animated:YES]; } -(void)initControlNormalBtn { NSArray*nameArr=@[@"PFLight1_off.png",@"PFLight1_off.png",@"PFLight1_off.png",@"PFLight1_off.png",@"PFLight1_off.png",@"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 -(is_iPhone_X?40:20) , 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(controlBtnCilck:) forControlEvents:UIControlEventTouchUpInside]; self.chName = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith),kScreenSize.height - 3*btnControlPlace - 2 *btnControlWith -20 + btnControlWith -5-(is_iPhone_X?20:0) , btnControlWith, btnControlPlace - 5)]; //textLbl.backgroundColor = [UIColor blackColor]; self.chName.textColor = [UIColor colorWithRed:250/255.0f green:255/255.0f blue:255/254.0f alpha:1]; self.chName.textAlignment = NSTextAlignmentCenter; NSArray *arr = @[@"S1",@"S2",@"S3"]; self.chName.text = arr[i]; self.chName.font = [UIFont boldSystemFontOfSize:14]; [self.tableView addSubview:self.chName]; [self.tableView addSubview:self.button]; if (i==0) { self.ch1Button = self.button; self.ch1Name = self.chName; }else if (i==1){ self.ch2Button = self.button; self.ch2Name = self.chName; }else if (i==2){ self.ch3Name = self.chName; self.ch3Button = self.button; } } //CGFloat btnControlPlace1 = (kScreenSize.width - 2*btnControlWith )/3; for (int i = 0; i < 3; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith), kScreenSize.height - 2*btnControlPlace - btnControlWith -(is_iPhone_X?50:30) , btnControlWith, btnControlWith + 11); [self.button setImage:[UIImage imageNamed:nameArr[i+3]]forState:UIControlStateNormal]; self.button.tag= 6003+i; [self.button addTarget:self action:@selector(controlBtnCilck:) forControlEvents:UIControlEventTouchUpInside]; UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith), kScreenSize.height - 2*btnControlPlace - btnControlWith -35 + btnControlWith-(is_iPhone_X?20:0), 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 = @[@"S4",@"USB灯",@"S5"]; textLbl.font = [UIFont boldSystemFontOfSize:14]; textLbl.text = arr[i]; self.chName = textLbl; [self.tableView addSubview:textLbl]; [self.tableView addSubview:self.button]; if (i==0) { self.ch4Button = self.button; self.ch4Name = self.chName; }else if (i==1){ self.guidengButton = self.button; self.guiDengName = self.chName; }else if (i==2){ self.heatBtn = self.button; self.jiaReName = self.chName; } } //重置 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); //(kScreenSize.width - 2 * kPlace - 200)*2/3 self.temperature.frame = CGRectMake(30, 70, (kScreenSize.width - 2 * kPlace - 100)*2/3, 50); 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]; self.hotcolLabe = [[UILabel alloc] init]; self.hotcolLabe.frame = CGRectMake(0, CGRectGetMaxY(self.temperature.frame) + 10, self.bubble.frame.size.width, 15); //self.hotcolLabe.textColor = JWUIColorFromRGB(fc6638); self.hotcolLabe.textAlignment = NSTextAlignmentCenter; self.hotcolLabe.font =[UIFont systemFontOfSize:13]; self.hotcolLabe.text = @"制冷加热"; [self.bubble addSubview:self.hotcolLabe]; self.hotcolTempLabe = [[UILabel alloc] init]; self.hotcolTempLabe.frame = CGRectMake(0, CGRectGetMaxY(self.hotcolLabe.frame) + 5, self.bubble.frame.size.width, 15); self.hotcolTempLabe.font =[UIFont systemFontOfSize:14]; self.hotcolTempLabe.textAlignment = NSTextAlignmentCenter; self.hotcolTempLabe.textColor = JWUIColorFromRGB(0x666666); self.hotcolTempLabe.text = @"温度"; [self.bubble addSubview:self.hotcolTempLabe]; }else{ //kScreenSize.width - 2 * kPlace - 200 self.temperature.frame = CGRectMake(10, 80, kScreenSize.width - 2 * kPlace - 100,70); self.temperature.font = [UIFont fontWithName:@"Avenir Next Condensed" size:60]; 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, 60); 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]; self.hotcolLabe = [[UILabel alloc] init]; self.hotcolLabe.frame = CGRectMake(0, CGRectGetMaxY(self.temperature.frame) + 10, self.bubble.frame.size.width, 15); //self.hotcolLabe.textColor = JWUIColorFromRGB(fc6638); self.hotcolLabe.textAlignment = NSTextAlignmentCenter; self.hotcolLabe.font =[UIFont systemFontOfSize:13]; [self.bubble addSubview:self.hotcolLabe]; self.hotcolTempLabe = [[UILabel alloc] init]; self.hotcolTempLabe.frame = CGRectMake(0, CGRectGetMaxY(self.hotcolLabe.frame) + 5, self.bubble.frame.size.width, 15); self.hotcolTempLabe.font =[UIFont systemFontOfSize:14]; self.hotcolTempLabe.textAlignment = NSTextAlignmentCenter; self.hotcolTempLabe.textColor = JWUIColorFromRGB(0x666666); self.hotcolTempLabe.text = @"温度"; [self.bubble addSubview:self.hotcolTempLabe]; } [self initCHNames]; } #pragma mark - 控制按钮事件 -(void)controlBtnCilck:(UIButton *)btn{ RunSun84Protocol*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"RuSunBackMessage84bite"]; if (backmodel) { }else{ [self.indicatorView stopAnimating]; [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; return; } NSString *lightSate; if (btn.selected) { lightSate=@"00"; btn.selected=NO; }else { lightSate=@"01"; btn.selected=YES; } switch (btn.tag) { case RUNSUN_CH1: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"01" liaghtState:lightSate]; } break; case RUNSUN_CH2: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"02" liaghtState:lightSate]; } break; case RUNSUN_CH3: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"03" liaghtState:lightSate]; } break; case RUNSUN_CH4: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"04" liaghtState:lightSate]; } break; case RUNSUN_GUIDENG: { //此款设备 柜灯在主控制界面 btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; [self sendGuiDengCommend:lightSate]; } break; case RUNSUN_JARE: { if (backmodel) { _wenduPicview=[[HaveHotCoolWenDuPicview 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]; _wenduPicview.wenDuPicviewDelegate = self; NSString *stateStr =nil; if ([backmodel.hotCool isKindOfClass:[NSNull class]]||!backmodel.hotCool) { backmodel.hotCool = @"0000"; } stateStr = [backmodel.hotCool substringWithRange:NSMakeRange(2, 2)]; [_wenduPicview initCateBtnSate:stateStr]; [self ruSunJiaReMianQue]; }else{ [self showLableAction:@"设备已离线"]; } } break; default: break; } } #pragma mark - 发送开关灯指令 -(void)sendOffOnLinghtCommend:(NSString *)linghtNumber liaghtState:(NSString *)state { //此款设备无运行模式 RuSunLightOrder*lightOrder=[[RuSunLightOrder alloc]init]; lightOrder.sendmacId = self.currentDevice.macAddress; lightOrder.resavemacId = self.currentDevice.macAddress; NSString*switchString1=lightOrder.description; lightOrder.switchBtn = state; lightOrder.crc16Str=@"0000"; lightOrder.lightNumber=linghtNumber; NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightOrder.lightNumber,lightOrder.switchBtn,lightOrder.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [ [Socketsingleton sharedInstance] soketWriteData:manulData]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self initHUD]; [self.myhud myhudstart]; } } #pragma mark -发送柜灯指令 -(void)sendGuiDengCommend:(NSString *)lightSate { RuSunGuiDeng*guidengModel=[[RuSunGuiDeng alloc]init]; guidengModel.resavemacId = self.currentDevice.macAddress; guidengModel.sendmacId = self.currentDevice.macAddress; guidengModel.crc16Str=@"0000"; guidengModel.onOff=lightSate; NSString* guidengOrder=[NSString stringWithFormat:@"%@%@%@",guidengModel.description,guidengModel.onOff,guidengModel.crc16Str]; NSData*guidengData=[dataContorl stringToHexData:guidengOrder]; [[Socketsingleton sharedInstance] soketWriteData:guidengData]; if ([Socketsingleton sharedInstance].clientSocket.isConnected) { //soket 未断开时显示 [self initHUD]; [self.myhud myhudstart]; } } #pragma mark -加热制冷温度选择 -(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)ruSunJiaReMianQue { RunSun84Protocol*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"RuSunBackMessage84bite"]; UInt64 mac=[dataContorl hexToTen:backmodel.heatTemperature]; NSLog(@"%llu",mac); 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(_ruSunMainQueue, ^{ for (NSInteger i=0; i