-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMenuDisplay.cpp
More file actions
114 lines (104 loc) · 2.72 KB
/
MenuDisplay.cpp
File metadata and controls
114 lines (104 loc) · 2.72 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
#include "MenuDisplay.h"
void MenuDisplay::updateDisplay(Menu* currentMenu) {
if (!currentMenu->needsRedraw()) return;
char buffer[20];
//display->setTextSize(1);
//display->setTextColor(WHITE);
//display->clear();//Display();
//display->setFont(&FreeMonoBold9pt7b);
display->setFont(Arial_bold_14);
uint8_t startIndex = currentMenu->getScrollOffset();
uint8_t active = currentMenu->getSelectedItem();
for (int i=0; i<currentMenu->getMenuLines(); i++) {
display->setCursor(0,i*2);
//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);
display->setCursor(12,i*2);
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;
}
}