-
Notifications
You must be signed in to change notification settings - Fork 0
/
calibrate.h
47 lines (39 loc) · 1.13 KB
/
calibrate.h
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
#ifndef CALIBRATE_H_
#define CALIBRATE_H_
#define CALIBRATE
#ifdef CALIBRATE
extern uint16_t EEMEM EE_FullHeight;
extern volatile uint16_t FullHeight;
extern volatile uint16_t distance; // decalred as global for debug
inline uint16_t calibrateFullHeight()
{
uint16_t result = 0;
measureDistance(&result);
if (result > TOO_FAR_HEIGHT)
return CALBIRATION_SENSOR_TOO_FAR;
else if (result < TOO_CLOSE_HEIGHT)
return CALBIRATION_SENSOR_TOO_CLOSE;
// to make current value as 98%
FullHeight = FULL_WATER * 102/100 + result;
eeprom_write_word(&EE_FullHeight, FullHeight);
distance = result;
return 0;
}
#endif
volatile uint8_t calibrateRequested = 0;
inline void calibrate()
{
#ifdef CALIBRATE
if (!calibrateRequested)
return;
uint16_t error_code = calibrateFullHeight();
if (error_code)
{
flashValue(error_code); // display error code infinitly (until reset)
pushError(error_code - 8100);
}
flashValue(distance); // display distance for 1 sec then clear sceen
flashValue(FullHeight); // display full height for 1 sec then clear sceen
#endif
}
#endif