-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdisplay.cpp
144 lines (117 loc) · 3.76 KB
/
display.cpp
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
137
138
139
140
141
142
143
144
/**
* Copyright (c) 2015 by Matt Carpenter <[email protected]>
* Display class for RSSI Diversity Controller
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "display.h"
/**
* The Dispaly class is essentially a view model, binding RSSI state
* information to a KS0108 chipset based LCD display.
*
* @constructor
*/
Display::Display() {
u8g = new U8GLIB_ST7920_128X64_4X(10);
int _rawValues[3] = {0};
int _activeChannel = 0;
}
/**
* @destructor
*/
Display::~Display() {
if (NULL != u8g) {
delete u8g;
u8g = NULL;
}
}
/**
* Updates a channel in the view model
*
* @param {uint8_t} channel Channel number to update
* @param {uint8_t} rawValue Raw RSSI value
* @param {boolean} active Indicates whether or not this is the active channel
*/
void Display::updateChannel(uint8_t channel, uint8_t rawValue, boolean active) {
_rawValues[channel] = rawValue;
_activeChannel = (active ? channel : _activeChannel);
}
/**
* Draw cycle routine
*/
void Display::drawCycle() {
u8g->firstPage();
do {
drawChrome();
drawText();
drawIndicators();
} while (u8g->nextPage());
}
/**
* Paints boxes and frames for segmenting information
*/
void Display::drawChrome() {
u8g->setColorIndex(1);
// Draw channel ID boxes
u8g->drawBox(12, 0, 21, 17);
u8g->drawBox(12, 18, 21, 17);
u8g->drawBox(12, 36, 21, 17);
// Draw RSSI bar frames
u8g->drawFrame(34, 0, 94, 17);
u8g->drawFrame(34, 18, 94, 17);
u8g->drawFrame(34, 36, 94, 17);
}
/**
* Paints channel indicator and RSSI value text
*/
void Display::drawText() {
String ch1 = String(_rawValues[0]) + "%";
String ch2 = String(_rawValues[1]) + "%";
String ch3 = String(_rawValues[2]) + "%";
char buffer[5];
u8g->setColorIndex(0);
// Channel numbers
u8g->setFont(u8g_font_6x10);
u8g->drawStr( 14, 12, "CH1");
u8g->drawStr( 14, 30, "CH2");
u8g->drawStr( 14, 48, "CH3");
// RSSI %
u8g->setFont(u8g_font_9x15);
u8g->setColorIndex(1);
ch1.toCharArray(buffer,5);
u8g->drawStr( 36, 14, buffer);
ch2.toCharArray(buffer, 5);
u8g->drawStr( 36, 32, buffer);
ch3.toCharArray(buffer, 5);
u8g->drawStr( 36, 50, buffer);
// Footer
u8g->setFont(u8g_font_04b_03r);
u8g->drawStr(14, 62, "RSSI Diversity Controller");
}
/**
* Paints strength bar indicators and active channel decorator
*/
void Display::drawIndicators() {
int yOffset = (_activeChannel * 19) - (_activeChannel == 2 ? 1 : 0);
u8g->setColorIndex(1);
// Active channel decorator
u8g->drawTriangle(2, yOffset, 10, 8 + yOffset, 2, 16 + yOffset);
// Strength bars
// Max width 53 pixels
u8g->drawBox(73, 2, (_rawValues[0] * 53 / 100), 13);
u8g->drawBox(73, 20, (_rawValues[1] * 53 / 100), 13);
u8g->drawBox(73, 38, (_rawValues[2] * 53 / 100), 13);
}