-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcalibrate_handler.cpp
123 lines (118 loc) · 3.65 KB
/
calibrate_handler.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "DB_CG_scale-master.h"
int CalibrateHandler::handle(int button, I2C_LCD *lcd, HX711 *frontCell, HX711 *rearCell, EepromValues *eepromValues) {
static int step = 0;
static float calibrationWeight;
static long rawEmpty;
static long rawWeighted;
if (status == WAITING)
{
status = WORKING;
step = 0;
}
switch (step) {
case 0:
lcd->printrow(0, "Calibrate?");
lcd->printrow(1, "Btn 1 = Yes");
if ((button == BUTTON2) || (button == BUTTON3)) {
status = WAITING;
return MAIN_ID;
}
break;
case 1:
lcd->printrow(0, "Target wt (100s)");
lcd->printrow(1, String(eepromValues->calibrationWeight,0));
switch (button)
{
case BUTTON2:
eepromValues->calibrationWeight += 100;
break;
case BUTTON3:
eepromValues->calibrationWeight -= 100;
break;
}
break;
case 2:
lcd->printrow(0, "Target wt (10s)");
lcd->printrow(1, String(eepromValues->calibrationWeight,0));
switch (button)
{
case BUTTON2:
eepromValues->calibrationWeight += 10;
break;
case BUTTON3:
eepromValues->calibrationWeight -= 10;
break;
}
break;
case 3:
lcd->printrow(0, "Target wt (1s)");
lcd->printrow(1, String(eepromValues->calibrationWeight,0));
switch (button)
{
case BUTTON2:
eepromValues->calibrationWeight += 1;
break;
case BUTTON3:
eepromValues->calibrationWeight -= 1;
break;
}
break;
case 4:
lcd->printrow(0, "F. cradle empty?");
lcd->printrow(1, "Btn 1 = Ready");
if (button == BUTTON1) {
lcd->printrow(1, "Zeroing front...");
rawEmpty = frontCell->read_average(CELL_SAMPLE_ITERATIONS * 4);
Serial.println("Front rawEmpty= " + String(rawEmpty));
}
break;
case 5:
lcd->printrow(0, "F. weighted?");
lcd->printrow(1, "Btn 1 = Ready");
if (button == BUTTON1) {
lcd->printrow(0, "Reading front");
lcd->printrow(1, "...");
rawWeighted = frontCell->read_average(CELL_SAMPLE_ITERATIONS * 4);
Serial.println("Front rawWeighted= " + String(rawWeighted));
eepromValues->frontScale = (rawWeighted - rawEmpty) / eepromValues->calibrationWeight;
Serial.println("Front scale: " + String(eepromValues->frontScale, 4));
frontCell->set_scale(eepromValues->frontScale);
}
break;
case 6:
lcd->printrow(0, "R. cradle empty?");
lcd->printrow(1, "Btn 1 = Ready");
if (button == BUTTON1) {
lcd->printrow(1, "Zeroing rear...");
rawEmpty = rearCell->read_average(CELL_SAMPLE_ITERATIONS * 4);
Serial.println("Rear rawEmpty= " + String(rawEmpty));
}
break;
case 7:
lcd->printrow(0, "R. weighted?");
lcd->printrow(1, "Btn 1 = Ready");
if (button == BUTTON1) {
lcd->printrow(0, "Reading rear");
lcd->printrow(1, "...");
rawWeighted = rearCell->read_average(CELL_SAMPLE_ITERATIONS * 4);
Serial.println("Rear rawWeighted= " + String(rawWeighted));
eepromValues->rearScale = (rawWeighted - rawEmpty) / eepromValues->calibrationWeight;
Serial.println("Rear scale: " + String(eepromValues->rearScale, 4));
rearCell->set_scale(eepromValues->rearScale);
}
break;
default:
lcd->printrow(0, "Saving values ...");
Eeprom::putValues(*eepromValues);
delay(500);
status = WAITING;
return MAIN_ID;
break;
}
switch (button) {
case BUTTON1:
step++;
break;
}
return CALIBRATE_ID;
}