-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempController.cpp
More file actions
71 lines (55 loc) · 1.68 KB
/
TempController.cpp
File metadata and controls
71 lines (55 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* TempController.cpp
*
* Created on: Aug 1, 2012
* Author: dlouw
*/
#include "TempController.h"
#define DEFAULT_FERM_TEMP 68.0f
bool TempController::initialized = false;
float TempController::deadbandRadius = 1.0f;
void TempController::begin() {
if (!initialized) {
Thermometer::begin();
CoolingControl::begin();
initialized = true;
}
}
TempController::TempController() {
this->targetTemp = DEFAULT_FERM_TEMP;
}
TempController::~TempController() {
}
float TempController::readFermentationTempF() {
return this->thermometer.readTemperatureF();
}
bool TempController::isFermentationTempError() {
return this->thermometer.isInError();
}
void TempController::setCoolingControl(bool enabled) {
this->coolingControl.setPoweredOn(enabled);
}
void TempController::processTempControl() {
float tempF = this->readFermentationTempF();
if (this->thermometer.isInError()) {
Serial.println("Error reading temperature.");
return;
}
Serial.println("Processing Temp Control");
Serial.print("Current Temperature: ");
Serial.println(tempF);
Serial.print("Target Temperature: ");
Serial.println(this->targetTemp);
if (abs(tempF - this->targetTemp) < this->deadbandRadius) {
Serial.println("Temperature within deadband. Cooling unchanged.");
} else if (tempF < this->targetTemp) {
Serial.println("Temperature below target. Cooling disabled.");
this->coolingControl.setPoweredOn(false);
} else {
Serial.println("Temperature above target. Cooling enabled.");
this->coolingControl.setPoweredOn(true);
}
}
bool TempController::getCoolingControlEnabled() {
return this->coolingControl.isPoweredOn();
}