forked from codemakeshare/Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuDisplay.cpp
More file actions
136 lines (121 loc) · 3.03 KB
/
MenuDisplay.cpp
File metadata and controls
136 lines (121 loc) · 3.03 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "MenuDisplay.h"
#include "conf.h"
void MenuDisplay::updateDisplay(Menu* currentMenu) {
if (!currentMenu->needsRedraw()) return;
char buffer[20];
//display->setTextSize(1);
//display->setTextColor(WHITE);
//display->clear();//Display();
#ifdef SSD128x32
display->setFont(Adafruit5x7);
#else
//display->setFont(&FreeMonoBold9pt7b);
display->setFont(Arial_bold_14);
#endif
#ifdef REVERSE
display->displayRemap(1);
#endif
display->setContrast(0);
uint8_t startIndex = currentMenu->getScrollOffset();
uint8_t active = currentMenu->getSelectedItem();
for (int i=0; i<4; i++) {
#ifdef SSD128x32
display->setCursor(0,i);
#else
display->setCursor(0,i*2);
#endif
//display->clearToEOL();
MenuItem* item = currentMenu->getItem(startIndex+i);
display->setInvertMode(0);
//display->setTextColor(WHITE, BLACK);
if (startIndex+i==active) {
//display->setCursor(0,12+i*15);
if (currentMenu->isActivated()) {
display->print("O ");
//display->setTextColor(BLACK, WHITE);
//display->fillRect(15, i*15, 128, 14, WHITE);
display->setInvertMode(1);
} else {
display->print("> ");
}
} else {
display->print(" ");
}
//display->setCursor(15,12+i*15);
#ifdef SSD128x32
display->setCursor(12,i);
#else
display->setCursor(12,i*2);
#endif
if (item!=NULL) {
item->getText(buffer);
display->print(buffer);
display->clearToEOL();
item->doneRedraw();
} else {
display->clearToEOL();
}
}
//print_float(inp, 4, 2);
//display->display();
currentMenu->doneRedraw();
}
#define MAX_DIGITS 10
void MenuDisplay::print_num_padded(int32_t c, char base, int padded_length, char padding_character)
{
char storage[MAX_DIGITS];
int32_t i = MAX_DIGITS;
int32_t cpos;
int j = 0;
cpos=abs(c);
do
{
i--;
storage[i] = cpos % base;
cpos = cpos / base;
} while((i >= 0) && (cpos > 0) );
/* Take Care of the sign (only for decimal numbers)*/
if(c < 0)
{
// add padding counting minus sign
for (j = 0; j<padded_length - (MAX_DIGITS - i) - 1; j++) {
display->print(padding_character);
}
display->print('-');
} else {
// add padding
for (j = 0; j<padded_length - (MAX_DIGITS - i); j++) {
display->print(padding_character);
}
}
/* i is the index of the last digit calculated */
/* Hence, there is no need to initialize i */
for( ; i<MAX_DIGITS; i++)
{
display->print((int32_t)storage[i]);
}
}
void MenuDisplay::print_float(float c, int before_digits, int after_digits)
{
int32_t i;
float num = c;
if (c<0)
{
display->print("-");
num=-c;
}
else
{
display->print(" ");
}
int32_t whole=abs(num);
float after=(num-(float)whole);
print_num_padded(whole, 10, before_digits, ' ');
display->print(".");
for (i=0; i<after_digits; i++)
{
after*=10;
display->print( (int32_t)after);
after=after-(int32_t)after;
}
}