-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathInfoDisplayRender.hpp
More file actions
121 lines (109 loc) · 3.01 KB
/
InfoDisplayRender.hpp
File metadata and controls
121 lines (109 loc) · 3.01 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
#pragma once
#include <Arduino.h>
#include "OLEDDisplay.h"
#include "fonts128x64.h"
#include "../Configuration.hpp"
// Base class to implement a
class InfoDisplayRender
{
const static int MAX_CONSOLE_LINES = 16; // Maximum number of lines of text to buffer in console mode
const static int DISPLAY_CONSOLE_LINES = 6; // Number of lines to display in console mode
protected:
OLEDDisplay *_display;
long _lastNumCmds;
bool _consoleMode;
String _textList[MAX_CONSOLE_LINES];
int _curLine;
public:
InfoDisplayRender()
{
_consoleMode = true;
_curLine = 0;
for (int i = 0; i < MAX_CONSOLE_LINES; i++)
{
_textList[i] = "";
}
};
virtual void init()
{
_display->init();
#if (INFO_DISPLAY_UPSIDE_DOWN == 1)
_display->flipScreenVertically();
#endif
#if (INFO_DISPLAY_MIRRORED == 1)
_display->mirrorScreen();
#endif
_display->clear();
_display->displayOn();
};
OLEDDisplay *getDisplayDevice()
{
return _display;
};
virtual void renderScreen(void *context) = 0;
// Build the display from the mount
virtual void render(void (*drawContentFunction)(void *))
{
_display->clear();
if (drawContentFunction)
{
drawContentFunction(this);
}
if (_consoleMode)
{
// Console lines
int y = 21;
_display->setFont(Bitmap3x5);
// Start 6 lines back from current line and display next 6 lines
int indexStart = max(0, _curLine - DISPLAY_CONSOLE_LINES);
int indexEnd = min(indexStart + DISPLAY_CONSOLE_LINES, MAX_CONSOLE_LINES);
for (int i = indexStart; i < indexEnd; i++)
{
if (_textList[i].length() != 0)
{
String text = _textList[i];
text.toUpperCase();
_display->drawString(0, y, text);
}
y += 7;
}
}
else
{
}
_display->display();
};
virtual void setConsoleMode(bool active)
{
_consoleMode = active;
};
virtual int addConsoleText(const String &text, bool tinyFont = true)
{
int returnIndex = 0;
if (_curLine > MAX_CONSOLE_LINES - 1)
{
for (int i = 0; i < MAX_CONSOLE_LINES - 1; i++)
{
_textList[i] = _textList[i + 1];
}
_curLine = MAX_CONSOLE_LINES - 1;
_textList[_curLine] = text;
returnIndex = _curLine;
}
else
{
returnIndex = _curLine;
_textList[_curLine++] = text;
}
render(nullptr);
return returnIndex;
};
virtual void updateConsoleText(int line, String text)
{
if (line >= 0 && line < MAX_CONSOLE_LINES)
{
_textList[line] = text;
}
render(nullptr);
};
};