Livello Serbatoio v0.13
This project realizes a simple device to monitor the water level in a tank.
Loading...
Searching...
No Matches
SW Functions

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.
 

Detailed Description

Function Documentation

◆ autotest()

void autotest ( void )
inline

Executes an autotest of LCD and LED.

◆ button_interval_1_handle()

void button_interval_1_handle ( void )
inline

Actions for first menu slot.

◆ button_interval_2_handle()

void button_interval_2_handle ( void )
inline

Actions for second menu slot.

◆ button_interval_3_handle()

void button_interval_3_handle ( void )
inline

Actions for third menu slot.

◆ button_interval_4_handle()

void button_interval_4_handle ( void )
inline

Actions for fourth menu slot.

◆ button_interval_5_handle()

void button_interval_5_handle ( void )
inline

Actions for fifth menu slot.

◆ button_interval_6_handle()

void button_interval_6_handle ( void )
inline

Actions for sixth menu slot.

◆ compare_float()

int32_t compare_float ( const float64_t x,
const float64_t y,
const float64_t th )
inline

Determines if two float values are equal.

Parameters
[in]xThe first value.
[in]yThe second value.
[in]thThe threshold.
Returns
0 if different, 1 if equal (distance between x and y is below th).

◆ compute_liters()

float64_t compute_liters ( float64_t read_distance)
inline

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
Parameters
[in]read_distanceThe water distance from sensor.
Returns
The volume in liters.

◆ compute_percentage()

float64_t compute_percentage ( float64_t read_liters)
inline

Computes the percentage of filling of the tank.

It uses the most recent reading and the maximum capacity computed in setup.

Parameters
[in]read_litersThe volume of water read.
Returns
The filling percentage in range [0, 100].

◆ control_led()

void control_led ( const float64_t water_percentage)
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.

Parameters
[in]water_percentageThe percentage of filling of the tank (in range [0, 100]).

◆ do_menu_actions()

void do_menu_actions ( const uint32_t btn_press_time)
inline

Performs the menu associated actions based on button press time.

Parameters
[in]btn_press_timeTime since button is kept pressed.

◆ enter_debug()

void enter_debug ( void )
inline

Changes operative mode to DEBUG.

◆ exit_debug()

void exit_debug ( void )
inline

Changes operative mode to NORMAL.

◆ initialize()

void initialize ( void )
inline

Initializes all variables.

◆ manage_button()

void manage_button ( void )
inline

Manages the button events.

◆ measure_level()

float64_t measure_level ( void )
inline

Executes a measurement of water level.

Activates the ultrasonic sensor and applies the needed corrections (e.g. calibration).

Returns
The distance from water in centimeters or -1 in case of errors.

◆ monitorReadings()

void monitorReadings ( void )
inline

◆ print_error()

void print_error ( void )
inline

Prints an error message to LCD if not in debug mode.

◆ print_stat()

void print_stat ( String str,
const uint32_t stat )
inline

Prints on LCD the consumption statistic passed.

Follows the format:

 |----------------| 
 |<      str     >|
 |Tot. <stat>   L |
 |----------------|
Parameters
[in]strThe statistic title.
[in]statThe statistic value.

◆ round_float_value()

int32_t round_float_value ( const float64_t x)
inline

Round the given float value to the nearest integer.

Parameters
[in]xThe value.
Returns
The rounded integer value.

◆ sanitize_data()

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 )
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.

Parameters
[in]dataThe value to be sanitized.
[in]min_valThe minimum value in the admissible range.
[in]max_valThe maximum value in the admissible range.
[in]min_thresholdThe lowest threshold value.
[in]max_thresholdThe highest threshold value.
Returns
The value in range [ min_val, max_val ].

◆ show_err_code_debug()

void show_err_code_debug ( void )
inline

Shows the current error code to LCD (only in debug mode).

Implemented layout:

         |----------------|
         |XXXXXXXXXXX e:XX|
         |XXXXXXXXXXXXXXXX|
         |----------------|

◆ show_menu_options()

void show_menu_options ( const uint32_t btn_press_time)
inline

Prints on LCD the menu options based on button press time.

Parameters
[in]btn_press_timeTime since button is kept pressed.

◆ show_params()

void show_params ( void )
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 |
 |----------------|

◆ show_stats()

void show_stats ( void )
inline

Prints on LCD all the statistics.

Prints consumptions since:

  • 1 hour;
  • 12 hours;
  • 1 day;
  • 3 days.

◆ show_version()

void show_version ( void )
inline

Prints the SW version on LCD.

Follows the format:

 |----------------| 
 | Versione:      |
 | <num_version>  |
 |----------------|

◆ turn_off_lcd_light()

void turn_off_lcd_light ( void )
inline

Turns off the LCD backlight.

Lowers the backlight digital pin.

◆ turn_on_lcd_light()

void turn_on_lcd_light ( void )
inline

Turns on the LCD backlight.

Raises the backlight digital pin and activates the timer to turn off the LCD backlight.

◆ update_lcd()

void update_lcd ( const float64_t water_percentage,
const float64_t liters )
inline

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%
Parameters
[in]water_percentageThe tank filling percentage.
[in]litersThe water volume in liters.

◆ update_lcd_debug()

void update_lcd_debug ( const float64_t distance_to_print)
inline

Updates the LCD.

Used only in debug mode.

Parameters
[in]distance_to_printThe distance from the water in centimeters.