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

Helper class to write on LCD. More...

Public Member Functions

 LcdHelper (void)
 Class default constructor.
 
void begin (LiquidCrystal *const lcd, const int32_t backlight_dpin=-1)
 Initializes this instance with current LCD instance.
 
void turn_on_backlight (void)
 Turns on the LCD backlight if configured.
 
void turn_off_backlight (void)
 Turns off the LCD backlight if configured.
 
void clear (void)
 Clears the current LCD content (the internal buffer) and resets the cursor position.
 
void setCursor (const uint16_t c, const uint16_t r)
 Sets the cursor position if valid (in LCD sizes).
 
void home (void)
 Sets the cursor position to (0, 0).
 
void print (const char *str, const uint16_t str_length=LCD_COLS)
 Prints a string to the internal buffer without exceeding the limits of the LCD.
 
void print (const int32_t number)
 Prints a number to the LCD.
 
void print (const String &str)
 Prints a String to the LCD.
 
void print (const int16_t number)
 Prints a integer number to the LCD.
 
void print (const uint16_t number)
 Prints a integer number to the LCD.
 
void print (const float64_t number)
 Prints a floating point number to the LCD.
 
void write (const int32_t special_char_index)
 Writes a special character to the LCD.
 
void update_lcd (void)
 Updates the LCD HW with the current written data.
 

Private Member Functions

bool is_special_symbol (const uint16_t r, const uint16_t c)
 Checks if the symbol in the given position is special or not.
 
bool need_update (void)
 Checks if the LCD HW view needs an update.
 

Private Attributes

uint16_t cursor_r
 
uint16_t cursor_c
 
int32_t backlight_digital_pin
 
char lcd_matrix [LCD_ROWS][LCD_COLS]
 
char last_lcd_matrix [LCD_ROWS][LCD_COLS]
 
bool special_char_map [LCD_ROWS][LCD_COLS]
 
bool last_special_char_map [LCD_ROWS][LCD_COLS]
 
LiquidCrystal * lcd_instance
 

Static Private Attributes

static const char EMPTY_CHAR = ' '
 

Detailed Description

Helper class to write on LCD.

The purpose is to try the optimization of writings on LCD to prevent unwanted screen flickering. It uses a buffer to keep the current LCD content. When the user writes using the "print" or "write" methods, data are written in the buffer. The user has in charge the responsibility to update the LCD view by explicitly invoking the "update_lcd" method. The latter verifies which characters have been changed from previous view and updates only the different ones.

Constructor & Destructor Documentation

◆ LcdHelper()

LcdHelper::LcdHelper ( void )
inline

Class default constructor.

Member Function Documentation

◆ begin()

void LcdHelper::begin ( LiquidCrystal *const lcd,
const int32_t backlight_dpin = -1 )
inline

Initializes this instance with current LCD instance.

Parameters
[in]lcdThe pointer to the LiquidCrystal lcd instance.
[in]backlight_dpinThe digital pin number used to control LCD backlight (default: -1, if not controllable).

◆ clear()

void LcdHelper::clear ( void )
inline

Clears the current LCD content (the internal buffer) and resets the cursor position.

◆ home()

void LcdHelper::home ( void )
inline

Sets the cursor position to (0, 0).

◆ is_special_symbol()

bool LcdHelper::is_special_symbol ( const uint16_t r,
const uint16_t c )
inlineprivate

Checks if the symbol in the given position is special or not.

Checks if the symbol is a number in 0-9 and it flagged true in special_char_map.

Parameters
[in]rThe row.
[in]cThe column.
Returns
true if the symbol in ( r, c ) is special or false otherwise.

◆ need_update()

bool LcdHelper::need_update ( void )
inlineprivate

Checks if the LCD HW view needs an update.

Checks if there is a symbol different from the currently displayed data

Returns
true if there is a difference to display or false otherwise.

◆ print() [1/6]

void LcdHelper::print ( const char * str,
const uint16_t str_length = LCD_COLS )
inline

Prints a string to the internal buffer without exceeding the limits of the LCD.

Parameters
[in]strThe string (char pointer).
[in]str_lengthThe string length.

◆ print() [2/6]

void LcdHelper::print ( const float64_t number)
inline

Prints a floating point number to the LCD.

Parameters
[in]numberThe number to write.

◆ print() [3/6]

void LcdHelper::print ( const int16_t number)
inline

Prints a integer number to the LCD.

Parameters
[in]numberThe number to write.

◆ print() [4/6]

void LcdHelper::print ( const int32_t number)
inline

Prints a number to the LCD.

Parameters
[in]numberThe integer number to write.

◆ print() [5/6]

void LcdHelper::print ( const String & str)
inline

Prints a String to the LCD.

Parameters
[in]strThe string to write.

◆ print() [6/6]

void LcdHelper::print ( const uint16_t number)
inline

Prints a integer number to the LCD.

Parameters
[in]numberThe number to write.

◆ setCursor()

void LcdHelper::setCursor ( const uint16_t c,
const uint16_t r )
inline

Sets the cursor position if valid (in LCD sizes).

Parameters
[in]cThe column index.
[in]rThe row index.

◆ turn_off_backlight()

void LcdHelper::turn_off_backlight ( void )
inline

Turns off the LCD backlight if configured.

◆ turn_on_backlight()

void LcdHelper::turn_on_backlight ( void )
inline

Turns on the LCD backlight if configured.

◆ update_lcd()

void LcdHelper::update_lcd ( void )
inline

Updates the LCD HW with the current written data.

◆ write()

void LcdHelper::write ( const int32_t special_char_index)
inline

Writes a special character to the LCD.

It writes the number on the buffer and set to true the special_char_map matrix in the corresponding position on screen.

Parameters
[in]special_char_indexThe special character number.

Member Data Documentation

◆ backlight_digital_pin

int32_t LcdHelper::backlight_digital_pin
private

◆ cursor_c

uint16_t LcdHelper::cursor_c
private

◆ cursor_r

uint16_t LcdHelper::cursor_r
private

◆ EMPTY_CHAR

const char LcdHelper::EMPTY_CHAR = ' '
staticprivate

◆ last_lcd_matrix

char LcdHelper::last_lcd_matrix[LCD_ROWS][LCD_COLS]
private

◆ last_special_char_map

bool LcdHelper::last_special_char_map[LCD_ROWS][LCD_COLS]
private

◆ lcd_instance

LiquidCrystal* LcdHelper::lcd_instance
private

◆ lcd_matrix

char LcdHelper::lcd_matrix[LCD_ROWS][LCD_COLS]
private

◆ special_char_map

bool LcdHelper::special_char_map[LCD_ROWS][LCD_COLS]
private

The documentation for this class was generated from the following file: