HomeWaterLeaksDetection
LCDController Class Reference

#include <LCDController.h>

Public Member Functions

void update () override
 Updates the state of the class. More...
 
void addItem (IDisplayable *item)
 Adds another source of data for the LCD display (another class) More...
 

Static Public Member Functions

static LCDControllergetInstance ()
 Returns the instance of the class. More...
 

Private Member Functions

 LCDController ()
 Constructor of the class. More...
 
 LCDController (LCDController const &)
 Copy constructor of the class. More...
 
LCDControlleroperator= (LCDController const &)
 Assignment operator of the class. More...
 

Private Attributes

LiquidCrystal_I2C lcd = {0x27, 20, 4}
 0x27 - address of the [20x4] LCD on I2C More...
 
std::vector< IDisplayable * > items
 collection of classes implementing the interface IDisplayable More...
 
TimePeriod delay = SEC_TO_MILLIS(3)
 delay between displaying two pages More...
 
int index
 index of the current page More...
 

Static Private Attributes

static LCDControllerinstance = NULL
 the instance of the class More...
 

Detailed Description

Author
silhavyj A17B0362P

This class works as a controller for the LCD display. It holds a collection of classes capable of displaying information on the display. Each class gets repeatedly to display its content for a period of 3s.

Definition at line 32 of file LCDController.h.

Constructor & Destructor Documentation

◆ LCDController() [1/2]

LCDController::LCDController ( )
private

Constructor of the class.

Definition at line 5 of file LCDController.cpp.

5  {
6  lcd.begin(); // start the LCD
7  index = 0; // index of the 1st page
8 }

References index, and lcd.

Referenced by getInstance().

◆ LCDController() [2/2]

LCDController::LCDController ( LCDController const &  )
inlineprivate

Copy constructor of the class.

Definition at line 51 of file LCDController.h.

51 {};

Member Function Documentation

◆ addItem()

void LCDController::addItem ( IDisplayable item)

Adds another source of data for the LCD display (another class)

Parameters
itemclass to be added as another page

Definition at line 16 of file LCDController.cpp.

16  {
17  items.push_back(item);
18 }

References items.

Referenced by setup().

◆ getInstance()

LCDController * LCDController::getInstance ( )
static

Returns the instance of the class.

If the instance has not been created, it will create it and then return it.

Returns
the instance of the class

Definition at line 10 of file LCDController.cpp.

10  {
11  if (instance == NULL)
12  instance = new LCDController;
13  return instance;
14 }

References instance, and LCDController().

Referenced by setup().

◆ operator=()

LCDController& LCDController::operator= ( LCDController const &  )
inlineprivate

Assignment operator of the class.

Definition at line 54 of file LCDController.h.

54 { return *this; }

◆ update()

void LCDController::update ( )
overridevirtual

Updates the state of the class.

If the period of 3s has passed, it will display the content of the next page.

Implements IControllable.

Definition at line 20 of file LCDController.cpp.

20  {
21  String row;
22 
23  // test if it's time to switch
24  // on to another page
25  if (delay.isActive()) {
26  // test if there's actually something
27  // to display
28  if (items.size() == 0)
29  return;
30 
31  lcd.clear(); // clear up the LCD
32 
33  // display all 4 rows of the current
34  // page on the LCD display
35  for (int i = 0; i < LCD_ROWS; i++) {
36  row = items[index]->getRow(i);
37  lcd.setCursor(0, i);
38  lcd.print(row);
39  }
40  // increment the page counter
41  index++;
42  if (index == (int)items.size())
43  index = 0;
44  }
45 }

References delay, index, TimePeriod::isActive(), items, lcd, and LCD_ROWS.

Member Data Documentation

◆ delay

TimePeriod LCDController::delay = SEC_TO_MILLIS(3)
private

delay between displaying two pages

Definition at line 42 of file LCDController.h.

Referenced by update().

◆ index

int LCDController::index
private

index of the current page

Definition at line 43 of file LCDController.h.

Referenced by LCDController(), and update().

◆ instance

LCDController * LCDController::instance = NULL
staticprivate

the instance of the class

Definition at line 39 of file LCDController.h.

Referenced by getInstance().

◆ items

std::vector<IDisplayable *> LCDController::items
private

collection of classes implementing the interface IDisplayable

Definition at line 41 of file LCDController.h.

Referenced by addItem(), and update().

◆ lcd

LiquidCrystal_I2C LCDController::lcd = {0x27, 20, 4}
private

0x27 - address of the [20x4] LCD on I2C

Definition at line 40 of file LCDController.h.

Referenced by LCDController(), and update().


The documentation for this class was generated from the following files:
LCDController::lcd
LiquidCrystal_I2C lcd
0x27 - address of the [20x4] LCD on I2C
Definition: LCDController.h:40
TimePeriod::isActive
int isActive()
Returns information if the period of time has passed.
Definition: TimePeriod.cpp:7
LCD_ROWS
#define LCD_ROWS
number of rows on the LCD display
Definition: LCDController.h:22
LCDController::delay
TimePeriod delay
delay between displaying two pages
Definition: LCDController.h:42
LCDController::instance
static LCDController * instance
the instance of the class
Definition: LCDController.h:39
LCDController::LCDController
LCDController()
Constructor of the class.
Definition: LCDController.cpp:5
LCDController::index
int index
index of the current page
Definition: LCDController.h:43
LCDController::items
std::vector< IDisplayable * > items
collection of classes implementing the interface IDisplayable
Definition: LCDController.h:41