-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageHandler.cpp
88 lines (79 loc) · 2.03 KB
/
MessageHandler.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
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* MessageHandler.cpp
*
* Created: 5/2/2014 11:40:41 AM
* Author: Ketil Wright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MessagePump.h"
#include "MessageHandler.h"
#include "LcdImpl.h"
// Base class ctor just initializes OK on bottom line of menu[].
IMessageHandler::IMessageHandler(MessagePump* _pump)
:
m_pump(_pump),
m_caretCol(0),
m_caretRow(0)
{
//for(unsigned int line = 0; line < sizeof(menu) / sizeof(menu[0]); line++) menu[line] = NULL;
memset(menu, 0, sizeof(menu)); // 33076
}
void IMessageHandler::printMenuItem(uint8_t col, uint8_t item)
{
g_print->setCursor(col, 0);
g_print->print(menu[item]);
}
// Draws the menu text, indenting all lines but
// the 1st by one column
void IMessageHandler::show()
{
g_print->clear();
if(menu[0])
{
g_print->setCursor(0, 0);
g_print->print(menu[0]);
}
if(menu[1])
{
g_print->setCursor(8, 0);
g_print->print(menu[1]);
}
if(menu[2])
{
g_print->setCursor(0, 1);
g_print->print(menu[2]);
}
if(menu[3])
{
g_print->setCursor(8, 1);
g_print->print(menu[2]);
}
m_caretCol = 0;
}
// Draws or hides the caret.
void IMessageHandler::showCaret(bool show)
{
g_print->setCursor(m_caretCol, m_caretRow);
if(show) g_print->cursor();
else g_print->noCursor();
}
// Redraws the caret at the specified location
void IMessageHandler::moveCaret(uint8_t col, uint8_t row)
{
showCaret(false);
m_caretCol = col;
m_caretRow = row;
showCaret(true);
}