设置温度校准

This commit is contained in:
kai60 2022-05-22 22:09:39 +08:00
parent 2423e97bf8
commit cee511f388
7 changed files with 147 additions and 42 deletions

View File

@ -91,5 +91,18 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) NSString *type;
@end
@interface XuanduoTempCorrectModel : NSObject
/// 01-正偏差02-负偏差
@property (nonatomic, strong) NSString *deviation;
//偏差值
@property (nonatomic, strong) NSString *tempDelta;
//实际值
@property (nonatomic, strong) NSString *realTemp;
@end
NS_ASSUME_NONNULL_END

View File

@ -34,5 +34,11 @@
@end
@implementation XuanduoTempCorrectModel
@end

View File

@ -51,7 +51,8 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
@property(nonatomic,copy) NSString *nextChangeDateLabel;
@property(nonatomic,strong) MyHud *XuTohud;
@property(nonatomic,strong)XuanduoTempratureCorrectView*tempView;
@property(nonatomic,strong)XuanduoTempCorrectModel*tempCorrectModel;
@property(nonatomic,strong)NSTimer*timer;
@end
@implementation XuanduoTempratueCorrectViewController
@ -162,9 +163,12 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
label.numberOfLines=0;
label.text=@"温度校准值需在+-5℃以内超过+-5℃请更换水温抬头更换探头后需点击取消校准按钮清除上一次温度校准的误差值";
CGSize size= [label.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:(NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: label.font} context:NULL].size;
label.frame=CGRectMake((self.view.frame.size.width-size.width)/2.0, CGRectGetMaxY(tempView.frame)+10, size.width, size.height);
label.frame=CGRectMake((self.view.frame.size.width-size.width)/2.0, CGRectGetMaxY(tempView.frame)+100, size.width, size.height);
[self.view addSubview:label];
[self.tempView.cancelBtn addTarget:self action:@selector(cancelCorrect) forControlEvents:UIControlEventTouchUpInside];
[self.tempView.textField becomeFirstResponder];
}
@ -174,8 +178,14 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
#pragma mark - cell
-(void)cancelCorrect
{
[self.tempView.textField resignFirstResponder];
[self correctTempCorrectModel:NO];
}
- (void)sure {
[self.tempView.textField resignFirstResponder];
[self correctTempCorrectModel:NO];
}
- (void)cancel {
@ -260,40 +270,40 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
NSString*string1=[dataContorl dataToHexString:data];
NSLog(@"return str == %@",string1);
NSString *readTimer = [string1 substringToIndex:4];
if (_selectSection-2<_titieArr.count && _selectSection-2>=0 && [readTimer isEqualToString:@"0116"]) {
if (!_timerModel) {
_timerModel = [[Xuanduo2TimerModel alloc] init];
_timerModel.groupModelArr = [NSMutableArray array];
}else {
[_timerModel.groupModelArr removeAllObjects];
if ( [readTimer isEqualToString:@"0116"]) {
NSString*lightNumber=[string1 substringWithRange:NSMakeRange(30, 2)];
if ([lightNumber isEqualToString:@"0b"])//
{
XuanduoTempCorrectModel*tempModel=[[XuanduoTempCorrectModel alloc]init];
tempModel.deviation=[string1 substringWithRange:NSMakeRange(32, 2)];
tempModel.tempDelta=[string1 substringWithRange:NSMakeRange(34, 2)];
tempModel.realTemp=[string1 substringWithRange:NSMakeRange(36, 4)];
self.tempCorrectModel=tempModel;
float mac=[dataContorl hexToTen:tempModel.realTemp];
//float TPlabel=mac/10+(mac%10)*0.1;
float temp = mac/10.0;
NSString *stringTemp = [NSString stringWithFormat:@"%.1f℃",temp];
self.tempView.realTempLabel.text=[NSString stringWithFormat:@"探测温度:%@",stringTemp];
float delta=[dataContorl hexToTen:tempModel.tempDelta];
//float TPlabel=mac/10+(mac%10)*0.1;
float deltatemp = delta/10.0;
NSString *deltatempString = [NSString stringWithFormat:@"%.1f",deltatemp];
NSString*prefix=@"+";
if ([tempModel.deviation isEqualToString:@"02"])
{
prefix=@"-";
}
self.tempView.textField.text=[NSString stringWithFormat:@"%@%@",prefix,deltatempString];
NSString *corrTemp = [NSString stringWithFormat:@"%.1f℃",[tempModel.deviation isEqualToString:@"02"]?(temp-deltatemp):(temp+deltatemp)];
self.tempView.correectTempLabel.text=corrTemp;
}
[Xuanduo2DataUtility readTimerSocketDataWithBackMsgModel:_timerModel addWithBackStr:string1 type:self.currentdevice.type];
NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]];
[dataArr removeAllObjects];
[dataArr addObject:plusflag];
[dataArr addObjectsFromArray:_timerModel.groupModelArr];
BOOL havePlus = [dataArr containsObject:plusflag];
if (havePlus && dataArr.count > 10) {
[dataArr removeObjectAtIndex:0];
}else if (!havePlus && dataArr.count < 10){
[dataArr insertObject:plusflag atIndex:0];
}
NSLog(@"dataarr.count = %ld",dataArr.count);
}
else if (_selectSection-2<_titieArr.count && _selectSection-2>=0 && [readTimer isEqualToString:@"0119"]) {
_cycleModel=[[XuanduoCycleModel alloc]init];
[Xuanduo2DataUtility readCycleSocketDataWithBackMsgModel:_cycleModel addWithBackStr:string1 type:self.currentdevice.type];
NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]];
[dataArr removeAllObjects];
[dataArr addObject:_cycleModel];
}
if ([readTimer isEqualToString:@"0108"] || [readTimer isEqualToString:@"0105"]) {
[Xuanduo2DataUtility readSocketDataWithBackMsgModel:self.dataModel addWithBackData:data type:self.currentdevice.type];
[self refreshWithData:self.dataModel];
@ -309,8 +319,64 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell";
}
-(void)ifishDeviceLogInSuccees{
[self readTempCorrectModel];
// [self.timer invalidate];
// self.timer=nil;
// self.timer=[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(readTempCorrectModel) userInfo:nil repeats:YES];
}
-(void)readTempCorrectModel
{
baseModel*readModel=[[baseModel alloc]init];
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId =self.currentdevice.macAddress;
readModel.functionCode=@"16";
readModel.massagelegth=@"12";
NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,@"0b",@"0000"];
NSData*readData=[dataContorl stringToHexData:readString];
[[Socketsingleton sharedInstance] soketWriteData:readData];
[_indicatorView startAnimating];
}
-(void)correctTempCorrectModel:(BOOL)cancelCorrect;
{
baseModel*readModel=[[baseModel alloc]init];
readModel.sendmacId =self.currentdevice.macAddress;
readModel.resavemacId =self.currentdevice.macAddress;
readModel.functionCode=@"15";
readModel.massagelegth=@"18";
NSString*deviation=@"01";//
if ([self.tempView.textField.text containsString:@"-"])
{
deviation=@"02";//
}
if (cancelCorrect)
{
deviation=@"00";
}
NSString*pureString=[self.tempView.textField.text stringByReplacingOccurrencesOfString:@"-" withString:@""];
pureString=[pureString stringByReplacingOccurrencesOfString:@"+" withString:@""];
pureString=[pureString stringByReplacingOccurrencesOfString:@"℃" withString:@""];
NSInteger delta= (NSInteger)(pureString.floatValue*10);
NSString*hex=[dataContorl leftAddZero:2 andStr:[dataContorl ToHex:delta]];
NSString*readString=[NSString stringWithFormat:@"%@%@%@%@%@%@",readModel.description,@"0b",deviation,hex,@"00000000",@"0000"];
NSData*readData=[dataContorl stringToHexData:readString];
[[Socketsingleton sharedInstance] soketWriteData:readData];
[_indicatorView startAnimating];
[self readTempCorrectModel];
}
-(void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket{

View File

@ -11,7 +11,10 @@
NS_ASSUME_NONNULL_BEGIN
@interface XuanduoTempratureCorrectView : UIView
@property (weak, nonatomic) IBOutlet UILabel *correectTempLabel;
@property (weak, nonatomic) IBOutlet UILabel *realTempLabel;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
@end

View File

@ -20,6 +20,8 @@
-(void)awakeFromNib
{
[super awakeFromNib];
self.cancelBtn.titleLabel.font=[UIFont systemFontOfSize:15];
self.correectTempLabel.layer.cornerRadius=8;
}

View File

@ -26,7 +26,7 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eZR-Ff-N9f">
<rect key="frame" x="134" y="10" width="100" height="30"/>
<rect key="frame" x="144" y="10" width="90" height="27"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="取消校准">
<backgroundConfiguration key="background" cornerRadius="5">
@ -41,10 +41,10 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="26.5" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2pv-Tc-pht">
<rect key="frame" x="204" y="160" width="30" height="30"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2pv-Tc-pht">
<rect key="frame" x="174" y="160" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="AGi-MS-Fiy"/>
<constraint firstAttribute="width" constant="60" id="AGi-MS-Fiy"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<color key="textColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@ -62,7 +62,7 @@
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="校准后温度" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wKE-qN-OPf">
<rect key="frame" x="104" y="160" width="100" height="30"/>
<rect key="frame" x="74" y="160" width="100" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -112,11 +112,11 @@
<constraint firstItem="UAM-uW-zwv" firstAttribute="bottom" secondItem="tlB-Qi-mvx" secondAttribute="bottom" id="SG0-B0-jvm"/>
<constraint firstItem="Stf-9K-Vtb" firstAttribute="leading" secondItem="DJa-9i-S0t" secondAttribute="leading" constant="10" id="WG8-b7-TFf"/>
<constraint firstItem="wKE-qN-OPf" firstAttribute="width" secondItem="lNj-YX-wf8" secondAttribute="width" id="aVX-zi-E9e"/>
<constraint firstItem="eZR-Ff-N9f" firstAttribute="width" secondItem="eTc-I0-xrM" secondAttribute="width" id="akQ-uf-l8S"/>
<constraint firstItem="eZR-Ff-N9f" firstAttribute="width" secondItem="eTc-I0-xrM" secondAttribute="width" multiplier="0.9" id="akQ-uf-l8S"/>
<constraint firstItem="eTc-I0-xrM" firstAttribute="leading" secondItem="DJa-9i-S0t" secondAttribute="leading" constant="10" id="hcQ-6T-XJu"/>
<constraint firstItem="wKE-qN-OPf" firstAttribute="height" secondItem="lNj-YX-wf8" secondAttribute="height" id="lZH-Lf-c2W"/>
<constraint firstItem="eTc-I0-xrM" firstAttribute="top" secondItem="2c8-dl-t76" secondAttribute="top" constant="10" id="mZ3-zX-X38"/>
<constraint firstItem="eZR-Ff-N9f" firstAttribute="height" secondItem="eTc-I0-xrM" secondAttribute="height" id="njJ-Xg-nZV"/>
<constraint firstItem="eZR-Ff-N9f" firstAttribute="height" secondItem="eTc-I0-xrM" secondAttribute="height" multiplier="0.9" id="njJ-Xg-nZV"/>
<constraint firstItem="tlB-Qi-mvx" firstAttribute="leading" secondItem="UAM-uW-zwv" secondAttribute="trailing" id="qKW-8X-Jdb"/>
<constraint firstItem="Stf-9K-Vtb" firstAttribute="centerX" secondItem="2c8-dl-t76" secondAttribute="centerX" id="qaD-6J-CIh"/>
<constraint firstItem="UAM-uW-zwv" firstAttribute="centerX" secondItem="2c8-dl-t76" secondAttribute="centerX" constant="-25" id="rsP-yf-UVU"/>
@ -125,6 +125,9 @@
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="cancelBtn" destination="eZR-Ff-N9f" id="PPd-sa-6YL"/>
<outlet property="correectTempLabel" destination="2pv-Tc-pht" id="ukG-tt-i95"/>
<outlet property="realTempLabel" destination="lNj-YX-wf8" id="fUK-QZ-LCX"/>
<outlet property="textField" destination="tlB-Qi-mvx" id="aZk-GW-RxM"/>
</connections>
<point key="canvasLocation" x="-1346.376811594203" y="-94.419642857142847"/>

View File

@ -178,6 +178,18 @@ static NSString *cycleTimerflag = @"CycleTimerCell";
[self.tableView registerNib:[UINib nibWithNibName:addCellid bundle:nil] forCellReuseIdentifier:addCellid];
[self.tableView registerNib:[UINib nibWithNibName:cycleTimerflag bundle:nil] forCellReuseIdentifier:cycleTimerflag];
[self.tableView registerNib:[UINib nibWithNibName:setTimerflag bundle:nil] forCellReuseIdentifier:setTimerflag];
if (self.timerType==2)
{
UILabel*label=[[UILabel alloc]initWithFrame:CGRectZero];
label.textColor=[UIColor whiteColor];
label.font=[UIFont systemFontOfSize:12];
label.numberOfLines=0;
label.text=@"开启时间为设备运行的时间,关闭时间为设备停止的时间,例如设置开启1小时关闭2小时设备将会运行1小时停止2小时以此规律循环运行。";
CGSize size= [label.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:(NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: label.font} context:NULL].size;
label.frame=CGRectMake((kScreenWidth-size.width)/2.0, 300, size.width, size.height);
[self.view addSubview:label];
}
}
-(void)clickCell:(TimerTypeTableViewCell *)cell button:(UIButton *)button timerType:(NSInteger )type