ifish/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/SongNuo/SongNuo86Byte/SongNuoDBSetViewController.m

1217 lines
44 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SongNuoDBSetViewController.m
// Ifish
//
// Created by imac on 17/1/6.
// Copyright © 2017年 lianxiang. All rights reserved.
//
#import "SongNuoDBSetViewController.h"
#import "SetTimeCell.h"
#import "SecondSetTimeCell.h"
#import "SetTimeModel.h"
#import "SetSelectorTime.h"
//#import "AsyncSocket.h"
#import "setWaringTpModel.h"
#import "appLogin.h"
#import "workTypeModel.h"
#import "SetSelectorTime.h"
#define TIME_TAG 300
#import "MyPickerView.h"
#import "searchDeviceModel.h"
#import "SongNuoBDProtocol.h"
#import "MydatePickerView.h"
#define SET_CELL_TAG 2000
#define MYSWITCH_TAG 3000
#import "CenterViewController.h"
#import "TimerSateModel.h"
#import "TemperatureSetCell.h"
#import "TemperatureSetModel.h"
#import "AppDelegate.h"
#import "BrightnessCell.h"
#import "GuidengKaiGuanModel.h"
#import "GuiDengViewCell.h"
#import "ChangeWaterCell.h"
#import "remindCyclePic.h"
#import "BrightnessModel.h"
#import "CreatErWeiMaController.h"
#import "SOngNuoGuiDeng.h"
@interface SongNuoDBSetViewController ()
{
MydatePickerView*_mydatepicView;
MyPickerView* _mypicView;
remindCyclePic*_remindPic;
dispatch_queue_t _mainQueue;
BOOL _huanShuiSwitchIsOn;
}
@property(nonatomic,strong)NSIndexPath*indexpath;
@property(nonatomic,copy)NSString*statString;
@property(nonatomic,copy)NSString*endString;
@property(nonatomic,strong)UIView*lodingbackView;
@property(nonatomic,copy)NSString*nextChangeDateLabel;
@property(nonatomic,strong)setRemindWaterModel*waterInfmodel;
@property(nonatomic) NSInteger tian;
@end
@implementation SongNuoDBSetViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_waterInfmodel=[[setRemindWaterModel alloc]init];
[super viewDidLoad];
_mainQueue = dispatch_get_main_queue();
self.navigationController.navigationBar.backItem.title=@"";
[self addTitleViewWithTitle:@"设置"];
[self initData];
[self creatIndicatorView];
self.tableView.backgroundColor=COLOR_MIAN;
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
}
-(void)creatIndicatorView{
_indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_indicatorView.frame=CGRectMake(kScreenSize.width/2-50,kScreenSize.height/2-100,100, 100);
_indicatorView.backgroundColor=IndicatorBack_COLOR;
_indicatorView.layer.masksToBounds=YES;
_indicatorView.layer.cornerRadius=5;
AppDelegate*delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
[delegate.window addSubview:_indicatorView];
}
-(void)initData{
self.titleArr=@[@[@"预警设置",@"背光亮度",@"换水提醒"],@[@"时段一",@"时段二"],@[@"时段一",@"时段二"],@[@"时段一",@"时段二"],@[@"时段一",@"时段二",@""]];
//松诺BD 86字节 8定时器 //此种设备柜灯在主页当正常灯控制 ,注意这里柜灯没有定时器。
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
if (backmodel) {
NSString*low=backmodel.miniTp;
NSString*heigh=backmodel.maxTp;
UInt64 lowten=[dataContorl hexToTen:low];
UInt64 heighten=[dataContorl hexToTen:heigh];
float formatlow=lowten/10;
float formatheigh=heighten/10;
NSString*wenduString=[NSString stringWithFormat:@"%.0f~%.0f°C",formatlow,formatheigh];
// 十六进制
NSString*startTimeHex1=[backmodel.timer1 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex1=[backmodel.timer1 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen1=[dataContorl hexStringToDateString:startTimeHex1];
NSString*endTimeTen1=[dataContorl hexStringToDateString:endTimeHex1];
NSString*setTim1=[NSString stringWithFormat:@"%@~%@",startTimeTen1,endTimeTen1];
// 十六进制
NSString*startTimeHex2=[backmodel.timer2 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex2=[backmodel.timer2 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen2=[dataContorl hexStringToDateString:startTimeHex2];
NSString*endTimeTen2=[dataContorl hexStringToDateString:endTimeHex2];
NSString*setTim2=[NSString stringWithFormat:@"%@~%@",startTimeTen2,endTimeTen2];
// 十六进制
NSString*startTimeHex3=[backmodel.timer3 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex3=[backmodel.timer3 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen3=[dataContorl hexStringToDateString:startTimeHex3];
NSString*endTimeTen3=[dataContorl hexStringToDateString:endTimeHex3];
NSString*setTim3=[NSString stringWithFormat:@"%@~%@",startTimeTen3,endTimeTen3];
// 十六进制
NSString*startTimeHex4=[backmodel.timer4 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex4=[backmodel.timer4 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen4=[dataContorl hexStringToDateString:startTimeHex4];
NSString*endTimeTen4=[dataContorl hexStringToDateString:endTimeHex4];
NSString*setTim4=[NSString stringWithFormat:@"%@~%@",startTimeTen4,endTimeTen4];
// 十六进制
NSString*startTimeHex5=[backmodel.timer5 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex5=[backmodel.timer5 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen5=[dataContorl hexStringToDateString:startTimeHex5];
NSString*endTimeTen5=[dataContorl hexStringToDateString:endTimeHex5];
NSString*setTim5=[NSString stringWithFormat:@"%@~%@",startTimeTen5,endTimeTen5];
// 十六进制
NSString*startTimeHex6=[backmodel.timer6 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex6=[backmodel.timer6 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen6=[dataContorl hexStringToDateString:startTimeHex6];
NSString*endTimeTen6=[dataContorl hexStringToDateString:endTimeHex6];
NSString*setTim6=[NSString stringWithFormat:@"%@~%@",startTimeTen6,endTimeTen6];
// 十六进制
NSString*startTimeHex7=[backmodel.timer7 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex7=[backmodel.timer7 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen7=[dataContorl hexStringToDateString:startTimeHex7];
NSString*endTimeTen7=[dataContorl hexStringToDateString:endTimeHex7];
NSString*setTim7=[NSString stringWithFormat:@"%@~%@",startTimeTen7,endTimeTen7];
// 十六进制
NSString*startTimeHex8=[backmodel.timer8 substringWithRange:NSMakeRange(4, 4)];
NSString*endTimeHex8=[backmodel.timer8 substringWithRange:NSMakeRange(8, 4)];
// 十进制
NSString*startTimeTen8=[dataContorl hexStringToDateString:startTimeHex8];
NSString*endTimeTen8=[dataContorl hexStringToDateString:endTimeHex8];
NSString*setTim8=[NSString stringWithFormat:@"%@~%@",startTimeTen8,endTimeTen8];
self.timeArr=@[@[wenduString,@"设置时段"],@[setTim1,setTim2],@[setTim3,setTim4],@[setTim5,setTim6],@[setTim7,setTim8],@""];
}else{
[self.view makeToast:@"设备已离线"];
self.timeArr=@[@[@"20~30°C",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@[@"2:00~5:00",@"2:00~5:00"],@""];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
//预警 背光 换水2row
return 4;
}else if (section == 4){
return 3;
}else{
return 2;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
static NSString *cellID=@"kongCell";
UITableViewCell *kongCell=[tableView dequeueReusableCellWithIdentifier:cellID];
if (kongCell==nil) {
kongCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
if (indexPath.section==0&&indexPath.row==0){
if (self.currentdevice) {
if (![self.currentdevice.isPushWendu isEqual:[NSNull null]]) {
TemperatureSetCell*cell=[tableView dequeueReusableCellWithIdentifier:@"TemperatureSetCell"];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"TemperatureSetCell" owner:self options:nil]lastObject];
}
cell.tag=indexPath.row +SET_CELL_TAG+indexPath.section*10;
TemperatureSetModel*model=[[TemperatureSetModel alloc]init];
model.title=self.titleArr[indexPath.section][indexPath.row];
cell.titleLabel.text=model.title;
model.temperatureLabel=self.timeArr[indexPath.section][indexPath.row];
cell.temperaturelabel.text=model.temperatureLabel;
[cell.temPSwitch addTarget:self action:@selector(songNuotempSwitchAction:) forControlEvents:UIControlEventTouchUpInside];
if (backmodel) {
if ([backmodel.baojingSwitch isEqualToString:@"01"]) {
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal];
cell.temPSwitch.selected = NO;
}else{
[cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal];
cell.temPSwitch.selected = YES;
}
}else{
}
return cell;
}else{
return kongCell;
}
}else{
return kongCell;
}
}else if (indexPath.section==0&&indexPath.row==1){
//背光
BrightnessCell*cell=[tableView dequeueReusableCellWithIdentifier:@"BrightnessCell"];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"BrightnessCell" owner:self options:nil]lastObject];
}
if (![_currentdevice.isLightness isEqual:[NSNull null]]) {
if ([_currentdevice.isLightness isEqualToString:@"1"]) {
//有背光
cell.brightTitleLabel.text=_titleArr[indexPath.section][indexPath.row];
// 系统默认YES 这里拖拽结束时再传值需设为NO
cell.btightnessSlider.continuous=NO;
if (backmodel) {
UInt64 lightTen=[dataContorl hexToTen:backmodel.backLight];
[cell.btightnessSlider setValue:lightTen animated:YES];
}
[cell.btightnessSlider addTarget:self action:@selector(songNuobtightnessSlider:) forControlEvents:UIControlEventValueChanged];
cell.brightTitleLabel.hidden=NO;
cell.btightnessSlider.hidden=NO;
cell.persentLabel.hidden=NO;
return cell;
}else{
//无背光
return kongCell;
}
}else{
cell.brightTitleLabel.hidden=YES;
cell.btightnessSlider.hidden=YES;
cell.persentLabel.hidden=YES;
return cell;
}
}else if (indexPath.section==0&&indexPath.row==2){
// 换水提醒
if (![self.currentdevice.waterRemind isEqual:[NSNull null]]) {
ChangeWaterCell*cell=[tableView dequeueReusableCellWithIdentifier:@"ChangeWaterCell"];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"ChangeWaterCell" owner:self options:nil]lastObject];
}
[cell.ChangeWaterSwitch addTarget:self action:@selector(songNuoBDWaterSwitch:) forControlEvents:UIControlEventTouchUpInside];
if ([self.waterInfmodel.waterremind isEqualToString:@"1"]) {
[cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal];
cell.ChangeWaterSwitch.selected = NO;
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"firstSetCell"]];
_huanShuiSwitchIsOn=YES;
}else{
[cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal];
cell.ChangeWaterSwitch.selected = YES;
_huanShuiSwitchIsOn=NO;
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"set_cellBack"]];
}
if (self.waterInfmodel.remindcycle == 0) {
//在未获取换水信息时暂时显示
cell.huanshuiDaylabel.text=@"换水时间";
}else{
cell.huanshuiDaylabel.text=[NSString stringWithFormat:@"%ld天",(long)self.waterInfmodel.remindcycle];
NSLog(@"ce;;%@",cell.huanshuiDaylabel.text);
NSLog(@"222");
}
return cell;
}else{
kongCell.textLabel.text =@"错误信息 waterRemind null";
return kongCell;
}
}else if (indexPath.section==0&&indexPath.row==3){
static NSString*nextHuanShuiLablecellId=@"labelcell";
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:nextHuanShuiLablecellId];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nextHuanShuiLablecellId];
}
if (_huanShuiSwitchIsOn) {
cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.waterInfmodel.remindDate];
if (!self.waterInfmodel.remindDate) {
cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.nextChangeDateLabel];
}
cell.textLabel.font=[UIFont systemFontOfSize:15];
[cell.textLabel sizeToFit];
cell.textLabel.textColor =[UIColor colorWithRed:146.0/256.0 green:146.0/256.0 blue:146.0/256.0 alpha:1];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]];
}else{
cell.textLabel.text=@"";
}
cell.userInteractionEnabled = NO;
return cell;
}else{
if (indexPath.section==4&&indexPath.row==2) {
//最后插入一个cell达到 椭圆底效果
static NSString*cellId=@"lastSectlastcell";
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
cell.backgroundView =[ [UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]];
cell.userInteractionEnabled = NO;
return cell;
}else{
SetTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetTimeCell"];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"SetTimeCell" owner:self options:nil]lastObject];
}
if (indexPath.section==0&&indexPath.row==0) {
cell.mySwitchButton.hidden=YES;
}else{
cell.mySwitchButton.hidden=NO;
}
SetTimeModel*model=[[SetTimeModel alloc]init];
model.title=self.titleArr[indexPath.section][indexPath.row];
cell.titleLabel.text=model.title;
model.timestring=self.timeArr[indexPath.section][indexPath.row];
cell.timeLabel.text=model.timestring;
cell.timeLabel.tag=TIME_TAG+indexPath.section*10+indexPath.row;
if (indexPath.section!=0 && !(indexPath.section==4&&indexPath.row==2)) {
cell.tag=indexPath.row +SET_CELL_TAG+indexPath.section*10;
cell.mySwitchButton.tag=indexPath.row +MYSWITCH_TAG+indexPath.section*10;
}
if (indexPath.section!=0 && !(indexPath.section==4&&indexPath.row==2)) {
// 小按钮状态
[cell setSongNuoBDSwithState:indexPath WithBacmodel:backmodel];
//设置 cell 背景
[cell setSongNuoBDCellBackAtIndex:indexPath];
}
[cell.mySwitchButton addTarget:self action:@selector(songNuobtnCliCk:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
}
}
#pragma mark tableView 头视图和脚视图
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 1) {
return 50;
}else if (section ==0){
return 5;
}else {
return 0;
}
}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//
// if (section==3) {
//
// return 50;
// }else{
// return 0;
// }
//}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0&&indexPath.row==3) {
if (_huanShuiSwitchIsOn) {
return 50;
}else{
return 0;
}
}else if (indexPath.section==0&&indexPath.row==1){
//背光
if (![_currentdevice.isLightness isEqual:[NSNull null]]) {
if ([_currentdevice.isLightness isEqualToString:@"1"]) {
return 100;
}else{
return 0;
}
}else{
return 0;
}
}else if (indexPath.section==0&&indexPath.row==2){
if (![_currentdevice.waterRemind isEqual:[NSNull null]]) {
return 50;
}else{
return 0;
}
}else if (indexPath.section==0&&indexPath.row==0){
//会否有 预警
if (![_currentdevice.isPushWendu isEqual:[NSNull null]]) {
if ([_currentdevice.isPushWendu isEqualToString:@"1"]) {
return 50;
}else{
return 0;
}
}else{
return 0;
}
}else{
return 50;
}
}
-(void)songNuobtnCliCk:(UIButton*)btn{
TimerSateModel*stateModel=[[TimerSateModel alloc]init];
stateModel.resavemacId =self.currentdevice.macAddress;
stateModel.sendmacId =self.currentdevice.macAddress;
stateModel.crc16String=@"0000";
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
NSString*backState=nil;
// SetSelectorTime*selectorTimeModel=[[SetSelectorTime alloc]init];
if (btn.tag==3010) {
backState=[backmodel.timer1 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"01";
// stateModel.timerState=[backmodel.timer1 substringWithRange:NSMakeRange(2, 2)];
}else if (btn.tag==3011){
backState=[backmodel.timer2 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"02";
// stateModel.timerState=[backmodel.timer2 substringWithRange:NSMakeRange(2, 2)];
}else if (btn.tag==3020){
backState=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"03";
// stateModel.timerState=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)];
}else if (btn.tag==3021){
backState=[backmodel.timer4 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"04";
// stateModel.timerState=[backmodel.timer4 substringWithRange:NSMakeRange(2, 2)];
}else if (btn.tag==3030){
backState=[backmodel.timer5 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"05";
//stateModel.timerState=[backmodel.timer5 substringWithRange:NSMakeRange(2, 2)];
}else if (btn.tag==3031){
backState=[backmodel.timer6 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"06";
}else if (btn.tag==3040){
backState=[backmodel.timer7 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"07";
}else if (btn.tag==3041){
backState=[backmodel.timer8 substringWithRange:NSMakeRange(2, 2)];
stateModel.timerNumber=@"08";
}
if ([backState isEqualToString:@"01"]) {
stateModel.timerState=@"00";// 关
NSString*stateString=[NSString stringWithFormat:@"%@%@%@%@",stateModel.description,stateModel.timerNumber,stateModel.timerState,stateModel.crc16String];
NSData*selctorData=[dataContorl stringToHexData:stateString];
[[Socketsingleton sharedInstance] soketWriteData:selctorData];
[_indicatorView startAnimating];
[btn setImage:[UIImage imageNamed:@"Switch-Off"] forState:UIControlStateNormal];
}else{
stateModel.timerState=@"01";// 开
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@",stateModel.description,stateModel.timerNumber,stateModel.timerState,stateModel.crc16String];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
[[Socketsingleton sharedInstance] soketWriteData:selctorData];
[_indicatorView startAnimating];
[btn setImage:[UIImage imageNamed:@"Switch-On"] forState:UIControlStateNormal];
}
}
#pragma mark 开启关闭报警
-(void)songNuotempSwitchAction:(UIButton*)temperatureSwitch{
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
setWaringTpModel*warModel1=[[setWaringTpModel alloc]init];
warModel1.sendmacId =self.currentdevice.macAddress;
warModel1.resavemacId =self.currentdevice.macAddress;
//BOOL isOn=[temperatureSwitch isOn];
if (temperatureSwitch.selected == YES) {
NSLog(@"");
temperatureSwitch.selected = NO;
warModel1.kaiguan=@"01";// 开
warModel1.miniwaterTp=@"0000"; // 0
warModel1.maxwaterTp=@"0000";//0
}else{
temperatureSwitch.selected =YES;
warModel1.kaiguan=@"00";// 关
warModel1.miniwaterTp=@"0000"; // 0
warModel1.maxwaterTp=@"0000";//0
NSLog(@"");
}
[self setTmperatureStateWithModel:warModel1 addBackModel:backmodel];
}
-(void)setTmperatureStateWithModel:(setWaringTpModel*)waringModel addBackModel:(SongNuoBDProtocol *)backModel{
NSString*maxminTpString=waringModel.description;
waringModel.crc16Ing=@"0000";
NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@",maxminTpString,waringModel.kaiguan,waringModel.miniwaterTp,waringModel.maxwaterTp,waringModel.crc16Ing];
NSData*minwenDuData=[dataContorl stringToHexData:minString];
[[Socketsingleton sharedInstance] soketWriteData:minwenDuData];
[_indicatorView startAnimating];
backModel.miniTp=waringModel.miniwaterTp;
backModel.maxTp=waringModel.maxwaterTp;
}
#pragma mark 换水提醒Action
-(void)songNuoBDWaterSwitch:(UIButton*)sender{
UIButton*huanShuiSwitch=(UIButton*)sender;
//BOOL isButtonOn=[huanShuiSwitch isOn];
NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults];
NSString *picResult=[defuat objectForKey:@"SongNuoBDPicSult"];
int pic = picResult.intValue;
if (pic==0) {
[self showTitle:@"" messsage:@"请设置提醒天数"];
if (huanShuiSwitch.selected == YES) {
huanShuiSwitch.selected =NO;
}else{
huanShuiSwitch.selected =YES;
}
}else{
if (huanShuiSwitch.selected ==YES) {
//开
huanShuiSwitch.selected =NO;
[IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId
waterRemind:@"1" remindCycle:picResult
huishuiShiJian:^(setRemindWaterModel *remindModel) {
self.nextChangeDateLabel=remindModel.remindDate;
}];
//更新选择状态 设置界面 在不断 刷新
self.waterInfmodel.waterremind=@"1";
[self.tableView reloadData];
}else{
//关
huanShuiSwitch.selected =YES;
[IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId
waterRemind:@"0" remindCycle:picResult
huishuiShiJian:^(setRemindWaterModel *remindModel) {
self.nextChangeDateLabel=remindModel.remindDate;
self.waterInfmodel=remindModel;
}];
self.waterInfmodel.waterremind=@"0";
[self.tableView reloadData];
}
}
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section==1) {
UIImageView*secondSectionHeader=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"firstSetCell"]];
UILabel *label=[[UILabel alloc] init];
label.text=@"定时模式";
label.font = [UIFont systemFontOfSize:15];
label.frame=CGRectMake(18, 5, 100, 40);
[secondSectionHeader addSubview:label];
return secondSectionHeader;
}else if (section == 0){
UIView*oneHeader=[[UIView alloc] init];
oneHeader.backgroundColor=COLOR_MIAN;
return oneHeader;
}else{
return nil;
}
}
#pragma mark tableView 点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_indexpath=indexPath;
if (indexPath.row==0&&indexPath.section==0) {
_mypicView=[[MyPickerView alloc]init];
_mypicView.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height);
[self.view.window addSubview:_mypicView];
[_mypicView.cancleButton addTarget:self action:@selector(songNuopicviewRemoveByCancle) forControlEvents:UIControlEventTouchUpInside];
[_mypicView.sureButton addTarget:self action:@selector(songNuopicViewRemoveByDone) forControlEvents:UIControlEventTouchUpInside];
[self temperatureMainQueue];
}else if (indexPath.section==0&&indexPath.row==2){
//换水提醒日期选择
_remindPic=[[remindCyclePic alloc]init];
_remindPic.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height);
[self.view.window addSubview:_remindPic];
[_remindPic.cancleBtn addTarget:self action:@selector(songNuoremindCyclePicRemove) forControlEvents:UIControlEventTouchUpInside];
[_remindPic.sureBtn addTarget:self action:@selector(songNuoremindCyclePicDone) forControlEvents:UIControlEventTouchUpInside];
[self huanShuiMainQueue];
}else if (indexPath.section!=0){
_mydatepicView=[[MydatePickerView alloc]init];
_mydatepicView.frame=CGRectMake(0,0,kScreenSize.width,kScreenSize.height);
[_mydatepicView.cancleButton addTarget:self action:@selector(cancleButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_mydatepicView.sureButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
if (backmodel) {
//在线
[self useMainQueue];
}
// 设置pickerView 默认选择行
[self.view.window addSubview:_mydatepicView];
}
}
#pragma mark 移除换水时间选择器
-(void)songNuoremindCyclePicRemove{
[_remindPic removeFromSuperview];
}
#pragma mark 换水时间设置
-(void)songNuoremindCyclePicDone{
// if (_indexpath.section==0&&_indexpath.row==3) {
ChangeWaterCell*cell=[self.tableView cellForRowAtIndexPath:_indexpath];
NSString *str=_remindPic.picViewResultString;
if (str==nil) {
//str=@"1";
NSLog(@"ni hua dong tai kuai");
str=[NSString stringWithFormat:@"%ld",(long)self.waterInfmodel.remindcycle];
//[self.view makeToast:@"请设置换水天数"];
[_remindPic makeToast:@"请设置换水天数"];
return;
}
cell.huanshuiDaylabel.text=[NSString stringWithFormat:@"%@天",str];
//设置换水日期
[IFISHHTTPTOOL setRemindWaterInfWith:self.currentdevice.deviceId
waterRemind:@"1" remindCycle:str
huishuiShiJian:^(setRemindWaterModel *remindModel) {
self.nextChangeDateLabel=remindModel.remindDate;
self.waterInfmodel.waterremind=@"1";
self.waterInfmodel.remindDate=remindModel.remindDate;
self.waterInfmodel.remindcycle = remindModel.remindcycle;
[self.tableView reloadData];
}];
NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults];
[defuat setValue:str forKey:@"SongNuoBDPicSult"];
[defuat synchronize];
[_remindPic removeFromSuperview];
// }
}
#pragma mark 默认换水时间
-(void)huanShuiMainQueue{
if (_remindPic.picViewResultString !=nil || (_remindPic.picViewResultString ==nil && self.waterInfmodel.remindcycle !=0 )) {
NSArray*shijianArr=[_remindPic.picArr objectAtIndex:0];
dispatch_async(_mainQueue, ^{
NSLog(@"a");
for (NSInteger k=0; k<shijianArr.count; k++) {
ChangeWaterCell*cell=(ChangeWaterCell*)[self tableView:self.tableView cellForRowAtIndexPath:_indexpath];
NSString*dateString=cell.huanshuiDaylabel.text;
NSString*start=nil;
if (self.waterInfmodel.remindcycle == 0) {
//未设置换水时间时 默认为1
start = @"1";
}else{
NSRange range=[dateString rangeOfString:@""];
start=[dateString substringToIndex:range.location];
}
//判断数据源数组小于十的情况
//_remindPic.picViewResultString=dateString;
NSString*picString=shijianArr[k];
if ([picString isEqualToString:start] ) {
[_remindPic.pic selectRow:k inComponent:0 animated:NO];
}
}
});
}
}
- (void)useMainQueue{
NSArray*statArr=[_mydatepicView.dataArr objectAtIndex:0];
NSArray*endArr=[_mydatepicView.dataArr objectAtIndex:1];
// 一区
dispatch_async(_mainQueue, ^{
NSLog(@"a");
for (NSInteger i=0; i<statArr.count; i++) {
NSString*timeString=_timeArr[_indexpath.section][_indexpath.row];
NSRange range=[timeString rangeOfString:@"~"];
NSString*start=[timeString substringToIndex:range.location];
//判断数据源数组小于十的情况
_mydatepicView.startString=start;
NSString*startpicString=statArr[i];
if ([startpicString isEqualToString:start ] ) {
[_mydatepicView.picView selectRow:i inComponent:0 animated:NO];
}
}
});
// 二区
dispatch_async(_mainQueue, ^{
NSLog(@"b");
for (NSInteger k=0; k<endArr.count; k++) {
NSString*timeString=_timeArr[_indexpath.section][_indexpath.row];
NSRange range=[timeString rangeOfString:@"~"];
NSString*end=[timeString substringFromIndex:range.location+1];
_mydatepicView.endString=end;
NSString*endString=endArr[k];
if ([endString isEqualToString:end ]) {
[_mydatepicView.picView selectRow:k inComponent:1 animated:NO];
}
}
});
}
-(void)temperatureMainQueue{
NSArray*lowArr=[_mypicView.picArr objectAtIndex:0];
NSArray*heighArr=[_mypicView.picArr objectAtIndex:2];
dispatch_async(_mainQueue, ^{
for (NSInteger i=0; i<lowArr.count; i++) {
NSString*tempretureString=_timeArr[_indexpath.section][_indexpath.row];
NSString*tempretureString1=[tempretureString substringWithRange:NSMakeRange(0, tempretureString.length-2)];
NSRange range=[tempretureString1 rangeOfString:@"~"];
NSString*start=[tempretureString1 substringToIndex:range.location];
NSString*startpicString=lowArr[i];
if ([startpicString isEqualToString:start ] ) {
[_mypicView.picView selectRow:i inComponent:0 animated:NO];
_mypicView.lowindex=i;
}
}
});
dispatch_async(_mainQueue, ^{
for (NSInteger j=0; j<heighArr.count; j++) {
NSString*tempretureString=_timeArr[_indexpath.section][_indexpath.row];
NSString*tempretureString1=[tempretureString substringWithRange:NSMakeRange(0, tempretureString.length-2)];
NSRange range=[tempretureString1 rangeOfString:@"~"];
NSString*start=[tempretureString1 substringFromIndex:range.location+1];
NSString*startpicString=heighArr[j];
if ([startpicString isEqualToString:start ] ) {
[_mypicView.picView selectRow:j inComponent:2 animated:NO];
_mypicView.heighindex=j;
}
}
});
}
-(void)songNuopicviewRemoveByCancle{
[_mypicView removeFromSuperview];
}
//温度设置
#pragma mark 温度设置
-(void)songNuopicViewRemoveByDone{
if (_mypicView.picViewResultString==nil) {
[_mypicView removeFromSuperview];
}else{
if (_indexpath.section==0&&_indexpath.row==0) {
TemperatureSetCell*cell=[self.tableView cellForRowAtIndexPath:_indexpath];
cell.temperaturelabel.text=[NSString stringWithFormat:@"%@°C",_mypicView.picViewResultString];
}
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
// 低温
setWaringTpModel*warModel1=[[setWaringTpModel alloc]init];
warModel1.resavemacId =self.currentdevice.macAddress;
warModel1.sendmacId =self.currentdevice.macAddress;
warModel1.crc16Ing=@"0000";
warModel1.kaiguan=@"02";//设置
NSString*maxminTpString=warModel1.description;
NSRange range=[_mypicView.picViewResultString rangeOfString:@"~"];
NSString*lowString=[_mypicView.picViewResultString substringToIndex:range.location];
int intlowString = [lowString intValue];
int newIntlowString=intlowString*10;
warModel1.miniwaterTp=[dataContorl tpIntStringToFourHex:newIntlowString]; // 转四位16进制
//写入数据
backmodel.miniTp=warModel1.miniwaterTp;
// 高温
setWaringTpModel*warModel2=[[setWaringTpModel alloc]init];
warModel2.resavemacId =self.currentdevice.macAddress;
warModel2.sendmacId =self.currentdevice.macAddress;
warModel2.crc16Ing=@"0000";
warModel2.kaiguan=@"02";//设置
NSString*heighString=[_mypicView.picViewResultString substringFromIndex:range.location+1];
int intString = [heighString intValue];
int newIntString=intString*10;
warModel2.maxwaterTp=[dataContorl tpIntStringToFourHex:newIntString];
if ([lowString intValue]<[heighString intValue]) {
backmodel.miniTp=warModel1.miniwaterTp;
NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@",maxminTpString,warModel1.kaiguan,warModel1.miniwaterTp,warModel2.maxwaterTp,warModel1.crc16Ing];
NSData*minwenDuData=[dataContorl stringToHexData:minString];
[[Socketsingleton sharedInstance] soketWriteData:minwenDuData];
backmodel.maxTp=warModel2.maxwaterTp;
[_indicatorView startAnimating];
[_mypicView removeFromSuperview];
}else{
[self showTitle:@"提醒" messsage:@"请正确设置温度"];
}
}
}
#pragma mark 设置时间段
-(void)doneButtonClick{
NSLog(@"点击了确定");
_mydatepicView.resultString=nil;
if (_mydatepicView.startString==nil|_mydatepicView.endString==nil) {
[self showTitle:@"" messsage:@"请选择时间"];
}else{
_mydatepicView.resultString=[NSString stringWithFormat:@"%@~%@",_mydatepicView.startString,_mydatepicView.endString];
UILabel*timeLabel=(UILabel*)[self.view viewWithTag:TIME_TAG+_indexpath.section*10+_indexpath.row];
//时小于十时
NSString*hexDateString1=[dataContorl dateStringToHexString:_mydatepicView.startString];
NSString*hexDateString2=[dataContorl dateStringToHexString:_mydatepicView.endString];
//
SetSelectorTime*selectorTimeModel=[[SetSelectorTime alloc]init];
selectorTimeModel.sendmacId =self.currentdevice.macAddress;
selectorTimeModel.resavemacId =self.currentdevice.macAddress;
SongNuoBDProtocol *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoDBProto"];
NSString*timerKaiGuanState=nil;
// NSString*backMasageTimeString=nil;
selectorTimeModel.crc16str=@"0000";
if (_indexpath.section==1&&_indexpath.row==0) {
selectorTimeModel.selectorNumber=@"01";
timerKaiGuanState=[backmodel.timer1 substringWithRange:NSMakeRange(2, 2)];
///backMasageTimeString=[backmessage.timer1 substringFromIndex:4];
}else if (_indexpath.section==1&&_indexpath.row==1){
selectorTimeModel.selectorNumber=@"02";
timerKaiGuanState=[backmodel.timer2 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==2&&_indexpath.row==0){
selectorTimeModel.selectorNumber=@"03";
timerKaiGuanState=[backmodel.timer3 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==2&&_indexpath.row==1){
selectorTimeModel.selectorNumber=@"04";
timerKaiGuanState=[backmodel.timer4 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==3&&_indexpath.row==0){
selectorTimeModel.selectorNumber=@"05";
timerKaiGuanState=[backmodel.timer5 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==3&&_indexpath.row==1){
selectorTimeModel.selectorNumber=@"06";
timerKaiGuanState=[backmodel.timer6 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==4&&_indexpath.row==0){
selectorTimeModel.selectorNumber=@"07";
timerKaiGuanState=[backmodel.timer7 substringWithRange:NSMakeRange(2, 2)];
}else if (_indexpath.section==4&&_indexpath.row==1){
selectorTimeModel.selectorNumber=@"08";
timerKaiGuanState=[backmodel.timer8 substringWithRange:NSMakeRange(2, 2)];
}
timeLabel.text=_mydatepicView.resultString;//
selectorTimeModel.selectorTime=[NSString stringWithFormat:@"%@%@",hexDateString1,hexDateString2];
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@",selectorTimeModel.description,selectorTimeModel.selectorNumber,selectorTimeModel.selectorTime,selectorTimeModel.crc16str];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
[[Socketsingleton sharedInstance] soketWriteData:selctorData];
[_indicatorView startAnimating];
NSLog(@"hexString%@",hexDateString1);
NSLog(@"result%@",_mydatepicView.resultString);
[_mydatepicView removeFromSuperview];
}
}
-(void)cancleButtonClick{
NSLog(@"点击了取消");
[_mydatepicView removeFromSuperview];
}
#pragma mark 导航条 跳转时处理
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBarHidden=NO;
if (_currentdevice) {
[IFISHHTTPTOOL getRemindWaterInfWith:_currentdevice.deviceId huishuiInfo:^(setRemindWaterModel *remindModel) {
self.waterInfmodel=remindModel;
NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults];
[defuat setInteger:self.waterInfmodel.remindcycle forKey:@"SongNuoBDPicSult"];
[defuat synchronize];
self.nextChangeDateLabel=self.waterInfmodel.remindDate;
[self.tableView reloadData];
}];
}
}
#pragma mark - 背光
-(void)songNuobtightnessSlider:(UISlider*)sender{
UISlider*slider=(UISlider*)sender;
NSLog(@"%f",slider.value);
//这里 只传整数
//1.强转四舍五入
int sliderValue=(int)(slider.value+0.5);
NSLog(@"%d",sliderValue);
self.percent=(sliderValue*100)/250;
NSString*hexString=[dataContorl ToHex:sliderValue];
if (hexString.length<2) {
hexString=[NSString stringWithFormat:@"0%@",hexString];
}
BrightnessModel*brightModel=[[BrightnessModel alloc]init
];
brightModel.resavemacId = self.currentdevice.macAddress;
brightModel.sendmacId = self.currentdevice.macAddress;
brightModel.liangdu=hexString;
brightModel.crc16Code=@"0000";
NSString*changeLightOder=[NSString stringWithFormat:@"%@%@%@",brightModel.description,brightModel.liangdu,brightModel.crc16Code];
NSData*changeLghtData=[dataContorl stringToHexData:changeLightOder];
[[Socketsingleton sharedInstance] soketWriteData:changeLghtData];
[_indicatorView startAnimating];
}
-(void)viewWillDisappear:(BOOL)animated{
[_indicatorView stopAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)addAlertView{
[self.view makeToast:@"已经与服务器断开连接"];
}
@end