-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
989 lines (860 loc) · 34.8 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
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
#include <Adafruit_NeoPixel.h>
#include "graphics.h"
#include "defines.h"
#include "display.h"
#include "ircomm.hpp"
#include "bkmcomm.hpp"
#define LED_BACKGROUND ( 0 )
#define LED_ENCODER_1 ( 1 )
#define LED_ENCODER_2 ( 2 )
#define DISPLAY_BACKLIGHT ( true )
#define ENCODER_BACKLIGHT ( false )
#define TIMEOUT_BACKLIGHT ( 10000 ) // ten seconds
// Hardware Solution. MUST SET SPI PINS!! See setup
U8G2_ST7567_OS12864_F_4W_HW_SPI display(U8G2_R2, /* cs=*/PIN_LCD_EN,
/* dc=*/PIN_LCD_RS,
/* reset=*/PIN_LCD_RESET );
// SOFTWARE SOLUTION WORKS!
//U8G2_ST7567_OS12864_F_4W_SW_SPI display (U8G2_R2 , PIN_LCD_SPI_SCK, PIN_LCD_SPI_MOSI, PIN_LCD_EN, PIN_LCD_RS, PIN_LCD_RESET);
// Backlight
Adafruit_NeoPixel pixels(3, PIN_LCD_RGB, NEO_GRB + NEO_KHZ800);
// Global Variables
unsigned long g_lLastInputEvent;
unsigned long g_lStartTime;
byte g_yContrast = CONTRAST_LCD_DEF;
byte g_yBrightness = BRIGHTNESS_LCD_DEF;
bool g_bBacklightIsIdle = false;
// Show the pot background colors
bool g_bShowPotColors = true;
// Gr, Rd, Bl
int iRed = pixels.Color( 0, 100, 0);
int iGreen = pixels.Color( 100, 0, 0);
int iBlue = pixels.Color( 0, 0, 100);
int iWhite = pixels.Color( 100, 100, 100);
int iOff = pixels.Color( 0, 0, 0);
int iGreenBg = pixels.Color( 200, 0, 0);
int iYellowBg = pixels.Color( 193, 204, 0);
int iWhiteBg = pixels.Color( 200, 200, 200);
byte ayCursorPositionP12[] = { PAGE1COL1, PAGE1ROW1CURSOR };
byte ayCursorPositionP3[] = { PAGE3COL1, PAGE3ROW1CURSOR };
byte yActiveIndicatorPosition = PAGE3COL1;
bool abButtonStates[ BUTTON_NUM ];
bool bPage1Initialized = false;
bool bPage2Initialized = false;
bool bPage3Initialized = false;
byte yCurrentPage = PAGE_NO_1;
bool bDrawPage1Buttons = false;
bool bDrawPage3Buttons = false;
bool bDrawPage1Cursor = false;
bool bDrawPage3Cursor = false;
bool bDrawActiveIndicator = false;
word wButtonStatesP1Buff = 0x0000U;
word wButtonStatesP2Buff = 0x0000U;
word wButtonStatesP3Buff = 0x0000U;
word wButtonStatesP1 = 0x0000U;
word wButtonStatesP2 = 0x0000U;
word wButtonStatesP3 = 0x0000U;
// Image pointers of the buttons, page 1 to 3
const uint8_t *pButton1 = image_ButtonNotPressed_bits;
const uint8_t *pButton2 = image_ButtonNotPressed_bits;
const uint8_t *pButton3 = image_ButtonNotPressed_bits;
const uint8_t *pButton4 = image_ButtonNotPressed_bits;
const uint8_t *pButton5 = image_ButtonNotPressed_bits;
const uint8_t *pButton6 = image_ButtonNotPressed_bits;
const uint8_t *pButton7 = image_ButtonNotPressed_bits;
const uint8_t *pButton8 = image_ButtonNotPressed_bits;
const uint8_t *pButton9 = image_ButtonNotPressed_bits;
const uint8_t *pButton10 = image_ButtonNotPressed_bits;
const uint8_t *pButton11 = image_ButtonNotPressed_bits;
const uint8_t *pButton12 = image_ButtonNotPressed_bits;
const uint8_t *pButton13 = image_ButtonNotPressed_bits;
const uint8_t *pButton14 = image_ButtonNotPressed_bits;
//-----------------------------------------------------
//-----------------
// Local functions
//-----------------
// Initial Boot Logo
static void displayBootLogo( void )
{
g_lStartTime = millis();
display.clearBuffer(); // clear the internal memory
// code from https://lopaka.app/
display.setFontMode(1);
display.setBitmapMode(1);
display.drawXBMP(0, 16, 128, 23, image_SONY_LOGO_bits);
display.setFont(u8g2_font_5x8_tr);
display.drawStr(16, 52, "BKM-10R DIY Edition");
display.sendBuffer(); // transfer internal memory to the display
}
static void setIndividualColor( bool bEncoderOrBackground, int iColor )
{
if ( bEncoderOrBackground )
{
// Set Background LED
pixels.setPixelColor( LED_BACKGROUND, iColor );
}
else
{
// Set Encoder LEDs
pixels.setPixelColor( LED_ENCODER_1, iColor );
pixels.setPixelColor( LED_ENCODER_2, iColor );
}
pixels.show();
}
static void updateButtonBitfields( void )
{
// This is the part in the code where the actual
// connection between the bool-array and the
// position of the button on the display is set!
if ( abButtonStates[ IDX_SHIFT ] ) wButtonStatesP1 |= BUTTON_MASK_R1C1;
else wButtonStatesP1 &= ~BUTTON_MASK_R1C1;
if ( abButtonStates[ IDX_SHIFT ] ) wButtonStatesP2 |= BUTTON_MASK_R1C1;
else wButtonStatesP2 &= ~BUTTON_MASK_R1C1;
if ( abButtonStates[ IDX_F1 ] ) wButtonStatesP1 |= BUTTON_MASK_R1C2;
else wButtonStatesP1 &= ~BUTTON_MASK_R1C2;
if ( abButtonStates[ IDX_F2 ] ) wButtonStatesP1 |= BUTTON_MASK_R2C2;
else wButtonStatesP1 &= ~BUTTON_MASK_R2C2;
if ( abButtonStates[ IDX_F3 ] ) wButtonStatesP2 |= BUTTON_MASK_R1C2;
else wButtonStatesP2 &= ~BUTTON_MASK_R1C2;
if ( abButtonStates[ IDX_F4 ] ) wButtonStatesP2 |= BUTTON_MASK_R2C2;
else wButtonStatesP2 &= ~BUTTON_MASK_R2C2;
if ( abButtonStates[ IDX_HDELAY ] ) wButtonStatesP1 |= BUTTON_MASK_R1C3;
else wButtonStatesP1 &= ~BUTTON_MASK_R1C3;
if ( abButtonStates[ IDX_VDELAY ] ) wButtonStatesP1 |= BUTTON_MASK_R2C3;
else wButtonStatesP1 &= ~BUTTON_MASK_R2C3;
if ( abButtonStates[ IDX_APT ] ) wButtonStatesP1 |= BUTTON_MASK_R1C4;
else wButtonStatesP1 &= ~BUTTON_MASK_R1C4;
if ( abButtonStates[ IDX_MONO ] ) wButtonStatesP1 |= BUTTON_MASK_R1C5;
else wButtonStatesP1 &= ~BUTTON_MASK_R1C5;
if ( abButtonStates[ IDX_UNDERSCAN ] ) wButtonStatesP1 |= BUTTON_MASK_R2C1;
else wButtonStatesP1 &= ~BUTTON_MASK_R2C1;
if ( abButtonStates[ IDX_COMB ] ) wButtonStatesP1 |= BUTTON_MASK_R2C4;
else wButtonStatesP1 &= ~BUTTON_MASK_R2C4;
if ( abButtonStates[ IDX_ADDRESS ] ) wButtonStatesP1 |= BUTTON_MASK_R2C5;
else wButtonStatesP1 &= ~BUTTON_MASK_R2C5;
if ( abButtonStates[ IDX_RED ] ) wButtonStatesP2 |= BUTTON_MASK_R1C3;
else wButtonStatesP2 &= ~BUTTON_MASK_R1C3;
if ( abButtonStates[ IDX_GREEN ] ) wButtonStatesP2 |= BUTTON_MASK_R1C4;
else wButtonStatesP2 &= ~BUTTON_MASK_R1C4;
if ( abButtonStates[ IDX_BLUE ] ) wButtonStatesP2 |= BUTTON_MASK_R1C5;
else wButtonStatesP2 &= ~BUTTON_MASK_R1C5;
if ( abButtonStates[ IDX_SYNC ] ) wButtonStatesP2 |= BUTTON_MASK_R2C1;
else wButtonStatesP2 &= ~BUTTON_MASK_R2C1;
if ( abButtonStates[ IDX_16BY9 ] ) wButtonStatesP2 |= BUTTON_MASK_R2C3;
else wButtonStatesP2 &= ~BUTTON_MASK_R2C3;
if ( abButtonStates[ IDX_BLUEONLY ] ) wButtonStatesP2 |= BUTTON_MASK_R2C4;
else wButtonStatesP2 &= ~BUTTON_MASK_R2C4;
if ( abButtonStates[ IDX_SAFEAREA ] ) wButtonStatesP2 |= BUTTON_MASK_R2C5;
else wButtonStatesP2 &= ~BUTTON_MASK_R2C5;
if ( abButtonStates[ IDX_PHASE ] ) wButtonStatesP3 |= BUTTON_MASK_KNOB1;
else wButtonStatesP3 &= ~BUTTON_MASK_KNOB1;
if ( abButtonStates[ IDX_CHROMA ] ) wButtonStatesP3 |= BUTTON_MASK_KNOB2;
else wButtonStatesP3 &= ~BUTTON_MASK_KNOB2;
if ( abButtonStates[ IDX_BRIGHTNESS ] ) wButtonStatesP3 |= BUTTON_MASK_KNOB3;
else wButtonStatesP3 &= ~BUTTON_MASK_KNOB3;
if ( abButtonStates[ IDX_CONTRAST ] ) wButtonStatesP3 |= BUTTON_MASK_KNOB4;
else wButtonStatesP3 &= ~BUTTON_MASK_KNOB4;
}
static void setButtonStates( word wStateBitfield )
{
if ( ( BUTTON_MASK_R1C1 & wStateBitfield ) == BUTTON_MASK_R1C1 ) pButton1 = image_ButtonPressed_bits;
else pButton1 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R1C2 & wStateBitfield ) == BUTTON_MASK_R1C2 ) pButton2 = image_ButtonPressed_bits;
else pButton2 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R1C3 & wStateBitfield ) == BUTTON_MASK_R1C3 ) pButton3 = image_ButtonPressed_bits;
else pButton3 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R1C4 & wStateBitfield ) == BUTTON_MASK_R1C4 ) pButton4 = image_ButtonPressed_bits;
else pButton4 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R1C5 & wStateBitfield ) == BUTTON_MASK_R1C5 ) pButton5 = image_ButtonPressed_bits;
else pButton5 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R2C1 & wStateBitfield ) == BUTTON_MASK_R2C1 ) pButton6 = image_ButtonPressed_bits;
else pButton6 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R2C2 & wStateBitfield ) == BUTTON_MASK_R2C2 ) pButton7 = image_ButtonPressed_bits;
else pButton7 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R2C3 & wStateBitfield ) == BUTTON_MASK_R2C3 ) pButton8 = image_ButtonPressed_bits;
else pButton8 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R2C4 & wStateBitfield ) == BUTTON_MASK_R2C4 ) pButton9 = image_ButtonPressed_bits;
else pButton9 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_R2C5 & wStateBitfield ) == BUTTON_MASK_R2C5 ) pButton10 = image_ButtonPressed_bits;
else pButton10 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_KNOB1 & wStateBitfield ) == BUTTON_MASK_KNOB1 ) pButton11 = image_ButtonPressed_bits;
else pButton11 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_KNOB2 & wStateBitfield ) == BUTTON_MASK_KNOB2 ) pButton12 = image_ButtonPressed_bits;
else pButton12 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_KNOB3 & wStateBitfield ) == BUTTON_MASK_KNOB3 ) pButton13 = image_ButtonPressed_bits;
else pButton13 = image_ButtonNotPressed_bits;
if ( ( BUTTON_MASK_KNOB4 & wStateBitfield ) == BUTTON_MASK_KNOB4 ) pButton14 = image_ButtonPressed_bits;
else pButton14 = image_ButtonNotPressed_bits;
}
static void drawPage3ActiveIndicator( byte yCol )
{
byte xPosition = ( yCol - ACTIVE_INDICATOR_OFFSET );
// Setting all possible Cursor positions to blank
display.setDrawColor( 0 );
display.drawBox( 0, 11, 128, 20 ); // Erasing the whole line of cursors
display.setDrawColor( 1 );
display.setFont(u8g2_font_4x6_tr);
display.drawStr( xPosition, 22, "active");
display.drawXBMP( xPosition, 24, 24, 5, image_ActiveArrow_bits );
}
static void drawPage1Cursor( byte yRow, byte yCol )
{
// Setting all possible Cursor positions to blank
display.setDrawColor( 0 );
display.drawBox( PAGE1COL1, PAGE1ROW1CURSOR, 107, 4 ); // Erasing the whole line of cursors
display.drawBox( PAGE1COL1, PAGE1ROW2CURSOR, 107, 4 ); // Erasing the whole line of cursors
display.setDrawColor( 1 );
display.drawXBMP( yRow, yCol, 7, 4, image_SmallArrowUp_bits );
}
static void drawPage3Cursor( byte yRow, byte yCol )
{
// Setting all possible Cursor positions to blank
display.setDrawColor( 0 );
display.drawBox( PAGE3COL1, PAGE3ROW1CURSOR, 114, 4 ); // Erasing the whole line of cursors
display.setDrawColor( 1 );
display.drawXBMP( yRow, yCol, 7, 4, image_SmallArrowUp_bits );
}
static void displayInitialSetupPage( byte yPageNumber, bool bDrawButtons, bool bDrawCursor )
{
// Initialize static elements of the page once
display.clearBuffer(); // clear the internal memory
display.setFontMode(1);
display.setBitmapMode(1);
// Display Header
display.drawLine(3, 10, 123, 10);
display.setFont(u8g2_font_6x10_tr);
if ( yPageNumber == PAGE_NO_1 ) display.drawStr(3, 8, "Buttons");
if ( yPageNumber == PAGE_NO_2 ) display.drawStr(3, 8, "Buttons");
if ( yPageNumber == PAGE_NO_3 ) display.drawStr(3, 8, "Encoders" );
if ( yPageNumber == PAGE_NO_1 ) display.drawStr(107, 8, "1/2"); // Page 1 or 2 is determined by Shift
if ( yPageNumber == PAGE_NO_2 ) display.drawStr(107, 8, "1/2"); // Page 1 or 2 is determined by Shift
if ( yPageNumber == PAGE_NO_3 ) display.drawStr(107, 8, "2/2");
display.setFont(u8g2_font_5x8_tr);
if ( yPageNumber == PAGE_NO_1 )
{
// First Row of Labels
display.drawStr( 1, 30, "SHIFT");
display.drawStr( 34, 30, "F1" );
display.drawStr( 54, 30, "HDLY" );
display.drawStr( 82, 30, "APT" );
display.drawStr(103, 30, "MONO" );
// Second Row of Labels
display.drawStr( 1, 58, "USCAN");
display.drawStr( 34, 58, "F2" );
display.drawStr( 54, 58, "VDLY" );
display.drawStr( 79, 58, "COMB" );
display.drawStr( 103, 58, "ADDR" );
}
if ( yPageNumber == PAGE_NO_2 )
{
// First Row of Labels
display.drawStr( 1, 30, "SHIFT");
display.drawStr( 34, 30, "F3" );
display.drawStr( 61, 30, "R" );
display.drawStr( 86, 30, "G" );
display.drawStr(111, 30, "B" );
// Second Row of Labels
display.drawStr( 4, 58, "SYNC" );
display.drawStr( 34, 58, "F4" );
display.drawStr( 54, 58, "16:9" );
display.drawStr( 79, 58, "BLUE" );
display.drawStr(103, 58, "SAFE" );
}
if ( yPageNumber == PAGE_NO_3 )
{
display.drawStr( 3, 50, "PHASE" );
display.drawStr(31, 50, "CHROMA");
display.drawStr(64, 50, "BRIGHT");
display.drawStr(99, 50, "CONTR" );
}
// Set the global button pointers to images corresponding to button state
if ( PAGE_NO_1 == yPageNumber ) setButtonStates( wButtonStatesP1 );
if ( PAGE_NO_2 == yPageNumber ) setButtonStates( wButtonStatesP2 );
if ( PAGE_NO_3 == yPageNumber ) setButtonStates( wButtonStatesP3 );
if ( ( PAGE_NO_1 == yPageNumber ) || ( PAGE_NO_2 == yPageNumber ) )
{
// First Row of Button indicators
display.drawXBMP( PAGE1COL1, PAGE1ROW1, 7, 7, pButton1 );
display.drawXBMP( PAGE1COL2, PAGE1ROW1, 7, 7, pButton2 );
display.drawXBMP( PAGE1COL3, PAGE1ROW1, 7, 7, pButton3 );
display.drawXBMP( PAGE1COL4, PAGE1ROW1, 7, 7, pButton4 );
display.drawXBMP( PAGE1COL5, PAGE1ROW1, 7, 7, pButton5 );
// Second Row of Button indicators
display.drawXBMP( PAGE1COL1, PAGE1ROW2, 7, 7, pButton6 );
display.drawXBMP( PAGE1COL2, PAGE1ROW2, 7, 7, pButton7 );
display.drawXBMP( PAGE1COL3, PAGE1ROW2, 7, 7, pButton8 );
display.drawXBMP( PAGE1COL4, PAGE1ROW2, 7, 7, pButton9 );
display.drawXBMP( PAGE1COL5, PAGE1ROW2, 7, 7, pButton10 );
// Draw Cursor arrow
drawPage1Cursor ( ayCursorPositionP12[0], ayCursorPositionP12[1] );
}
if ( PAGE_NO_3 == yPageNumber )
{
// First Row of Button indicators
display.drawXBMP( PAGE3COL1, PAGE3ROW1, 7, 7, pButton11 );
display.drawXBMP( PAGE3COL2, PAGE3ROW1, 7, 7, pButton12 );
display.drawXBMP( PAGE3COL3, PAGE3ROW1, 7, 7, pButton13 );
display.drawXBMP( PAGE3COL4, PAGE3ROW1, 7, 7, pButton14 );
// Draw Cursor Arrow
drawPage3Cursor ( ayCursorPositionP3[0], ayCursorPositionP3[1] );
// Draw "Active" indicator Arrow
drawPage3ActiveIndicator( yActiveIndicatorPosition );
}
// Update Display
display.sendBuffer();
}
// Page to display
static void displayPage( byte yPageNumber )
{
if ( ( PAGE_NO_1 == yPageNumber ) && !bPage1Initialized )
{
displayInitialSetupPage( yPageNumber, true, true );
bPage1Initialized = true;
bPage2Initialized = false;
bPage3Initialized = false;
}
else if( ( PAGE_NO_2 == yPageNumber ) && !bPage2Initialized )
{
displayInitialSetupPage( yPageNumber, true, true );
bPage1Initialized = false;
bPage2Initialized = true;
bPage3Initialized = false;
}
else if( ( PAGE_NO_3 == yPageNumber ) && !bPage3Initialized )
{
displayInitialSetupPage( yPageNumber, true, true );
bPage1Initialized = false;
bPage2Initialized = false;
bPage3Initialized = true;
}
else
{
if ( bDrawPage1Buttons )
{
if ( PAGE_NO_1 == yCurrentPage ) setButtonStates( wButtonStatesP1 );
if ( PAGE_NO_2 == yCurrentPage ) setButtonStates( wButtonStatesP2 );
// Clear Old Values
display.setDrawColor(0); // Setting DrawColor to Clear individual Pixels
display.drawXBMP( PAGE1COL1, PAGE1ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL2, PAGE1ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL3, PAGE1ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL4, PAGE1ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL5, PAGE1ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL1, PAGE1ROW2, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL2, PAGE1ROW2, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL3, PAGE1ROW2, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL4, PAGE1ROW2, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE1COL5, PAGE1ROW2, 7, 7, image_ButtonPressed_bits );
// Set the new values
display.setDrawColor(1); // Setting DrawColor back
display.drawXBMP( PAGE1COL1, PAGE1ROW1, 7, 7, pButton1 );
display.drawXBMP( PAGE1COL2, PAGE1ROW1, 7, 7, pButton2 );
display.drawXBMP( PAGE1COL3, PAGE1ROW1, 7, 7, pButton3 );
display.drawXBMP( PAGE1COL4, PAGE1ROW1, 7, 7, pButton4 );
display.drawXBMP( PAGE1COL5, PAGE1ROW1, 7, 7, pButton5 );
display.drawXBMP( PAGE1COL1, PAGE1ROW2, 7, 7, pButton6 );
display.drawXBMP( PAGE1COL2, PAGE1ROW2, 7, 7, pButton7 );
display.drawXBMP( PAGE1COL3, PAGE1ROW2, 7, 7, pButton8 );
display.drawXBMP( PAGE1COL4, PAGE1ROW2, 7, 7, pButton9 );
display.drawXBMP( PAGE1COL5, PAGE1ROW2, 7, 7, pButton10 );
// Update Display
display.sendBuffer();
// Done Updating
bDrawPage1Buttons = false;
}
if ( bDrawPage1Cursor )
{
drawPage1Cursor ( ayCursorPositionP12[0], ayCursorPositionP12[1] );
// Update Display
display.sendBuffer();
// Done Updating
bDrawPage1Cursor = false;
}
if ( bDrawPage3Buttons )
{
setButtonStates( wButtonStatesP3 );
// Clear Old Values
display.setDrawColor(0); // Setting DrawColor to Clear individual Pixels
display.drawXBMP( PAGE3COL1, PAGE3ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE3COL2, PAGE3ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE3COL3, PAGE3ROW1, 7, 7, image_ButtonPressed_bits );
display.drawXBMP( PAGE3COL4, PAGE3ROW1, 7, 7, image_ButtonPressed_bits );
// Set the new values
display.setDrawColor(1); // Setting DrawColor back
display.drawXBMP( PAGE3COL1, PAGE3ROW1, 7, 7, pButton11 );
display.drawXBMP( PAGE3COL2, PAGE3ROW1, 7, 7, pButton12 );
display.drawXBMP( PAGE3COL3, PAGE3ROW1, 7, 7, pButton13 );
display.drawXBMP( PAGE3COL4, PAGE3ROW1, 7, 7, pButton14 );
// Update Display
display.sendBuffer();
// Done Updating
bDrawPage3Buttons = false;
}
if ( bDrawPage3Cursor )
{
drawPage3Cursor ( ayCursorPositionP3[0], ayCursorPositionP3[1] );
// Update Display
display.sendBuffer();
// Done Updating
bDrawPage3Cursor = false;
}
if ( bDrawActiveIndicator )
{
drawPage3ActiveIndicator ( yActiveIndicatorPosition );
// Update Display
display.sendBuffer();
// Done
bDrawActiveIndicator = false;
}
}
}
void display_exec( bool bMoveCursorLeft, bool bMoveCursorRight, bool bMoveActiveIndicator )
{
if ( g_lStartTime != BOOT_DONE )
{
if ( ( millis() - g_lStartTime ) < BOOT_LOGO_TIME )
{
return;
}
else
{
g_lStartTime = BOOT_DONE;
setIndividualColor( DISPLAY_BACKLIGHT, iGreenBg ); // Display background
}
}
//--------------
// Backlight
//--------------
if ( ircomm_event_flag()
|| bkmcomm_event_flag()
|| bMoveActiveIndicator
)
{
// Update timestamp
g_lLastInputEvent = millis();
}
// Disable backlight when idle
if ( ( ( millis() - g_lLastInputEvent ) > TIMEOUT_BACKLIGHT ) )
{
if( !g_bBacklightIsIdle )
{
pixels.setBrightness( BRIGHTNESS_LCD_IDLE );
pixels.show();
g_bBacklightIsIdle = true;
}
}
else
{
if ( g_bBacklightIsIdle )
{
pixels.setBrightness( g_yBrightness );
if ( !bMoveActiveIndicator ) pixels.show(); // The Active Indicator Button triggers its own "Show"
g_bBacklightIsIdle = false; // and it can appearently only be called once per cycle
}
}
//------------------------------
// process Inputs
//
// Input signals have to already
// be rising edge signals!
//------------------------------
wButtonStatesP1Buff = wButtonStatesP1;
wButtonStatesP2Buff = wButtonStatesP2;
wButtonStatesP3Buff = wButtonStatesP3;
// Now the function bool-Array has to be passed on
// to the Bitfields of the three pages
updateButtonBitfields();
// if a function was updated, the display has to be redrawn
if ( ( PAGE_NO_1 == yCurrentPage ) || ( PAGE_NO_2 == yCurrentPage ) )
{
if ( wButtonStatesP1Buff != wButtonStatesP1 ) bDrawPage1Buttons = true;
if ( wButtonStatesP2Buff != wButtonStatesP2 ) bDrawPage1Buttons = true;
}
if ( PAGE_NO_3 == yCurrentPage )
{
if ( wButtonStatesP3Buff != wButtonStatesP3 ) bDrawPage3Buttons = true;
}
//---------------
// move cursor
//---------------
//------------------
// Moving right
//------------------
if ( bMoveCursorRight )
{
// Rising Edge detected -> Move Cursor to the Right
if ( ( PAGE_NO_1 == yCurrentPage ) || ( PAGE_NO_2 == yCurrentPage ) )
{
if ( PAGE1COL5 == ayCursorPositionP12[0] )
{
// Special 1: Cursor is at the end of its Row:
if ( PAGE1ROW1CURSOR == ayCursorPositionP12[1] )
{
// End of first Row -> jump to 2nd Row, 1st Col
ayCursorPositionP12[0] = PAGE1COL1;
ayCursorPositionP12[1] = PAGE1ROW2CURSOR;
bDrawPage1Cursor = true;
}
else if ( ayCursorPositionP12[1] == PAGE1ROW2CURSOR )
{
// End of second Row -> jump to next page
ayCursorPositionP12[0] = PAGE1COL1;
ayCursorPositionP12[1] = PAGE1ROW1CURSOR;
// Always jump to Page 3
// Page 1 or 2 is dependent on Shift Button
yCurrentPage = PAGE_NO_3;
ayCursorPositionP3[0] = PAGE3COL1;
}
else
{
}
}
else
{
// Jump X-position by one Column
ayCursorPositionP12[0] += 25;
bDrawPage1Cursor = true;
}
}
else if ( PAGE_NO_3 == yCurrentPage )
{
// Page 3
// Special: Cursor is at the end
if ( PAGE3COL4 == ayCursorPositionP3[0] )
{
// Setting up Cursor pos for coming page 1/2
ayCursorPositionP12[0] = PAGE1COL1;
ayCursorPositionP12[1] = PAGE1ROW1CURSOR;
if ( abButtonStates[ IDX_SHIFT ] )
{
// Shifted buttons
yCurrentPage = PAGE_NO_2;
}
else
{
// Non-shifted buttons
yCurrentPage = PAGE_NO_1;
}
}
else
{
ayCursorPositionP3[0] += 32;
bDrawPage3Cursor = true;
}
}
else
{}
}
//------------------
// Moving left
//------------------
if ( bMoveCursorLeft )
{
// Rising Edge detected -> Move Cursor to the Left
if ( ( PAGE_NO_1 == yCurrentPage ) || ( PAGE_NO_2 == yCurrentPage ) )
{
if ( PAGE1COL1 == ayCursorPositionP12[0] )
{
// Special 1: Cursor is at the end of its Row:
if ( PAGE1ROW2CURSOR == ayCursorPositionP12[1] )
{
// End of second Row -> jump to 1st Row, 5th Col
ayCursorPositionP12[0] = PAGE1COL5;
ayCursorPositionP12[1] = PAGE1ROW1CURSOR;
bDrawPage1Cursor = true;
}
else if ( ayCursorPositionP12[1] == PAGE1ROW1CURSOR )
{
// End of first Row -> jump to previous page
ayCursorPositionP12[0] = PAGE1COL5;
ayCursorPositionP12[1] = PAGE1ROW2CURSOR;
// Always jumps to page 3, p1 or p2 is determined by SHIFT
yCurrentPage = PAGE_NO_3;
ayCursorPositionP3[0] = PAGE3COL4;
}
else
{
}
}
else
{
// Jump X-position by one Column
ayCursorPositionP12[0] -= 25;
bDrawPage1Cursor = true;
}
}
else if ( PAGE_NO_3 == yCurrentPage )
{
// Page 3
// Special: Cursor is at the end
if ( PAGE3COL1 == ayCursorPositionP3[0] )
{
// Setting up Cursor pos for coming page 1/2
ayCursorPositionP12[0] = PAGE1COL5;
ayCursorPositionP12[1] = PAGE1ROW2CURSOR;
if ( abButtonStates[ IDX_SHIFT ] )
{
// Shifted buttons
yCurrentPage = PAGE_NO_2;
}
else
{
// Non-shifted buttons
yCurrentPage = PAGE_NO_1;
}
}
else
{
ayCursorPositionP3[0] -= 32;
bDrawPage3Cursor = true;
}
}
else
{}
}
//-----------------------------
// Move Active Indicator Arrow
//-----------------------------
if ( bMoveActiveIndicator )
{
if ( yActiveIndicatorPosition < PAGE3COL4 )
{
yActiveIndicatorPosition += PAGE3COLSTEPS;
}
else
{
yActiveIndicatorPosition = PAGE3COL1;
}
if ( PAGE_NO_3 == yCurrentPage )
{
bDrawActiveIndicator = true;
}
if ( g_bShowPotColors )
{
if ( PAGE3COL1 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iRed );
if ( PAGE3COL2 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iGreen );
if ( PAGE3COL3 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iBlue );
if ( PAGE3COL4 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iWhite );
}
}
//---------------------
displayPage( yCurrentPage );
}
//-------------------
// Exported functions
//-------------------
void display_encoder_backlight( bool bOnOff )
{
g_bShowPotColors = bOnOff;
if ( g_bShowPotColors )
{
if ( PAGE3COL1 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iRed );
if ( PAGE3COL2 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iGreen );
if ( PAGE3COL3 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iBlue );
if ( PAGE3COL4 == yActiveIndicatorPosition ) setIndividualColor( ENCODER_BACKLIGHT, iWhite );
}
else
{
setIndividualColor( ENCODER_BACKLIGHT, iOff );
}
}
void display_set_contrast( bool bUp, bool bDown )
{
if ( bUp || bDown )
{
if ( bUp )
{
if ( g_yContrast <= ( CONTRAST_LCD_MAX - CONTRAST_LCD_STEP ) )
{
g_yContrast += CONTRAST_LCD_STEP;
}
else
{
g_yContrast = CONTRAST_LCD_MAX;
}
}
if ( bDown )
{
if ( g_yContrast >= ( CONTRAST_LCD_MIN + CONTRAST_LCD_STEP ) )
{
g_yContrast -= CONTRAST_LCD_STEP;
}
else
{
g_yContrast = CONTRAST_LCD_MIN;
}
}
Serial.print( "Contrast: ");
Serial.println( g_yContrast );
display.setContrast( g_yContrast );
}
}
void display_set_brightness( bool bUp, bool bDown )
{
if ( bUp )
{
if ( g_yBrightness <= ( BRIGHTNESS_LCD_MAX - BRIGHTNESS_LCD_STEP ) )
{
g_yBrightness += BRIGHTNESS_LCD_STEP;
}
else if ( g_yBrightness == BRIGHTNESS_LCD_MAX )
{
g_yBrightness = BRIGHTNESS_LCD_MIN;
}
else
{
g_yBrightness = BRIGHTNESS_LCD_MAX;
}
}
if ( bDown )
{
if ( g_yBrightness >= ( BRIGHTNESS_LCD_MIN + BRIGHTNESS_LCD_STEP ) )
{
g_yBrightness -= BRIGHTNESS_LCD_STEP;
}
else if ( g_yBrightness == BRIGHTNESS_LCD_MIN )
{
g_yBrightness = BRIGHTNESS_LCD_MAX;
}
else
{
g_yBrightness = BRIGHTNESS_LCD_MIN;
}
}
if ( bUp || bDown )
{
Serial.print( "Brightness: ");
Serial.println( g_yBrightness );
pixels.setBrightness( g_yBrightness );
pixels.show();
}
}
byte display_read_highlighted_function( void )
{
// give the current highlighted function to
// send out the OpCode to the monitor
byte yReturnVal = 0;
if ( PAGE_NO_1 == yCurrentPage )
{
if ( PAGE1ROW1CURSOR == ayCursorPositionP12[1] )
{
// First Row
if ( PAGE1COL1 == ayCursorPositionP12[0] ) yReturnVal = IDX_SHIFT;
if ( PAGE1COL2 == ayCursorPositionP12[0] ) yReturnVal = IDX_F1;
if ( PAGE1COL3 == ayCursorPositionP12[0] ) yReturnVal = IDX_HDELAY;
if ( PAGE1COL4 == ayCursorPositionP12[0] ) yReturnVal = IDX_APT;
if ( PAGE1COL5 == ayCursorPositionP12[0] ) yReturnVal = IDX_MONO;
}
if ( PAGE1ROW2CURSOR == ayCursorPositionP12[1] )
{
// Second Row
if ( PAGE1COL1 == ayCursorPositionP12[0] ) yReturnVal = IDX_UNDERSCAN;
if ( PAGE1COL2 == ayCursorPositionP12[0] ) yReturnVal = IDX_F2;
if ( PAGE1COL3 == ayCursorPositionP12[0] ) yReturnVal = IDX_VDELAY;
if ( PAGE1COL4 == ayCursorPositionP12[0] ) yReturnVal = IDX_COMB;
if ( PAGE1COL5 == ayCursorPositionP12[0] ) yReturnVal = IDX_ADDRESS;
}
}
if ( PAGE_NO_2 == yCurrentPage )
{
if ( PAGE1ROW1CURSOR == ayCursorPositionP12[1] )
{
// First Row
if ( PAGE1COL1 == ayCursorPositionP12[0] ) yReturnVal = IDX_SHIFT;
if ( PAGE1COL2 == ayCursorPositionP12[0] ) yReturnVal = IDX_F3;
if ( PAGE1COL3 == ayCursorPositionP12[0] ) yReturnVal = IDX_RED;
if ( PAGE1COL4 == ayCursorPositionP12[0] ) yReturnVal = IDX_GREEN;
if ( PAGE1COL5 == ayCursorPositionP12[0] ) yReturnVal = IDX_BLUE;
}
if ( PAGE1ROW2CURSOR == ayCursorPositionP12[1] )
{
// Second Row
if ( PAGE1COL1 == ayCursorPositionP12[0] ) yReturnVal = IDX_SYNC;
if ( PAGE1COL2 == ayCursorPositionP12[0] ) yReturnVal = IDX_F4;
if ( PAGE1COL3 == ayCursorPositionP12[0] ) yReturnVal = IDX_16BY9;
if ( PAGE1COL4 == ayCursorPositionP12[0] ) yReturnVal = IDX_BLUEONLY;
if ( PAGE1COL5 == ayCursorPositionP12[0] ) yReturnVal = IDX_SAFEAREA;
}
}
if ( PAGE_NO_3 == yCurrentPage )
{
if ( PAGE3COL1 == ayCursorPositionP3[0] ) yReturnVal = IDX_PHASE;
if ( PAGE3COL2 == ayCursorPositionP3[0] ) yReturnVal = IDX_CHROMA;
if ( PAGE3COL3 == ayCursorPositionP3[0] ) yReturnVal = IDX_BRIGHTNESS;
if ( PAGE3COL4 == ayCursorPositionP3[0] ) yReturnVal = IDX_CONTRAST;
}
return yReturnVal;
}
byte display_read_active_encoder( void )
{
byte yRetVal = IDX_PHASE;
if ( PAGE3COL1 == yActiveIndicatorPosition ) yRetVal = IDX_PHASE;
if ( PAGE3COL2 == yActiveIndicatorPosition ) yRetVal = IDX_CHROMA;
if ( PAGE3COL3 == yActiveIndicatorPosition ) yRetVal = IDX_BRIGHTNESS;
if ( PAGE3COL4 == yActiveIndicatorPosition ) yRetVal = IDX_CONTRAST;
return yRetVal;
}
bool display_set_function_button( byte yFunctionIdx, bool bValue )
{
bool bRetVal = false;
// Set Button state according to the monitor's response
if ( yFunctionIdx < BUTTON_NUM )
{
// valid Index
// Special: If Shift is toggled, the page has to switch
if ( IDX_SHIFT == yFunctionIdx )
{
if ( !abButtonStates[ yFunctionIdx ] && bValue )
{
// Shift was off and now on
// Shift Mode - Yellow Backgound
setIndividualColor( DISPLAY_BACKLIGHT, iYellowBg );
if ( ( yCurrentPage == PAGE_NO_1 ) || ( yCurrentPage == PAGE_NO_2 ) )
{
// Shift was false and is now true --> change to Page 2
yCurrentPage = PAGE_NO_2;
Serial.println( "Should now be Page 2" );
}
}
else if ( abButtonStates[ yFunctionIdx ] && !bValue )
{
// Shift was on and now off
// normal Mode - Green Backgound
setIndividualColor( DISPLAY_BACKLIGHT, iGreenBg );
if ( ( yCurrentPage == PAGE_NO_1 ) || ( yCurrentPage == PAGE_NO_2 ) )
{
// Shift was true and is now false --> change to Page 1
yCurrentPage = PAGE_NO_1;
Serial.println( "Should now be Page 1" );
}
}
}
abButtonStates[ yFunctionIdx ] = bValue;
bRetVal = true;
}
return bRetVal;
}
void display_init( void )
{
SPI.setTX( PIN_LCD_SPI_MOSI );
SPI.setSCK( PIN_LCD_SPI_SCK );
SPI.setRX( 4 ); // unused
SPI.setCS( 5 ); // unused
display.begin();
display.setContrast( CONTRAST_LCD_DEF );
// Display Sony Logo
displayBootLogo();
// Hintergrundbeleuchung
pixels.begin();
pixels.setPixelColor( LED_BACKGROUND, iWhiteBg ); // Display background
if ( g_bShowPotColors )
{
pixels.setPixelColor( LED_ENCODER_1, iRed ); // Encoder Pot LED 1
pixels.setPixelColor( LED_ENCODER_2, iRed ); // Encoder Pot LED 2
}
pixels.setBrightness( g_yBrightness );
pixels.show();
}