-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathST7735Display.h
469 lines (426 loc) · 12.5 KB
/
ST7735Display.h
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#include "TeensyThreads.h"
// This Teensy3 native optimized version requires specific pins
#define sclk 20 // SCLK can also use pin 14
#define mosi 21 // MOSI can also use pin 7
#define cs 2 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define dc 3 //but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define rst 8 // RST can use any pin
#define DISPLAYTIMEOUT 700
#include <Adafruit_GFX.h>
#include "ST7735_t3.h" // Local copy from TD1.48 that works for 0.96" IPS 160x80 display
#include "Fonts/Org_01.h"
#include "Yeysk16pt7b.h"
#include "Fonts/FreeSansBold18pt7b.h"
#include "Fonts/FreeSans12pt7b.h"
#include "Fonts/FreeSans9pt7b.h"
#include "Fonts/FreeSansOblique24pt7b.h"
#include "Fonts/FreeSansBoldOblique24pt7b.h"
#define PULSE 1
#define VAR_TRI 2
#define FILTER_ENV 3
#define AMP_ENV 4
ST7735_t3 tft = ST7735_t3(cs, dc, mosi, sclk, rst);
String currentParameter = "";
String currentValue = "";
float currentFloatValue = 0.0;
String currentPgmNum = "";
String currentPatchName = "";
String newPatchName = "";
char * currentSettingsOption = "";
char * currentSettingsValue = "";
int currentSettingsPart = SETTINGS;
int paramType = PARAMETER;
boolean MIDIClkSignal = false;
uint32_t peakCount = 0;
unsigned long timer = 0;
void startTimer()
{
if (state == PARAMETER)
{
timer = millis();
}
}
void renderBootUpPage()
{
tft.fillScreen(ST7735_BLACK);
tft.drawRect(42, 30, 46, 11, ST7735_WHITE);
tft.fillRect(88, 30, 61, 11, ST7735_WHITE);
tft.setCursor(45, 31);
tft.setFont(&Org_01);
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE);
tft.println("ELECTRO");
tft.setTextColor(ST7735_BLACK);
tft.setCursor(91, 37);
tft.println("TECHNIQUE");
tft.setTextColor(ST7735_YELLOW);
tft.setFont(&Yeysk16pt7b);
tft.setCursor(5, 70);
tft.setTextSize(1);
tft.println("TSynth");
tft.setTextColor(ST7735_RED);
tft.setFont(&FreeSans9pt7b);
tft.setCursor(110, 95);
tft.println(VERSION);
}
void renderPeak() {
if (vuMeter && peak.available()) {
uint16_t len = 0;
len = (int)(peak.read() * 75.0f);
tft.drawFastVLine(158, 103 - len, len , len > 72 ? ST77XX_RED : ST77XX_GREEN);
tft.drawFastVLine(159, 103 - len, len , len > 72 ? ST77XX_RED : ST77XX_GREEN);
}
}
void renderCurrentPatchPage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSansBold18pt7b);
tft.setCursor(5, 53);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.println(currentPgmNum);
tft.setTextColor(ST7735_BLACK);
tft.setFont(&Org_01);
if (MIDIClkSignal) {
tft.fillRect(93, 28, 19, 7, ST77XX_ORANGE);
tft.setCursor(94, 33);
tft.println("CLK");
}
renderPeak();
tft.drawRect(115, 28, 12, 12, ST7735_BLUE);
tft.drawRect(130, 28, 12, 12, ST7735_BLUE);
tft.drawRect(145, 28, 12, 12, ST7735_BLUE);
tft.drawRect(115, 43, 12, 12, ST7735_BLUE);
tft.drawRect(130, 43, 12, 12, ST7735_BLUE);
tft.drawRect(145, 43, 12, 12, ST7735_BLUE);
if (voices[0].voiceOn)
{
tft.fillRect(115, 28, 12, 12, ST7735_BLUE);
tft.setCursor(120, 36);
tft.println("1");
}
if (voices[1].voiceOn)
{
tft.fillRect(130, 28, 12, 12, ST7735_BLUE);
tft.setCursor(133, 36);
tft.println("2");
}
if (voices[2].voiceOn)
{
tft.fillRect(145, 28, 12, 12, ST7735_BLUE);
tft.setCursor(148, 36);
tft.println("3");
}
if (voices[3].voiceOn)
{
tft.fillRect(115, 43, 12, 12, ST7735_BLUE);
tft.setCursor(118, 51);
tft.println("4");
}
if (voices[4].voiceOn)
{
tft.fillRect(130, 43, 12, 12, ST7735_BLUE);
tft.setCursor(133, 51);
tft.println("5");
}
if (voices[5].voiceOn)
{
tft.fillRect(145, 43, 12, 12, ST7735_BLUE);
tft.setCursor(148, 51);
tft.println("6");
}
tft.drawFastHLine(10, 62, tft.width() - 20, ST7735_RED);
tft.setFont(&FreeSans12pt7b);
tft.setTextColor(ST7735_YELLOW);
tft.setCursor(1, 90);
tft.setTextColor(ST7735_WHITE);
tft.println(currentPatchName);
}
void renderPulseWidth(float value)
{
tft.drawFastHLine(108, 74, 15 + (value * 13), ST7735_CYAN);
tft.drawFastVLine(123 + (value * 13), 74, 20, ST7735_CYAN);
tft.drawFastHLine(123 + (value * 13), 94, 16 - (value * 13), ST7735_CYAN);
if (value < 0)
{
tft.drawFastVLine(108, 74, 21, ST7735_CYAN);
}
else
{
tft.drawFastVLine(138, 74, 21, ST7735_CYAN);
}
}
void renderVarTriangle(float value)
{
tft.drawLine(110, 94, 123 + (value * 13), 74, ST7735_CYAN);
tft.drawLine(123 + (value * 13), 74, 136, 94, ST7735_CYAN);
}
void renderEnv(float att, float dec, float sus, float rel)
{
tft.drawLine(100, 94, 100 + (att * 15), 74, ST7735_CYAN);
tft.drawLine(100 + (att * 15), 74.0, 100 + ((att + dec) * 15), 94 - (sus * 20), ST7735_CYAN);
tft.drawFastHLine(100 + ((att + dec) * 15), 94 - (sus * 20), 40 - ((att + dec) * 15), ST7735_CYAN);
tft.drawLine(139, 94 - (sus * 20), 139 + (rel * 13), 94, ST7735_CYAN);
}
void renderCurrentParameterPage()
{
switch (state)
{
case PARAMETER:
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans12pt7b);
tft.setCursor(0, 53);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.println(currentParameter);
tft.drawFastHLine(10, 62, tft.width() - 20, ST7735_RED);
tft.setCursor(1, 90);
tft.setTextColor(ST7735_WHITE);
tft.println(currentValue);
if (pickUpActive) {
tft.fillCircle(150, 70, 5, ST77XX_DARKGREY);
tft.drawFastHLine(146, 70, 4, ST7735_WHITE);
}
switch (paramType)
{
case PULSE:
renderPulseWidth(currentFloatValue);
break;
case VAR_TRI:
renderVarTriangle(currentFloatValue);
break;
case FILTER_ENV:
renderEnv(filterAttack * 0.0001, filterDecay * 0.0001, filterSustain, filterRelease * 0.0001);
break;
case AMP_ENV:
renderEnv(ampAttack * 0.0001, ampDecay * 0.0001, ampSustain, ampRelease * 0.0001);
break;
}
break;
}
}
void renderDeletePatchPage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSansBold18pt7b);
tft.setCursor(5, 53);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.println("Delete?");
tft.drawFastHLine(10, 60, tft.width() - 20, ST7735_RED);
tft.setFont(&FreeSans9pt7b);
tft.setCursor(0, 78);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches.last().patchNo);
tft.setCursor(35, 78);
tft.setTextColor(ST7735_WHITE);
tft.println(patches.last().patchName);
tft.fillRect(0, 85, tft.width(), 23, ST77XX_DARKRED);
tft.setCursor(0, 98);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches.first().patchNo);
tft.setCursor(35, 98);
tft.setTextColor(ST7735_WHITE);
tft.println(patches.first().patchName);
}
void renderDeleteMessagePage() {
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans12pt7b);
tft.setCursor(2, 53);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.println("Renumbering");
tft.setCursor(10, 90);
tft.println("SD Card");
}
void renderSavePage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSansBold18pt7b);
tft.setCursor(5, 53);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.println("Save?");
tft.drawFastHLine(10, 60, tft.width() - 20, ST7735_RED);
tft.setFont(&FreeSans9pt7b);
tft.setCursor(0, 78);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches[patches.size() - 2].patchNo);
tft.setCursor(35, 78);
tft.setTextColor(ST7735_WHITE);
tft.println(patches[patches.size() - 2].patchName);
tft.fillRect(0, 85, tft.width(), 23, ST77XX_DARKRED);
tft.setCursor(0, 98);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches.last().patchNo);
tft.setCursor(35, 98);
tft.setTextColor(ST7735_WHITE);
tft.println(patches.last().patchName);
}
void renderReinitialisePage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans12pt7b);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.setCursor(5, 53);
tft.println("Initialise to");
tft.setCursor(5, 90);
tft.println("panel setting");
}
void renderPatchNamingPage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans12pt7b);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.setCursor(0, 53);
tft.println("Rename Patch");
tft.drawFastHLine(10, 62, tft.width() - 20, ST7735_RED);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(5, 90);
tft.println(newPatchName);
}
void renderRecallPage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans9pt7b);
tft.setCursor(0, 45);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches.last().patchNo);
tft.setCursor(35, 45);
tft.setTextColor(ST7735_WHITE);
tft.println(patches.last().patchName);
tft.fillRect(0, 56, tft.width(), 23, 0xA000);
tft.setCursor(0, 72);
tft.setTextColor(ST7735_YELLOW);
tft.println(patches.first().patchNo);
tft.setCursor(35, 72);
tft.setTextColor(ST7735_WHITE);
tft.println(patches.first().patchName);
tft.setCursor(0, 98);
tft.setTextColor(ST7735_YELLOW);
patches.size() > 1 ? tft.println(patches[1].patchNo) : tft.println(patches.last().patchNo);
tft.setCursor(35, 98);
tft.setTextColor(ST7735_WHITE);
patches.size() > 1 ? tft.println(patches[1].patchName) : tft.println(patches.last().patchName);
}
void showRenamingPage(String newName)
{
newPatchName = newName;
}
void renderUpDown(uint16_t x, uint16_t y, uint16_t colour)
{
//Produces up/down indicator glyph at x,y
tft.setCursor(x, y);
tft.fillTriangle(x, y, x + 8, y - 8, x + 16, y, colour);
tft.fillTriangle(x, y + 4, x + 8, y + 12, x + 16, y + 4, colour);
}
void renderSettingsPage()
{
tft.fillScreen(ST7735_BLACK);
tft.setFont(&FreeSans12pt7b);
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(1);
tft.setCursor(0, 53);
tft.println(currentSettingsOption);
if (currentSettingsPart == SETTINGS) renderUpDown(140, 42, ST7735_YELLOW);
tft.drawFastHLine(10, 62, tft.width() - 20, ST7735_RED);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(5, 90);
tft.println(currentSettingsValue);
if (currentSettingsPart == SETTINGSVALUE) renderUpDown(140, 80, ST7735_WHITE);
}
void showCurrentParameterPage(const char *param, float val, int pType)
{
currentParameter = param;
currentValue = String(val);
currentFloatValue = val;
paramType = pType;
startTimer();
}
void showCurrentParameterPage(const char *param, String val, int pType)
{
if (state == SETTINGS || state == SETTINGSVALUE)state = PARAMETER;//Exit settings page if showing
currentParameter = param;
currentValue = val;
paramType = pType;
startTimer();
}
void showCurrentParameterPage(const char *param, String val)
{
showCurrentParameterPage(param, val, PARAMETER);
}
void showPatchPage(String number, String patchName)
{
currentPgmNum = number;
currentPatchName = patchName;
}
void showSettingsPage(char * option, char * value, int settingsPart)
{
currentSettingsOption = option;
currentSettingsValue = value;
currentSettingsPart = settingsPart;
}
void enableScope(boolean enable) {
enable ? scope.ScreenSetup(&tft) : scope.ScreenSetup(NULL);
}
void displayThread()
{
threads.delay(2000); //Give bootup page chance to display
while (1)
{
switch (state)
{
case PARAMETER:
if ((millis() - timer) > DISPLAYTIMEOUT) {
pickUpActive = false;
renderCurrentPatchPage();
}
else {
pickUpActive = pickUp;
renderCurrentParameterPage();
}
break;
case RECALL:
renderRecallPage();
break;
case SAVE:
renderSavePage();
break;
case REINITIALISE:
renderReinitialisePage();
tft.updateScreen(); //update before delay
threads.delay(1000);
state = PARAMETER;
break;
case PATCHNAMING:
renderPatchNamingPage();
break;
case PATCH:
renderCurrentPatchPage();
break;
case DELETE:
renderDeletePatchPage();
break;
case DELETEMSG:
renderDeleteMessagePage();
break;
case SETTINGS:
case SETTINGSVALUE:
renderSettingsPage();
break;
}
tft.updateScreen();
}
}
void setupDisplay()
{
tft.useFrameBuffer(true);
tft.initR(INITR_GREENTAB);
tft.setRotation(3);
tft.invertDisplay(true);
renderBootUpPage();
tft.updateScreen();
threads.addThread(displayThread);
}