forked from allpowerlabs/KS_PowerPallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPressure.pde
50 lines (44 loc) · 1.06 KB
/
Pressure.pde
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
// Pressure
void DoPressure() {
UpdateCalibratedPressure();
}
void CalibratePressureSensors() {
int P_sum[6] = {0,0,0,0};
int P_ave;
byte lowbyte,highbyte;
Logln_p("Calibrating Pressure Sensors");
for (int i=0; i<10; i++) {
Press_ReadAll();
for (int j=0; j<6; j++) {
P_sum[j] += Press_Data[j];
}
delay(1);
}
//write to EEPROM
for (int i=0; i<6; i++) {
P_ave = float(P_sum[i])/10.0;
lowbyte = ((P_ave >> 0) & 0xFF);
highbyte = ((P_ave >> 8) & 0xFF);
EEPROM.write(i*2, lowbyte);
EEPROM.write(i*2+1, highbyte);
}
}
void LoadPressureSensorCalibration() {
int calib;
byte lowbyte,highbyte;
Logln_p("Loading Pressure Sensor Calibrations:");
for (int i=0; i<6; i++) {
byte lowByte = EEPROM.read(i*2);
byte highByte = EEPROM.read(i*2 + 1);
Press_Calib[i] = ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
Log_p("P");
Log(i);
Log_p(": ");
Logln(Press_Calib[i]);
}
}
void UpdateCalibratedPressure() {
for (int i = 0; i<6; i++) {
Press[i] = Press_Data[i]-Press_Calib[i];
}
}