-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.cpp
77 lines (63 loc) · 1.93 KB
/
temperature.cpp
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
71
72
73
74
75
76
77
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PrintEx.h>
#include "constants.h"
extern DallasTemperature sensors;
extern LiquidCrystal lcd;
extern PrintEx exSerial;
extern float hexInTemp;
extern float hexOutTemp;
extern float hwcTopTemp;
extern float hwcBottomTemp;
bool sane(double temperature) {
//return (temperature > 0.0 && temperature < 100.0);
return true;
}
void measureTemperatures() {
sensors.requestTemperatures();
hexInTemp = sensors.getTempC(HeatExInAddr);
hexOutTemp = sensors.getTempC(HeatExOutAddr);
hwcTopTemp = sensors.getTempC(HWC_TopAddr);
hwcBottomTemp = sensors.getTempC(HWC_BottomAddr);
}
// warning: will block indefinitely if any sensor is offline
void measureFilteredTemperatures(int samples) {
hexInTemp = 0.0;
hexOutTemp = 0.0;
hwcTopTemp = 0.0;
hwcBottomTemp = 0.0;
for (int i = 0; i < samples; ) {
sensors.requestTemperatures();
double hexIn = sensors.getTempC(HeatExInAddr);
double hexOut = sensors.getTempC(HeatExOutAddr);
double hwcTop = sensors.getTempC(HWC_TopAddr);
double hwcBot = sensors.getTempC(HWC_BottomAddr);
if (sane(hexIn) && sane(hexOut) && sane(hwcTop) && sane(hwcBot)) {
hexInTemp += hexIn;
hexOutTemp += hexOut;
hwcTopTemp += hwcTop;
hwcBottomTemp += hwcBot;
i++;
}
else {
continue;
}
}
hexInTemp /= (double)samples;
hexOutTemp /= (double)samples;
hwcTopTemp /= (double)samples;
hwcBottomTemp /= (double)samples;
}
void displayTemperatures() {
exSerial.printf("%.3f ", millis()/1000.0);
exSerial.printf("HEX in/out: %.2f/%.2f C ", hexInTemp, hexOutTemp);
exSerial.printf("HWC top/bottom: %.2f/%.2f C\n", hwcTopTemp, hwcBottomTemp);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HEX:");
//lcd.print(hwcBottomTemp); lcd.print(" ");
//lcd.print(hwcTopTemp); lcd.print(" ");
lcd.print(hexInTemp); lcd.print(" ");
lcd.print(hexOutTemp);
}