// // SonNuoCenterViewController.m // Ifish // // Created by imac on 16/6/6. // Copyright © 2016年 imac. All rights reserved. // #import "SonNuoCenterViewController.h" #import "SongNuoBackMassage.h" #import "SongNuoSetViewController.h" #define SONGNUO_LIGHT1 600000 #define SONGNUO_LIGHT2 600001 #define SONGNUO_WATERPUMP 600002 #define SONGNUO_AIRPUMP 600003 #define SONGNUO_UV 600004 #define SONGNUO_WAVE 600005 #define SONGNUO_BEI 600006 #define SONGNUO_JIARE 600007 #define kPlace ([UIScreen mainScreen].bounds.size.width - btnWid*2) /4 #define btnWid 100 #import "XuToWenDuPicview.h" #import "JiaReWenDuModel.h" #import "SongNuoBackMsgDataUnity.h" #import "SonNuo128NameViewController.h" #import "SongNuo128Name.h" #import "UserExtendataArchaver.h" @interface SonNuoCenterViewController () { dispatch_queue_t _songNuoMainQueue; } @property(nonatomic,strong) SongNuoSetViewController *songNuoSetVC; @property(nonatomic,strong) SongNuoBackMassage * songNuoBackModel; @property(nonatomic,strong) MyHud *SongNuoHud; @property(nonatomic,strong) XuToWenDuPicview *wenduPicview; @property(nonatomic,strong) SonNuo128NameViewController *changeNameVC; @end @implementation SonNuoCenterViewController - (void)viewDidLoad { [super viewDidLoad]; _songNuoBackModel=[[SongNuoBackMassage alloc] init]; [Socketsingleton sharedInstance].communiteDelegate=self; // Do any additional setup after loading the view. _songNuoMainQueue = dispatch_get_main_queue(); [self initSongNuoUI]; [self creatFishAnimation]; [self.setbackBtn addTarget:self action:@selector(SongNuoSetBtnAction) forControlEvents:UIControlEventTouchUpInside]; UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(songSetBtnAction:)]; [self.setImag addGestureRecognizer:tapgestureRecognizer]; } #pragma mark- 设置 -(void)SongNuoSetBtnAction{ SongNuoBackMassage *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoBackMassage"]; if (self.binddeviceArr.count ==0) { [self.view makeToast:@"暂未绑定设备"]; }else{ if (backmodel) { [self pushSetTimeVC]; }else{ [self.indicatorView stopAnimating]; [self showLableAction:@"设备已离线"]; //[self.XuTohud hidmyHud]; } } NSLog(@"点击绚多的设置按钮"); } -(void)songSetBtnAction:(UIGestureRecognizer *)sender{ SongNuoBackMassage *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoBackMassage"]; if (self.binddeviceArr.count ==0) { [self.view makeToast:@"暂未绑定设备"]; }else{ if (backmodel) { [self pushSetTimeVC]; }else{ [self.indicatorView stopAnimating]; [self showLableAction:@"设备已离线"]; //[self.XuTohud hidmyHud]; } } NSLog(@"松诺的设置按钮"); } -(void)pushSetTimeVC{ _songNuoSetVC=[[SongNuoSetViewController alloc] init]; _songNuoSetVC.currentdevice=self.currentDevice; [self.navigationController pushViewController:_songNuoSetVC animated:YES]; // self.navigationBarHidden=NO; } //-(void)creatFishAnimation{ // //} -(void)initSongNuoUI{ NSArray *nameArr=@[ @"PFLight1_off",@"PFLight1_off",@"ChongLang_off",@"O2_off",@"PFkilLlight_off",@"PFPump_off",@"NewPiFu_beiyongoff",@"JiaReBang_off"]; CGFloat btnControlWith = kScreenSize.width*7/32 - 10; CGFloat btnControlPlace = (kScreenSize.width - 4*btnControlWith * 105 / 122 )/5; CGFloat wspace=25; CGFloat btnwidth= (kScreenSize.width-wspace * 5)/4; for (int i = 0; i < 4; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith * 105 / 122),kScreenSize.height - 2*20 - 2 * btnControlWith -10-64, btnControlWith * 105 / 122, btnControlWith); [self.button setImage:[UIImage imageNamed:nameArr[i]] forState:UIControlStateNormal]; //self.button.backgroundColor = [UIColor redColor]; self.button.tag=600000+i; [self.button addTarget:self action:@selector(songNuoBtnClick:) forControlEvents:UIControlEventTouchUpInside]; UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake((wspace+i * (btnwidth+wspace)) - 5,kScreenSize.height - 2*20 - 2 * btnControlWith -10-64 +btnControlWith,btnwidth +10, 20)]; 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.nuoLight1Btn = self.button; self.light1Name = textLbl; }else if (i==1){ self.nuoLight2Btn = self.button; self.light2Name = textLbl; }else if (i==2){ self.nuoWaterPumpBtn = self.button; self.waterPumpName = textLbl; }else if (i==3){ self.nuoAirPumpBtn = self.button; self.airPumpName = textLbl; } } CGFloat lineTwoOringY=kScreenSize.height - 2*20 - 2 * btnControlWith -10-64 +btnControlWith +20; for (int i = 0; i < 4; i ++) { self.button = [[UIButton alloc] init] ; self.button.frame = CGRectMake(btnControlPlace +i*(btnControlPlace + btnControlWith * 105 / 122), lineTwoOringY, btnControlWith * 105 / 122, btnControlWith); [self.button setImage:[UIImage imageNamed:nameArr[i+4]]forState:UIControlStateNormal]; //self.button.backgroundColor = [UIColor blueColor]; self.button.tag= 600004+i; [self.button addTarget:self action:@selector(songNuoBtnClick:) forControlEvents:UIControlEventTouchUpInside]; UILabel* textLbl = [[UILabel alloc] initWithFrame:CGRectMake((wspace+i * (btnwidth+wspace)) - 5, lineTwoOringY + btnControlWith, btnwidth +10, 20)]; //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 = @[@"UV",@"造浪",@"备用",@"加热棒"]; textLbl.font = [UIFont boldSystemFontOfSize:14]; textLbl.text = arr[i]; [self.tableView addSubview:textLbl]; [self.tableView addSubview:self.button]; if (i==0) { self.nuoUVPumpBtn = self.button; self.uVName = textLbl; }else if (i==1){ self.nuoWaveBtn = self.button; self.waveName = textLbl; }else if (i==2){ self.nuoBeiYongBtn = self.button; self.beiYongName = textLbl; }else if (i==3){ self.jiaReName = textLbl; self.nuoJiaReBtn = self.button; } } //重置 self.bubble 的 frame CGFloat animViewHeight= kScreenSize.width/4; if (kScreenSize.height==480) { CGFloat bubH = (kScreenSize.width - 2 * kPlace)*2/3; self.bubble.frame = CGRectMake((kScreenSize.width -(kScreenSize.width - 2 * kPlace)*2/3)/2, kPlace + 60 , bubH, bubH); 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); CGFloat notlabelH = kScreenSize.width - 2 * kPlace - 200; self.notOnLineLabel.frame = CGRectMake(0, bubH/2 - notlabelH/2, bubH, notlabelH); 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]; CGFloat bubH = kScreenSize.width - 3 * kPlace; CGFloat bubW = kScreenSize.width - 3 * kPlace; self.bubble.frame = CGRectMake((kScreenSize.width -(kScreenSize.width - 3 * kPlace ))/2, kPlace + 80 , bubW,bubH); 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 notlabelH = kScreenSize.width - 2 * kPlace - 200; self.notOnLineLabel.frame = CGRectMake(0 ,bubH/2 - notlabelH/2, bubW, notlabelH); self.notOnLineLabel .font = [UIFont fontWithName:@"Avenir Next Condensed" size:20]; } [self initCHNames]; } -(void)songNuoBtnClick:(UIButton*)btn{ SongNuoBackMassage*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoBackMassage"]; if (backmodel) { }else{ [self deviceNotOnlineState]; [self showLableAction:@"设备已离线"]; return; } XuToLightModel * lightModel=[[XuToLightModel 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 SONGNUO_LIGHT1: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber =@"01"; 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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_LIGHT2: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFLight1_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber =@"02";// 01 --灯1 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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_WATERPUMP: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"ChongLang_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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_AIRPUMP: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"O2_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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_UV: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFkilLlight_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber=@"05";// 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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_WAVE: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"PFPump_on.png"] forState:UIControlStateSelected]; lightModel.lightNumber=@"06";// 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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_BEI: { btn.userInteractionEnabled=YES; [btn setImage:[UIImage imageNamed:@"NewPiFu_beiyongon.png"] forState:UIControlStateSelected]; lightModel.lightNumber=@"07";// 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 creatSongNuoIndicator]; [self.SongNuoHud myhudstart]; } if ([lightModel.switchBtn isEqualToString:@"00"]) { btn.selected=YES; }else{ btn.selected=NO; } } break; case SONGNUO_JIARE: { 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 songNuoJiaReMianQue]; }else{ [self showLableAction:@"设备已离线"]; } } break; default: break; } } #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)songNuoJiaReMianQue{ SongNuoBackMassage *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoBackMassage"]; 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(_songNuoMainQueue, ^{ for (NSInteger i=0; i%@",data); self.dataLength=string1.length; //存储 if (string1.length == IFISH_BACKMASGTYAP128) { [SongNuoBackMsgDataUnity readSoketDataWithBaackMassgModel:_songNuoBackModel addWithBackData:data]; } // 温度 [SongNuoBackMsgDataUnity setTemperaturelabel:self.temperature addbubleImge:self.bubble WithBackData:data addWithBackMassageModel:_songNuoBackModel addWithTableview:self.tableView]; //灯的状态 [SongNuoBackMsgDataUnity resetSongNuoButtonState:self.nuoLight1Btn addlight2:self.nuoLight2Btn addWaterPump:self.nuoWaterPumpBtn addAir:self.nuoAirPumpBtn addUV:self.nuoUVPumpBtn addWave:self.nuoWaveBtn addBeiYong:self.nuoBeiYongBtn addJiaRe:self.nuoJiaReBtn withBackModel:_songNuoBackModel]; // 刷新设置界面 _songNuoSetVC.timeArr = [SongNuoBackMsgDataUnity refreshSongNuoTimerAddTemperatureWithBackMassageModel:_songNuoBackModel]; [_songNuoSetVC.tableView reloadData]; } -(void)ifishDeviceLogInSuccees{ self.isconnect=YES; NSLog(@"app登录成功"); } -(void)ifishDeviceLogInFail{ [self endRefreshing]; [self.indicatorView stopAnimating]; dispatch_async(dispatch_get_main_queue(), ^{ [self deviceNotOnlineState];//设备离线 }); } #pragma mark -父类方法 -(void)shezhiMingCheng { _changeNameVC = [[SonNuo128NameViewController alloc] init]; _changeNameVC.name = self.name.text; _changeNameVC.device = self.currentDevice; __weak typeof (self)wself = self; _changeNameVC.NameWithBlock = ^(NSString *nameStr){ wself.name.text = nameStr; [wself initCHNames]; }; [ wself.navigationController pushViewController: _changeNameVC animated:YES]; } -(void)initCHNames{ SongNuo128Name* songNuo = [UserExtendataArchaver currentSongNuo128:self.currentDevice.macAddress]; self.light1Name.text = songNuo.light1; self.light2Name.text = songNuo.light2; self.waterPumpName.text = songNuo.waterPump; self.airPumpName.text = songNuo.airPump; self.uVName.text = songNuo.uVPump; self.waveName.text = songNuo.wave; self.beiYongName.text = songNuo.beiYong; self.jiaReName.text = songNuo.jiaRe; } @end