自恢复定时

This commit is contained in:
kai60 2022-05-21 16:34:11 +08:00
parent a46a054ab2
commit 76e8cf7561
5 changed files with 111 additions and 192 deletions

View File

@ -127,9 +127,9 @@ static NSString *setTimerflag = @"SetTimerCell";
- (void)setupTable {
_titieArr = @[@"定时设置",@"喂鱼设置",@"温度校准",@"功能说明"];
_titieArr = @[@"定时设置",@"喂鱼设置",@"温度校准"];
_imgArr = @[@"定时",@"喂鱼",@"温度校准",@"功能说明 "];
_imgArr = @[@"定时",@"喂鱼",@"温度校准"];

View File

@ -44,7 +44,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
@interface XuanduoTimerListViewController ()<IfishCommuniteDelegate,TimerTypeTableViewCellDelegate>
@property(nonatomic,strong) setRemindWaterModel *waterInfmodel;
@property(nonatomic,strong) Xuanduo2TimerModel *timerModel;
@property(nonatomic,strong) XuanduoTimerTypeModel *timerType;
@property(nonatomic,strong) XuanduoTimerTypeModel *timerTypeModel;
@property(nonatomic,strong) XuanduoCycleModel *cycleModel;
@ -178,6 +178,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
_settingVC.currentdevice = self.currentdevice;
_settingVC.dataModel = self.dataModel;
_settingVC.readMode=self.readMode;
_settingVC.timerTypeModel=self.timerTypeModel ;
_settingVC.timerType=type;
[self.navigationController pushViewController:_settingVC animated:YES];
}
@ -353,13 +354,14 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
cell.recoverybtn.selected=NO;
cell.cyclebtn.selected=NO;
if ([_timerType.type isEqualToString:@"08"]) {
//X: 8, 4 2 1 0
if ([_timerTypeModel.type isEqualToString:@"08"]) {
cell.timerbtn.selected=YES;
}
else if ([_timerType.type isEqualToString:@"04"]) {
else if ([_timerTypeModel.type isEqualToString:@"04"]) {
cell.cyclebtn.selected=YES;
}
else if ([_timerType.type isEqualToString:@"02"]||[_timerType.type isEqualToString:@"01"])
else if ([_timerTypeModel.type isEqualToString:@"02"]||[_timerTypeModel.type isEqualToString:@"01"])
{
cell.recoverybtn.selected=YES;
}
@ -416,7 +418,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
}else if (indexPath.section - 2 <_titieArr.count) {
NSArray *dataArr = [self.timeDic objectForKey:_titieArr[indexPath.section-2]];
BOOL havePlus = [dataArr containsObject:plusflag];
if (_selectSection == indexPath.section&&_timerType) {
if (_selectSection == indexPath.section&&_timerTypeModel) {
if (havePlus && indexPath.row == dataArr.count - 1) {
return 40;
}else{
@ -631,7 +633,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
- (void)foldAction:(UIButton *)btn {
if (_selectSection == btn.tag - kBtnTag) {
_selectSection = -1;
_timerType=nil;
_timerTypeModel=nil;
[self.tableView reloadData];
}else {
//
@ -1603,9 +1605,9 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
//
if ([lightNumber.uppercaseString containsString:@"F"])
{
_timerType=[[XuanduoTimerTypeModel alloc]init];
_timerType.lightNumber=lightNumber;
_timerType.type=[string1 substringWithRange:NSMakeRange(32, 2)];
_timerTypeModel=[[XuanduoTimerTypeModel alloc]init];
_timerTypeModel.lightNumber=lightNumber;
_timerTypeModel.type=[string1 substringWithRange:NSMakeRange(32, 2)];
NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]];
[dataArr removeAllObjects];
[dataArr addObject:plusflag];

View File

@ -11,6 +11,7 @@
#include "xuanduo3fModel.h"
#import "ReadTimerModel.h"
#import "UIView+Frame.h"
#import "Xuanduo2TimerModel.h"
NS_ASSUME_NONNULL_BEGIN
@ -24,7 +25,11 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic,strong) DeviceModel* currentdevice;
@property (nonatomic, strong) ReadTimerModel *readMode;
@property (nonatomic, assign) NSInteger timerType; //1,定时 2循环 3自恢复
//原始model
@property(nonatomic,strong) XuanduoTimerTypeModel *timerTypeModel;
@property(nonatomic,strong)NSString*lightNumber;
- (void)refreshWithData:(id)model;
@end

View File

@ -285,7 +285,7 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
return cell;
}
}
else if (self.timerType==3) {//
else if (self.timerType==3) {
NSArray *dataArr = [self.timeDic objectForKey:_titieArr[indexPath.section]];
BOOL havePlus = [dataArr containsObject:plusflag];
if (havePlus && (indexPath.row == dataArr.count-1)) {
@ -295,19 +295,35 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
return cell;
}else {
CycleTimerCell *cell = [tableView dequeueReusableCellWithIdentifier:cycleTimerflag forIndexPath:indexPath];
cell.model=_cycleModel;
if (_cycleModel)
SetTimerCell *cell = [tableView dequeueReusableCellWithIdentifier:setTimerflag forIndexPath:indexPath];
cell.switchBtn.tag = kSwitchBtnTag + indexPath.row;
[cell.switchBtn addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
XuanduoTimerGroup *group = [dataArr objectAtIndex:havePlus?indexPath.row+1:indexPath.row];
cell.model=group;
if ([group isKindOfClass:[XuanduoTimerGroup class]])
{
NSString*hexDateString1=[dataContorl dateStringToHexString:_cycleModel.openTime];
NSString*hexDateString2=[dataContorl dateStringToHexString:_cycleModel.closeTime];
BOOL isOn = NO;
if ([group.status isEqualToString:@"01"]) {
isOn = YES;
}
[cell configTitleLabel:[NSString stringWithFormat:@"时段%@",group.groupNumber] timer:group.time switchStatus:isOn];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else if([group isKindOfClass:[XuanduoCycleModel class]])
{
XuanduoCycleModel*model=group;
BOOL isOn = NO;
if ([model.status isEqualToString:@"00"]) {
isOn = YES;
}
[cell configTitleLabel:@"循环开关" timer:[NSString stringWithFormat:@"持续时长%d分钟",[dataContorl hexToTen:model.lastTime]] switchStatus:isOn];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
}
@ -367,6 +383,16 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
UIButton*swichBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[swichBtn setBackgroundImage:[UIImage imageNamed:@"graybtn_big.png"] forState:UIControlStateNormal];
[swichBtn setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateSelected];
if ([self.timerTypeModel.type isEqualToString:@"01"])
{
swichBtn.selected=YES;
}
else
{
swichBtn.selected=NO;
}
[swichBtn addTarget:self action:@selector(allDayModesSwitchAction:) forControlEvents:UIControlEventTouchUpInside];
swichBtn.frame=CGRectMake(CGRectGetWidth(imageView.frame)-8-60, (CGRectGetHeight(imageView.frame)-33)/2.0, 60, 33);
[imageView addSubview:swichBtn];
@ -563,56 +589,7 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId = self.currentdevice.macAddress;
readModel.crc16str=@"0000";
switch (_selectSection ) {
case 0: //
{
timerModel.selectorNumber = @"04";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"01";
}
}
break;
case 1: //
{
timerModel.selectorNumber = @"01";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"02";
}
}
break;
case 2: //1
{
timerModel.selectorNumber = @"02";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"03";
}
}
break;
case 3: //2
{
timerModel.selectorNumber = @"03";
}
break;
case 4: //
{
timerModel.selectorNumber = @"06";
}
break;
case 5: //
{
timerModel.selectorNumber = @"05";
}
break;
default:
break;
}
readModel.selectorNumber=self.lightNumber;
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
@ -663,83 +640,57 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
}
}
//
- (void)allDayModesSwitchAction:(UIButton *)btn {
btn.selected=!btn.selected;
return;
NSInteger index = btn.tag - kSwitchBtnTag;
NSArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection]];
BOOL havePlus = [dataArr containsObject:plusflag];
SetTimerModel *timerModel = [[SetTimerModel alloc] init];
timerModel.sendmacId =self.currentdevice.macAddress;
timerModel.resavemacId = self.currentdevice.macAddress;
timerModel.crc16str=@"0000";
XuanduoTimerGroup *group = [dataArr objectAtIndex:(havePlus?index+1:index)];
if ([group isKindOfClass: [XuanduoTimerGroup class] ]) {
NSString*hexDateString1=[dataContorl dateStringToHexString:group.startTime];
NSString*hexDateString2=[dataContorl dateStringToHexString:group.endTime];
timerModel.selectorTime=[NSString stringWithFormat:@"%@%@",hexDateString1,hexDateString2];
timerModel.groupNumber = [dataContorl groupNumberTohex:group.groupNumber.integerValue];
if ([group.status isEqualToString:@"01"]) {
timerModel.isOn = @"00";
}else {
timerModel.isOn = @"01";
}
UIAlertController*alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"确认开启全天自恢复模式吗?开启此模式后当手动关闭该设备时10分钟后该设备将自动打开" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*okaction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
btn.selected=!btn.selected;
SetTimerModel *timerModel = [[SetTimerModel alloc] init];
timerModel.sendmacId =self.currentdevice.macAddress;
timerModel.resavemacId = self.currentdevice.macAddress;
timerModel.crc16str=@"0000";
timerModel.selectorNumber=self.lightNumber;
timerModel.groupNumber=@"00";
timerModel.selectorTime=@"00000000";
if (!btn.selected) {
timerModel.isOn = @"00";
}else {
timerModel.isOn = @"01";
}
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
[[Socketsingleton sharedInstance] soketWriteData:selctorData];
ReadTimerModel *readModel = [[ReadTimerModel alloc] init];
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId = self.currentdevice.macAddress;
readModel.crc16str=@"0000";
readModel.selectorNumber=@"";
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str];
ReadTimerModel *readModel = [[ReadTimerModel alloc] init];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
[[Socketsingleton sharedInstance] soketWriteData:selctorData];
// [_indicatorView startAnimating];
readModel.selectorNumber = timerModel.selectorNumber;
NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str];
NSLog(@"read str = %@",readString);
NSData*readData=[dataContorl stringToHexData:readString];
[[Socketsingleton sharedInstance] soketWriteData:readData];
;
}
else if ([group isKindOfClass: [XuanduoCycleModel class] ])
{
baseModel*tempModel=[[baseModel alloc]init];
tempModel.sendmacId =self.currentdevice.macAddress;
tempModel.resavemacId =self.currentdevice.macAddress;
tempModel.functionCode=@"18";
tempModel.massagelegth=@"17";
if ([_cycleModel.status isEqualToString:@"01"]) {
_cycleModel.status = @"00";
}else {
_cycleModel.status = @"01";
}
NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@%@",tempModel.description,_cycleModel.lightNumber,_cycleModel.lastTime,_cycleModel.gapTime,_cycleModel.status,@"0000"];
NSData*tempData=[dataContorl stringToHexData:minString];
[[Socketsingleton sharedInstance] soketWriteData:tempData];
readModel.functionCode=@"16";
baseModel*readModel=[[baseModel alloc]init];
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId =self.currentdevice.macAddress;
readModel.functionCode=@"19";
readModel.massagelegth=@"12";
NSString*readString=[NSString stringWithFormat:@"%@%@%@%@%@%@",readModel.description,_cycleModel.lightNumber,@"0000"];
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId = self.currentdevice.macAddress;
readModel.crc16str=@"0000";
readModel.selectorNumber=[self.lightNumber stringByReplacingOccurrencesOfString:@"d" withString:@"f"];
NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str];
NSData*readData=[dataContorl stringToHexData:readString];
[[Socketsingleton sharedInstance] soketWriteData:readData];
}
[_indicatorView startAnimating];
}];
UIAlertAction*cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:okaction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
@ -947,57 +898,7 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
}
}
switch (index) {
case 0: //
{
timerModel.selectorNumber = @"04";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"01";
}
}
break;
case 1: //
{
timerModel.selectorNumber = @"01";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"02";
}
}
break;
case 2: //1
{
timerModel.selectorNumber = @"02";
if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
timerModel.selectorNumber=@"03";
}
}
break;
case 3: //2
{
timerModel.selectorNumber = @"03";
}
break;
case 4: //
{
timerModel.selectorNumber = @"06";
}
break;
case 5: //
{
timerModel.selectorNumber = @"05";
}
break;
default:
break;
}
timerModel.selectorNumber=self.lightNumber;
NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str];
NSData*selctorData=[dataContorl stringToHexData:selectorString];
@ -1738,7 +1639,17 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
NSLog(@"dataarr.count = %ld",dataArr.count);
}//
else if (self.timerType==3&&[lightNumber.uppercaseString containsString:@"F"])
{
_timerTypeModel=[[XuanduoTimerTypeModel alloc]init];
_timerTypeModel.lightNumber=lightNumber;
_timerTypeModel.type=[string1 substringWithRange:NSMakeRange(32, 2)];
}
}
else if (_selectSection<_titieArr.count && _selectSection>=0 && [readTimer isEqualToString:@"0119"]) {

View File

@ -165,6 +165,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
tableView.delegate=self;
tableView.dataSource=self;
self.tableView=tableView;
[self.view addSubview:tableView];
self.tableView.backgroundColor=COLOR_MIAN;
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
[self.tableView registerNib:[UINib nibWithNibName:temperatureCellid bundle:nil] forCellReuseIdentifier:temperatureCellid];