|
1 | 1 | #pragma once |
2 | 2 | #include <Arduino.h> |
3 | | - |
4 | | -class Mount; |
| 3 | +#include <String.h> |
| 4 | +#include "OLEDDisplay.h" |
| 5 | +#include "fonts128x64.h" |
| 6 | +#include "../Configuration.hpp" |
5 | 7 |
|
6 | 8 | // Base class to implement a |
7 | 9 | class InfoDisplayRender |
8 | 10 | { |
| 11 | + const static int MAX_CONSOLE_LINES = 16; // Maximum number of lines of text to buffer in console mode |
| 12 | + const static int DISPLAY_CONSOLE_LINES = 6; // Number of lines to display in console mode |
| 13 | + |
| 14 | +protected: |
| 15 | + OLEDDisplay *_display; |
| 16 | + long _lastNumCmds; |
| 17 | + bool _consoleMode; |
| 18 | + String _textList[MAX_CONSOLE_LINES]; |
| 19 | + int _curLine; |
| 20 | + |
9 | 21 | public: |
10 | | - InfoDisplayRender() {}; |
| 22 | + InfoDisplayRender() |
| 23 | + { |
| 24 | + _consoleMode = true; |
| 25 | + _curLine = 0; |
| 26 | + for (int i = 0; i < MAX_CONSOLE_LINES; i++) |
| 27 | + { |
| 28 | + _textList[i] = ""; |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + virtual void init() |
| 33 | + { |
| 34 | + _display->init(); |
| 35 | + _display->clear(); |
| 36 | + _display->displayOn(); |
| 37 | + }; |
| 38 | + |
| 39 | + OLEDDisplay *getDisplayDevice() |
| 40 | + { |
| 41 | + return _display; |
| 42 | + }; |
| 43 | + |
| 44 | + virtual void renderScreen(void *context) =0; |
| 45 | + |
| 46 | + // Build the display from the mount |
| 47 | + virtual void render(void (*drawContentFunction)(void*)) |
| 48 | + { |
| 49 | + _display->clear(); |
| 50 | + if (drawContentFunction) |
| 51 | + { |
| 52 | + drawContentFunction(this); |
| 53 | + } |
| 54 | + |
| 55 | + if (_consoleMode) |
| 56 | + { |
| 57 | + // Console lines |
| 58 | + int y = 21; |
| 59 | + _display->setFont(Bitmap3x5); |
| 60 | + // Start 6 lines back from current line and display next 6 lines |
| 61 | + int indexStart = max(0, _curLine - DISPLAY_CONSOLE_LINES); |
| 62 | + int indexEnd = min(indexStart + DISPLAY_CONSOLE_LINES, MAX_CONSOLE_LINES); |
| 63 | + for (int i = indexStart; i < indexEnd; i++) |
| 64 | + { |
| 65 | + if (_textList[i].length() != 0) |
| 66 | + { |
| 67 | + String text = _textList[i]; |
| 68 | + text.toUpperCase(); |
| 69 | + _display->drawString(0, y, text); |
| 70 | + } |
| 71 | + y += 7; |
| 72 | + } |
| 73 | + } |
| 74 | + else |
| 75 | + { |
| 76 | + } |
| 77 | + |
| 78 | + _display->display(); |
| 79 | + }; |
| 80 | + |
| 81 | + virtual void setConsoleMode(bool active) |
| 82 | + { |
| 83 | + _consoleMode = active; |
| 84 | + }; |
| 85 | + |
| 86 | + virtual int addConsoleText(const String& text, bool tinyFont = true) |
| 87 | + { |
| 88 | + int returnIndex = 0; |
| 89 | + if (_curLine > MAX_CONSOLE_LINES - 1) |
| 90 | + { |
| 91 | + for (int i = 0; i < MAX_CONSOLE_LINES - 1; i++) |
| 92 | + { |
| 93 | + _textList[i] = _textList[i + 1]; |
| 94 | + } |
| 95 | + _curLine = MAX_CONSOLE_LINES - 1; |
| 96 | + _textList[_curLine] = text; |
| 97 | + returnIndex = _curLine; |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + returnIndex = _curLine; |
| 102 | + _textList[_curLine++] = text; |
| 103 | + } |
| 104 | + render(nullptr); |
| 105 | + return returnIndex; |
| 106 | + }; |
11 | 107 |
|
12 | | - virtual void init() {}; |
13 | | - virtual void render(Mount *mount) {}; |
14 | | - virtual void setConsoleMode(bool active) {}; |
15 | | - virtual int addConsoleText(String text, bool tinyFont = true); |
16 | | - virtual void updateConsoleText(int line, String newText); |
| 108 | + virtual void updateConsoleText(int line, String text) |
| 109 | + { |
| 110 | + if (line >= 0 && line < MAX_CONSOLE_LINES) |
| 111 | + { |
| 112 | + _textList[line] = text; |
| 113 | + } |
| 114 | + render(nullptr); |
| 115 | + }; |
17 | 116 | }; |
0 commit comments