forked from adacho/LCDMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCDMenu.cpp
74 lines (66 loc) · 1.17 KB
/
LCDMenu.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
70
71
72
73
74
#include <LiquidCrystal.h>
#include "LCDMenu.h"
LCDMenu::LCDMenu(String newName, LiquidCrystal* newLCD)
{
setName(newName);
setLCD(newLCD);
menuFirst = NULL;
menuLast = NULL;
}
void LCDMenu::setName(String newName)
{
Name = newName;
}
LCDMenuItem* LCDMenu::next()
{
menuCurrent=menuCurrent->getNext();
return menuCurrent;
}
LCDMenuItem* LCDMenu::prev()
{
menuCurrent=menuCurrent->getPrev();
return menuCurrent;
}
void LCDMenu::addMenuItem(LCDMenuItem* item)
{
if (item != NULL)
{
if (menuFirst == NULL)
{
menuFirst = menuLast = menuCurrent = item;
menuFirst->setPrev(item);
menuFirst->setNext(item);
}
else
{
menuLast->setNext(item);
item->setPrev(menuLast);
item->setNext(menuFirst);
menuFirst->setPrev(item);
menuLast=item;
}
}
}
void LCDMenu::setLCD(LiquidCrystal* newLCD)
{
LCD=newLCD;
}
LiquidCrystal* LCDMenu::getLCD()
{
return LCD;
}
void LCDMenu::selectOption()
{
menuCurrent->executeAction();
}
void LCDMenu::display()
{
LCD->clear();
LCD->setCursor(0,0);
LCD->print(">" + menuCurrent->getName());
if (menuCurrent->getNext() != menuCurrent)
{
LCD->setCursor(1,1);
LCD->print(menuCurrent->getNext()->getName());
}
}