// // RuiMeiViewController.m // Ifish // // Created by Minghao Xue on 2018/4/14. // Copyright © 2018年 lianlian. All rights reserved. // #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_JARE 6004 #define btnWid 100 #import "RuiMeiViewController.h" #import "RuiMeiProtocolModel.h" #import "RuiMeiBackMsgUtils.h" #import "XuToWenDuPicview.h" #import "RuSunLightOrder.h" #import "RuSunGuiDeng.h" #import "RuiMeiSetViewController.h" #import "RuiMeiCHControl.h" #import "RuiMeiCHNameCustom.h" #import "RuiMeiInputViewController.h" #import "HaveHotCoolWenDuPicview.h" @interface RuiMeiViewController () { dispatch_queue_t _ruSunMainQueue; } @property(nonatomic,strong) RuiMeiProtocolModel *backmodel; @property(nonatomic,strong) HaveHotCoolWenDuPicview *wenduPicview; @property(nonatomic,strong) RuiMeiSetViewController *setVC; //@property(nonatomic,strong) RunSunChangeNameViewController *changenameVC; @property(nonatomic,strong) RuiMeiInputViewController *changenameVC; @end @implementation RuiMeiViewController - (void)viewDidLoad { [super viewDidLoad]; _backmodel=[[RuiMeiProtocolModel 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 { RuiMeiProtocolModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:DataCenterRuiMeiModelKey]; if (backmodel) { [self pushSetTimeVC]; }else{ [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; [self.indicatorView stopAnimating]; } } #pragma mark -转跳设置界面 -(void)RuSunCenterViewSetAction:(UIButton*)btn { RuiMeiProtocolModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:DataCenterRuiMeiModelKey]; if (backmodel) { [self pushSetTimeVC]; }else{ [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; [self.indicatorView stopAnimating]; } } -(void)pushSetTimeVC{ self.setVC=[[RuiMeiSetViewController alloc]init]; self.setVC.currentdevice=self.currentDevice; NSString*stateString=[self.backmodel.customModel substringWithRange:NSMakeRange(2, 2)]; if ([stateString isEqualToString:@"01"]) { self.setVC.customModeOn=YES; }else{ self.setVC.customModeOn=NO; } [self.navigationController pushViewController:self.setVC animated:YES]; } -(void)initControlNormalBtn { NSArray*nameArr=@[@"PFLight1_off.png",@"PFLight1_off.png",@"PFkilLlight_off.png",@"O2_off.png",@"JiaReBang"]; 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 - 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(controlBtnCilck:) forControlEvents:UIControlEventTouchUpInside]; self.chName = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith),kScreenSize.height - 3*btnControlPlace - 2 *btnControlWith -20 + btnControlWith -5 , 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 = @[@"灯1",@"灯2",@"UV/杀菌"]; 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 < 2; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith), kScreenSize.height - 2*btnControlPlace - btnControlWith -25 -5 , 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]; if (i == 1) { UILabel *tempLbl = [UILabel new]; [self.button addSubview:tempLbl]; tempLbl.tag = 1; tempLbl.font = [UIFont boldSystemFontOfSize:16]; tempLbl.textColor = [UIColor lightGrayColor]; tempLbl.textAlignment = NSTextAlignmentCenter; tempLbl.translatesAutoresizingMaskIntoConstraints = NO; [NSLayoutConstraint constraintWithItem:tempLbl attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.button attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0].active = YES; [NSLayoutConstraint constraintWithItem:tempLbl attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.button attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:-4.0].active = YES; } UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake(btnControlPlace +i*(btnControlPlace + 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.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.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{ RuiMeiProtocolModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:DataCenterRuiMeiModelKey]; 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:@"PFkilLlight_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"03" liaghtState:lightSate]; } break; case RUNSUN_CH4: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"O2_on.png"] forState:UIControlStateSelected]; [self sendOffOnLinghtCommend:@"04" liaghtState:lightSate]; } break; case RUNSUN_JARE: { if (backmodel) { _wenduPicview=[[HaveHotCoolWenDuPicview alloc] init]; _wenduPicview.cateSwich.hidden = YES; _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.heatStickState isKindOfClass:[NSNull class]]||!backmodel.heatStickState) { backmodel.heatStickState = @"00"; } stateStr = [backmodel.heatStickState substringWithRange:NSMakeRange(0, 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 { RuiMeiProtocolModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:DataCenterRuiMeiModelKey]; 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