calibration stuff
This commit is contained in:
@ -35,7 +35,11 @@ Thermometer thermometer[NUM_OF_CHANNELS];
|
|||||||
LED led;
|
LED led;
|
||||||
Metro secondTick = Metro(1000);
|
Metro secondTick = Metro(1000);
|
||||||
uint32_t uptimeSeconds = 0;
|
uint32_t uptimeSeconds = 0;
|
||||||
bool calibrationDone = false;
|
|
||||||
|
|
||||||
|
typedef enum { e_CAL_IDLE, e_CAL_RUNNING, e_CAL_SET, e_CAL_COMPLETE } tCalibrationState;
|
||||||
|
|
||||||
|
tCalibrationState calibrationState = e_CAL_IDLE;
|
||||||
uint16_t calibrationCycleCnt = 0;
|
uint16_t calibrationCycleCnt = 0;
|
||||||
float calibrationValueSum[NUM_OF_CHANNELS];
|
float calibrationValueSum[NUM_OF_CHANNELS];
|
||||||
|
|
||||||
@ -118,9 +122,32 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((digitalRead(CAL_ENABLE) != 0) && (! calibrationDone)) {
|
if ((digitalRead(CAL_ENABLE) != 0) &&
|
||||||
|
((digitalRead(CAL_OFFSET_ENABLE) != 0) || (digitalRead(CAL_FACTOR_ENABLE) != 0)) &&
|
||||||
|
(calibrationState != e_CAL_COMPLETE)) {
|
||||||
led.toggle();
|
led.toggle();
|
||||||
calibrationCycleCnt++;
|
|
||||||
|
switch (calibrationState) {
|
||||||
|
case e_CAL_IDLE:
|
||||||
|
calibrationState = e_CAL_RUNNING;
|
||||||
|
break;
|
||||||
|
case e_CAL_RUNNING:
|
||||||
|
calibrationCycleCnt++;
|
||||||
|
for (uint8_t i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
|
calibrationValueSum += ads1210[i].getValue();
|
||||||
|
}
|
||||||
|
if (calibrationCycleCnt >= CALIBRATION_CYCLES) {
|
||||||
|
calibrationState = e_CAL_SET;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case e_CAL_SET:
|
||||||
|
// calculate and set according to selected calibration mode
|
||||||
|
calibrationState = e_CAL_COMPLETE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
calibrationState = e_CAL_COMPLETE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((digitalRead(CAL_ENABLE) == 0) && (secondTick.check() == 1)) {
|
if ((digitalRead(CAL_ENABLE) == 0) && (secondTick.check() == 1)) {
|
||||||
|
Reference in New Issue
Block a user