-
Notifications
You must be signed in to change notification settings - Fork 11
/
Display.cpp
69 lines (53 loc) · 1.42 KB
/
Display.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* "Drinks" RFID Terminal
* Buy sodas with your company badge!
*
* Benoit Blanchon 2014 - MIT License
* https://github.com/bblanchon/DrinksRfidTerminal
*/
#include <Arduino.h>
#include <LiquidCrystal.h>
#include "Display.h"
#include "Pins.h"
#define SCREEN_COLUMNS 20
#define SELECTION_MAX_LENGTH (SCREEN_COLUMNS-2)
static LiquidCrystal lcd(PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7);
void Display::begin()
{
pinMode(PIN_LCD_LIGHT, OUTPUT);
lcd.begin(SCREEN_COLUMNS, 2);
delay(100);
}
void Display::setText(int line, const char* s)
{
lcd.setCursor(0, line);
int i;
for (i = 0; s[i] && i < SCREEN_COLUMNS; i++)
lcd.print(s[i]);
for (; i < SCREEN_COLUMNS; i++)
lcd.print(' ');
}
void Display::setSelection(int line, const char* s)
{
int length = strnlen(s, SELECTION_MAX_LENGTH);
int leftPadding = (SELECTION_MAX_LENGTH - length) / 2;
int rightPadding = SELECTION_MAX_LENGTH - length - leftPadding;
lcd.setCursor(0, line);
lcd.print('<');
for (int i = 0; i < leftPadding; i++)
lcd.print(' ');
lcd.print(s);
for (int i = 0; i < rightPadding; i++)
lcd.print(' ');
lcd.print('>');
}
void Display::setBusy()
{
setText(0, "Please wait...");
setText(1, "");
}
void Display::setError()
{
setText(0, "ERROR !");
setText(1, "");
}