HomeWaterLeaksDetection
LCDController.cpp
Go to the documentation of this file.
1 #include "LCDController.h"
2 
4 
6  lcd.begin(); // start the LCD
7  index = 0; // index of the 1st page
8 }
9 
11  if (instance == NULL)
12  instance = new LCDController;
13  return instance;
14 }
15 
17  items.push_back(item);
18 }
19 
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 }
46 
47 #ifdef DEBUG
48  const String LCDController::getLogID() const { return "[LCD]"; }
49 
50  const String LCDController::getLogDescription() const {
51  String content = "";
52  if (items.size() == 0)
53  return content;
54 
55  for (int i = 0; i < LCD_ROWS; i++) {
56  content += items[index]->getRow(i);
57  if (i < LCD_ROWS - 1)
58  content += "; ";
59  }
60  return "[" + content + "]";
61  }
62 #endif
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
Definition: LCDController.h:36
LCDController::addItem
void addItem(IDisplayable *item)
Adds another source of data for the LCD display (another class)
Definition: LCDController.cpp:16
LCDController::delay
TimePeriod delay
delay between displaying two pages
Definition: LCDController.h:42
LCDController.h
LCDController::instance
static LCDController * instance
the instance of the class
Definition: LCDController.h:39
IDisplayable
Definition: IDisplayable.h:12
LCDController::update
void update() override
Updates the state of the class.
Definition: LCDController.cpp:20
LCDController::getInstance
static LCDController * getInstance()
Returns the instance of the class.
Definition: LCDController.cpp:10
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