-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathLCDDisplay.hpp
118 lines (107 loc) · 3.58 KB
/
LCDDisplay.hpp
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
#pragma once
#include <Banks/Bank.hpp>
#include <Display/DisplayElement.hpp>
#include <Display/DisplayInterface.hpp>
#include <MIDI_Inputs/MCU/LCD.hpp>
BEGIN_CS_NAMESPACE
namespace MCU {
/**
* @brief Displays the text of the Mackie Control Universal LCD screen for a
* single track. Often used for track names.
*
* @ingroup DisplayElements
*/
class LCDDisplay : public DisplayElement {
public:
/**
* @brief Constructor.
*
* @param display
* @param lcd
* @param bank
* @param track
* The track number to display [1, 8].
* @param loc
* @param textSize
* @param color
*/
LCDDisplay(DisplayInterface &display, const MCU::LCD<> &lcd,
const OutputBank &bank, uint8_t track, PixelLocation loc,
uint8_t textSize, uint16_t color)
: DisplayElement(display), lcd(lcd), bank(bank), offset(track - 1),
line(0), x(loc.x), y(loc.y), size(textSize), color(color) {}
/**
* @brief Constructor.
*
* @param display
* @param lcd
* @param bank
* @param track
* The track number to display [1, 8].
* @param line
* @param loc
* @param textSize
* @param color
*/
LCDDisplay(DisplayInterface &display, const MCU::LCD<> &lcd,
const OutputBank &bank, uint8_t track, uint8_t line,
PixelLocation loc, uint8_t textSize, uint16_t color)
: DisplayElement(display), lcd(lcd), bank(bank), offset(track - 1),
line(line), x(loc.x), y(loc.y), size(textSize), color(color) {}
void draw() override {
// If it's a message across all tracks, don't display anything.
if (!separateTracks())
return;
// Extract the six-character substring for this track.
uint8_t trackoffset = bank.getOffset() + offset;
if (trackoffset > 7) // TODO
trackoffset = 7;
if (line > 1) // TODO
line = 1;
const char *text = lcd.getText() + 7 * trackoffset + 56 * line;
char buffer[7];
strncpy(buffer, text, 6);
buffer[6] = '\0';
// Print it to the display
display.setCursor(x, y);
display.setTextSize(size);
display.setTextColor(color);
display.print(buffer);
}
/**
* @brief Check if the display contains a message for each track
* separately.
*
* On the original Mackie Control surfaces, the LCD display consists of two
* 56-character lines, where each of the 8 channels has 7 characters.
* If the LCD is used to display a message for each channel separately, the
* seventh character of each channel is always a space, as separation
* between the channels.
*
* @retval true
* The display contains a message for each track separately, and
* the messages are separated by spaces.
* @retval false
* The display contains a message that spans across multiple
* tracks, without separating spaces between the tracks.
*/
bool separateTracks() const {
for (uint8_t i = 0; i < 7; ++i) {
const char *text = lcd.getText() + 7 * i + 56 * line;
if (text[6] != ' ')
return false;
}
return true;
}
void setLine(uint8_t line) { this->line = line; }
private:
const MCU::LCD<> &lcd;
const OutputBank &bank;
uint8_t offset;
uint8_t line;
int16_t x, y;
uint8_t size;
uint16_t color;
};
} // namespace MCU
END_CS_NAMESPACE