fixed7_9 stringToTempDiff(const char * numberString){
	fixed23_9 rawTempDiff = stringToFixedPoint(numberString);
	return convertAndConstrain(rawTempDiff, 0);	
}
fixed7_9 stringToTemp(const char * numberString){
	fixed23_9 rawTemp = stringToFixedPoint(numberString);
	return convertAndConstrain(rawTemp, 32<<9);
}
Example #3
0
void PiLink::processJsonPair(char * key, char * val){
	debugMessage(PSTR("Received new setting: %s = %s"), key, val);
	if(strcmp(key,jsonKeys.mode) == 0){
		tempControl.setMode(val[0]);
		piLink.printFridgeAnnotation(PSTR("Mode set to %c in web interface"), val[0]);
	}
	else if(strcmp(key,jsonKeys.beerSetting) == 0){ 
		fixed7_9 newTemp = stringToTemp(val);
		if(tempControl.cs.mode == 'p'){
			if(abs(newTemp-tempControl.cs.beerSetting) > 100){ // this excludes gradual updates under 0.2 degrees
				printBeerAnnotation(PSTR("Beer temperature setting changed to %s by temperature profile."), val);
			}
		}
		else{
			printBeerAnnotation(PSTR("Beer temperature setting changed to %s in web interface."), val);
		}
		tempControl.cs.beerSetting = newTemp;
	}
	else if(strcmp(key,jsonKeys.fridgeSetting) == 0){
		fixed7_9 newTemp = stringToTemp(val);
		if(tempControl.cs.mode == 'f'){
			printFridgeAnnotation(PSTR("Fridge temperature setting changed to %s in web interface."), val);
		}
		tempControl.cs.fridgeSetting = newTemp;
	}
	else if(strcmp(key,jsonKeys.heatEstimator) == 0){ tempControl.cs.heatEstimator = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.coolEstimator) == 0){ tempControl.cs.coolEstimator = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.tempFormat) == 0){
		tempControl.cc.tempFormat = val[0];
		display.printStationaryText(); // reprint stationary text to update to right degree unit
	}
	else if(strcmp(key,jsonKeys.tempSettingMin) == 0){ tempControl.cc.tempSettingMin = stringToTemp(val); }
	else if(strcmp(key,jsonKeys.tempSettingMax) == 0){ tempControl.cc.tempSettingMax = stringToTemp(val); }
	else if(strcmp(key,jsonKeys.KpHeat) == 0){ tempControl.cc.KpHeat = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.KpCool) == 0){ tempControl.cc.KpCool = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.Ki) == 0){ tempControl.cc.Ki = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.KdCool) == 0){ tempControl.cc.KdCool = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.KdHeat) == 0){ tempControl.cc.KdHeat = stringToFixedPoint(val); }
	else if(strcmp(key,jsonKeys.iMaxError) == 0){ tempControl.cc.iMaxError = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.iMaxSlope) == 0){ tempControl.cc.iMaxSlope = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.iMinSlope) == 0){ tempControl.cc.iMinSlope = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.idleRangeHigh) == 0){ tempControl.cc.idleRangeHigh = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.idleRangeLow) == 0){ tempControl.cc.idleRangeLow = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.heatingTargetUpper) == 0){ tempControl.cc.heatingTargetUpper = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.heatingTargetLower) == 0){ tempControl.cc.heatingTargetLower = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.coolingTargetUpper) == 0){ tempControl.cc.coolingTargetUpper = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.coolingTargetLower) == 0){ tempControl.cc.coolingTargetLower = stringToTempDiff(val); }
	else if(strcmp(key,jsonKeys.maxHeatTimeForEstimate) == 0){ tempControl.cc.maxHeatTimeForEstimate = strtoul(val, NULL, 10); }
	else if(strcmp(key,jsonKeys.maxCoolTimeForEstimate) == 0){ tempControl.cc.maxCoolTimeForEstimate = strtoul(val, NULL, 10); }
	else if(strcmp(key,jsonKeys.maxCoolTimeForEstimate) == 0){ tempControl.cc.maxCoolTimeForEstimate = strtoul(val, NULL, 10); }
		
	// Receive two chars for filter as uint16_t
	else if(strcmp(key,jsonKeys.fridgeFastFilter) == 0){ 
		tempControl.cc.fridgeFastFilter = strtoul(val, NULL, 10);
		tempControl.fridgeSensor.setFastFilterCoefficients(tempControl.cc.fridgeFastFilter);
	}
	else if(strcmp(key,jsonKeys.fridgeSlowFilter) == 0){
		tempControl.cc.fridgeSlowFilter = strtoul(val, NULL, 10);
		tempControl.fridgeSensor.setSlowFilterCoefficients(tempControl.cc.fridgeSlowFilter);
	}
	else if(strcmp(key,jsonKeys.fridgeSlopeFilter) == 0){
		tempControl.cc.fridgeSlopeFilter = strtoul(val, NULL, 10);
		tempControl.fridgeSensor.setSlopeFilterCoefficients(tempControl.cc.fridgeSlopeFilter);
	}
	else if(strcmp(key,jsonKeys.beerFastFilter) == 0){
		tempControl.cc.beerFastFilter = strtoul(val, NULL, 10);
		tempControl.beerSensor.setFastFilterCoefficients(tempControl.cc.beerFastFilter);
	
	}
	else if(strcmp(key,jsonKeys.beerSlowFilter) == 0){
		tempControl.cc.beerSlowFilter = strtoul(val, NULL, 10);
		tempControl.beerSensor.setSlowFilterCoefficients(tempControl.cc.beerSlowFilter);
	}
	else if(strcmp(key,jsonKeys.beerSlopeFilter) == 0){
		tempControl.cc.beerSlopeFilter = strtoul(val, NULL, 10);
		tempControl.beerSensor.setSlopeFilterCoefficients(tempControl.cc.beerSlopeFilter);
	}
	else{
		debugMessage(PSTR("Could not process setting"));
	}
}