-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNefryDisplay.cpp
225 lines (195 loc) · 5.24 KB
/
NefryDisplay.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "NefryDisplay.h"
#include "NefryBTimg.h"
#include <string>
SSD1306 _nefrySsdDisplay(0x3c, SDA2, SCL2);
String _nefryPrintDisplay1 = "", _nefryPrintDisplay2 = "", _nefryPrintDisplay3 = "";
String _dialogTitle = "Nefry PrintDialog";
/* 初期化 */
bool Nefry_Display::begin()
{
// Initialising the UI will init the display too.
_nefrySsdDisplay.init();
_nefrySsdDisplay.flipScreenVertically();
_nefrySsdDisplay.setContrast(120);
/* BoardIDで表示する内容をできるようにする */
_nefrySsdDisplay.drawXbm(0, 0, nefrybt_img_width, nefrybt_img_height, nefrybt_img_bits);
_nefrySsdDisplay.display();
return true;
}
void Nefry_Display::setTitle(String title) {
_dialogTitle = title;
}
void setPrintDialogDisplay() {
NefryDisplay.setFont(Arimo_12);
NefryDisplay.drawString(15, 0, _dialogTitle);
NefryDisplay.drawStringWithHScroll(0, 20, _nefryPrintDisplay1,10);
NefryDisplay.drawStringWithHScroll(0, 35, _nefryPrintDisplay2, 10);
NefryDisplay.drawStringWithHScroll(0, 50, _nefryPrintDisplay3, 10);
}
/* 表示 */
bool Nefry_Display::print(String s)
{
s += " ";
if (_nefryPrintDisplayValue < 3) {
switch (_nefryPrintDisplayValue)
{
case 0:
_nefryPrintDisplay1 = s;
break;
case 1:
_nefryPrintDisplay2 = s;
break;
case 2:
_nefryPrintDisplay3 = s;
break;
}
_nefryPrintDisplayValue++;
}
else {
_nefryPrintDisplay1 = _nefryPrintDisplay2;
_nefryPrintDisplay2 = _nefryPrintDisplay3;
_nefryPrintDisplay3 = s;
}
setAutoScrollFlg(true);
autoScrollFunc(setPrintDialogDisplay);
return true;
}
void Nefry_Display::end()
{
_nefrySsdDisplay.end();
}
void Nefry_Display::setColor(OLEDDISPLAY_COLOR color)
{
_nefrySsdDisplay.setColor(color);
}
void Nefry_Display::drawString(int16_t x, int16_t y, String text, int16_t maxLineWidth)
{
/* スクロール機能未実装 */
if (maxLineWidth == 0)maxLineWidth = 127;
_nefrySsdDisplay.drawStringMaxWidth(x, y, maxLineWidth, text);
}
void Nefry_Display::drawStringWithHScroll(int16_t x, int16_t y, String text, int16_t scrollSpeed, int16_t scrollpointer)
{
int16_t maxLineWidth = 127 - x;
int16_t textWidth = getStringWidth(text);
String tempText = text;
if (scrollpointer == -1) {
if (_scrollMode == true) {
if (textWidth > maxLineWidth) {
long strIndex = _scrollTextCount / scrollSpeed;
int textLength = text.length();
long scrollNum = strIndex % textLength;
String h_text = text.substring(0, scrollNum);
String l_text = text.substring(scrollNum);
l_text.concat(h_text);
tempText = l_text;
}
}
}
else {
if (textWidth > maxLineWidth) {
long strIndex = scrollpointer / scrollSpeed;
int textLength = text.length();
long scrollNum = strIndex % textLength;
String h_text = text.substring(0, scrollNum);
String l_text = text.substring(scrollNum);
l_text.concat(h_text);
tempText = l_text;
}
}
_nefrySsdDisplay.drawString(x, y, tempText);
}
uint16_t Nefry_Display::getStringWidth(const char * text, uint16_t length)
{
return _nefrySsdDisplay.getStringWidth(text,length);
}
uint16_t Nefry_Display::getStringWidth(String text)
{
return _nefrySsdDisplay.getStringWidth(text);
}
Nefry_Display NefryDisplay;
void Nefry_Display::setFont(const char * fontData)
{
_nefrySsdDisplay.setFont(fontData);
}
void Nefry_Display::setPixel(int16_t x, int16_t y)
{
_nefrySsdDisplay.setPixel(x, y);
}
void Nefry_Display::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
{
_nefrySsdDisplay.drawLine(x0, y0, x1, y1);
}
void Nefry_Display::drawRect(int16_t x, int16_t y, int16_t width, int16_t height)
{
_nefrySsdDisplay.drawRect(x, y, width, height);
}
void Nefry_Display::fillRect(int16_t x, int16_t y, int16_t width, int16_t height)
{
_nefrySsdDisplay.fillRect(x, y, width, height);
}
void Nefry_Display::drawCircle(int16_t x, int16_t y, int16_t radius)
{
_nefrySsdDisplay.drawCircle(x, y, radius);
}
void Nefry_Display::fillCircle(int16_t x, int16_t y, int16_t radius)
{
_nefrySsdDisplay.fillCircle(x, y, radius);
}
void Nefry_Display::drawHorizontalLine(int16_t x, int16_t y, int16_t length)
{
_nefrySsdDisplay.drawHorizontalLine(x, y, length);
}
void Nefry_Display::drawVerticalLine(int16_t x, int16_t y, int16_t length)
{
_nefrySsdDisplay.drawVerticalLine(x, y, length);
}
void Nefry_Display::drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress)
{
_nefrySsdDisplay.drawProgressBar(x, y, width, height, progress);
}
void Nefry_Display::drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const char * xbm)
{
_nefrySsdDisplay.drawXbm(x, y, width, height, xbm);
}
void Nefry_Display::clear(void)
{
_nefrySsdDisplay.clear();
}
void Nefry_Display::display(void)
{
_nefrySsdDisplay.display();
}
void Nefry_Display::invertDisplay(void)
{
_nefrySsdDisplay.invertDisplay();
}
void Nefry_Display::normalDisplay(void)
{
_nefrySsdDisplay.normalDisplay();
}
void Nefry_Display::setContrast(char contrast)
{
_nefrySsdDisplay.setContrast(contrast);
}
void Nefry_Display::flipScreenVertically()
{
_nefrySsdDisplay.flipScreenVertically();
}
void Nefry_Display::setAutoScrollFlg(bool scroll)
{
_scrollMode = scroll;
}
void Nefry_Display::autoScrollFunc(GeneralFunction func)
{
_func = func;
}
void Nefry_Display::autoScrollTask()
{
if (_func != NULL) {
clear();
_scrollTextCount++;
_func();
display();
}
}