Livello Serbatoio v0.13
This project realizes a simple device to monitor the water level in a tank.
|
Functions | |
int32_t | compare_float (const float64_t x, const float64_t y, const float64_t th) |
Determines if two float values are equal. | |
int32_t | round_float_value (const float64_t x) |
Round the given float value to the nearest integer. | |
void | initialize (void) |
Initializes all variables. | |
float64_t | compute_liters (float64_t read_distance) |
Computes the volume of water in the tank. | |
float64_t | compute_percentage (float64_t read_liters) |
Computes the percentage of filling of the tank. | |
void | turn_on_lcd_light (void) |
Turns on the LCD backlight. | |
void | turn_off_lcd_light (void) |
Turns off the LCD backlight. | |
void | print_error (void) |
Prints an error message to LCD if not in debug mode. | |
void | show_err_code_debug (void) |
Shows the current error code to LCD (only in debug mode). | |
void | update_lcd_debug (const float64_t distance_to_print) |
Updates the LCD. | |
void | monitorReadings (void) |
float64_t | measure_level (void) |
Executes a measurement of water level. | |
void | control_led (const float64_t water_percentage) |
Controls the LED status depending on water level. | |
float64_t | sanitize_data (const float64_t data, const float64_t min_val, const float64_t max_val, const float64_t min_threshold, const float64_t max_threshold) |
Sanitizes the input value and contraints it in specified valid range. | |
void | update_lcd (const float64_t water_percentage, const float64_t liters) |
Updates the LCD with the actual parameters if needed. | |
void | autotest (void) |
Executes an autotest of LCD and LED. | |
void | print_stat (String str, const uint32_t stat) |
Prints on LCD the consumption statistic passed. | |
void | show_version (void) |
Prints the SW version on LCD. | |
void | show_params (void) |
Prints the tank parameters (diameter, number of tanks, max water heigh, max total capacity). | |
void | show_stats (void) |
Prints on LCD all the statistics. | |
void | enter_debug (void) |
Changes operative mode to DEBUG. | |
void | exit_debug (void) |
Changes operative mode to NORMAL. | |
void | button_interval_6_handle (void) |
Actions for sixth menu slot. | |
void | button_interval_5_handle (void) |
Actions for fifth menu slot. | |
void | button_interval_4_handle (void) |
Actions for fourth menu slot. | |
void | button_interval_3_handle (void) |
Actions for third menu slot. | |
void | button_interval_2_handle (void) |
Actions for second menu slot. | |
void | button_interval_1_handle (void) |
Actions for first menu slot. | |
void | show_menu_options (const uint32_t btn_press_time) |
Prints on LCD the menu options based on button press time. | |
void | do_menu_actions (const uint32_t btn_press_time) |
Performs the menu associated actions based on button press time. | |
void | manage_button (void) |
Manages the button events. | |
|
inline |
Executes an autotest of LCD and LED.
|
inline |
Actions for first menu slot.
|
inline |
Actions for second menu slot.
|
inline |
Actions for third menu slot.
|
inline |
Actions for fourth menu slot.
|
inline |
Actions for fifth menu slot.
|
inline |
Actions for sixth menu slot.
Determines if two float values are equal.
[in] | x | The first value. |
[in] | y | The second value. |
[in] | th | The threshold. |
x
and y
is below th
). Computes the volume of water in the tank.
See below for details on computation.
sensor +----| W |----+ --- TANK_HEIGHT_CM | | | } | (distance) | > SENSOR_DISTANCE_CM | | | } ----------------------> WATER_MAX_HEIGHT_CM | | | | V | ----------------------> current water level | | | | ----------------------> level 0 real distance = distance - SENSOR_DISTANCE_CM
[in] | read_distance | The water distance from sensor. |
Computes the percentage of filling of the tank.
It uses the most recent reading and the maximum capacity computed in setup.
[in] | read_liters | The volume of water read. |
|
inline |
Controls the LED status depending on water level.
If the tank filling is under LOW_LEVEL_THRESHOLD but over EMPTY_LEVEL_THRESHOLD turns on the LED. If the tank filling is under EMPTY_LEVEL_THRESHOLD makes the LED to blink. In all other cases the LED is off.
[in] | water_percentage | The percentage of filling of the tank (in range [0, 100]). |
|
inline |
Performs the menu associated actions based on button press time.
[in] | btn_press_time | Time since button is kept pressed. |
|
inline |
Changes operative mode to DEBUG.
|
inline |
Changes operative mode to NORMAL.
|
inline |
Initializes all variables.
|
inline |
Manages the button events.
|
inline |
Executes a measurement of water level.
Activates the ultrasonic sensor and applies the needed corrections (e.g. calibration).
|
inline |
|
inline |
Prints an error message to LCD if not in debug mode.
|
inline |
Prints on LCD the consumption statistic passed.
Follows the format:
|----------------| |< str >| |Tot. <stat> L | |----------------|
[in] | str | The statistic title. |
[in] | stat | The statistic value. |
|
inline |
Round the given float value to the nearest integer.
[in] | x | The value. |
|
inline |
Sanitizes the input value and contraints it in specified valid range.
If data
is under min_threshold
it returns min_val
. If data
is over max_threshold
it returns max_val
. If in range it returns data
.
[in] | data | The value to be sanitized. |
[in] | min_val | The minimum value in the admissible range. |
[in] | max_val | The maximum value in the admissible range. |
[in] | min_threshold | The lowest threshold value. |
[in] | max_threshold | The highest threshold value. |
min_val
, max_val
].
|
inline |
Shows the current error code to LCD (only in debug mode).
Implemented layout:
|----------------| |XXXXXXXXXXX e:XX| |XXXXXXXXXXXXXXXX| |----------------|
|
inline |
Prints on LCD the menu options based on button press time.
[in] | btn_press_time | Time since button is kept pressed. |
|
inline |
Prints the tank parameters (diameter, number of tanks, max water heigh, max total capacity).
Follows the format:
|----------------| |D:xxxxx N:xx | |H:xxxxx C:xxxxx | |----------------|
|
inline |
Prints on LCD all the statistics.
Prints consumptions since:
|
inline |
Prints the SW version on LCD.
Follows the format:
|----------------| | Versione: | | <num_version> | |----------------|
|
inline |
Turns off the LCD backlight.
Lowers the backlight digital pin.
|
inline |
Turns on the LCD backlight.
Raises the backlight digital pin and activates the timer to turn off the LCD backlight.
Updates the LCD with the actual parameters if needed.
The data are printed as follows:
|----------------| | xxxx L yyy % | | ############## | |----------------| ex: |----------------| | 876 L 87 % | | ############ | |----------------| |----------------| | xxxx L yyy % | | ## Riserva | |----------------| |----------------| | xxxx L yyy % | | Vuoto | |----------------| <xxxx> = [0, 9999] L <yyy> = [0, 100] % # X 16 => 0 = 0%, 16 = 100%
[in] | water_percentage | The tank filling percentage. |
[in] | liters | The water volume in liters. |
|
inline |
Updates the LCD.
Used only in debug mode.
[in] | distance_to_print | The distance from the water in centimeters. |