This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.cpp
4157 lines (3985 loc) · 149 KB
/
ui.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
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
*/
#define UI_MAIN 1
#include "Repetier.h"
#define UI_ROWS_EXTRA 0
#if UI_DISPLAY_TYPE == DISPLAY_U8G
#if defined(UI_HEAD)
#undef UI_ROWS
#define UI_ROWS (UI_LCD_HEIGHT/UI_FONT_HEIGHT)-1
#undef UI_ROWS_EXTRA
#define UI_ROWS_EXTRA 1
#endif
#endif
// The uimenu.h declares static variables of menus, which must be declared only once.
// It does not define interfaces for other modules, so should never be included elsewhere
#include "uimenu.h"
extern const int8_t encoder_table[16] PROGMEM ;
#include <math.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#if FEATURE_SERVO > 0 && UI_SERVO_CONTROL > 0
#if UI_SERVO_CONTROL == 1 && defined(SERVO0_NEUTRAL_POS)
uint16_t servoPosition = SERVO0_NEUTRAL_POS;
#elif UI_SERVO_CONTROL == 2 && defined(SERVO1_NEUTRAL_POS)
uint16_t servoPosition = SERVO1_NEUTRAL_POS;
#elif UI_SERVO_CONTROL == 3 && defined(SERVO2_NEUTRAL_POS)
uint16_t servoPosition = SERVO2_NEUTRAL_POS;
#elif UI_SERVO_CONTROL == 4 && defined(SERVO3_NEUTRAL_POS)
uint16_t servoPosition = SERVO3_NEUTRAL_POS;
#else
uint16_t servoPosition = 1500;
#endif
#endif
#if BEEPER_TYPE==2 && defined(UI_HAS_I2C_KEYS) && UI_I2C_KEY_ADDRESS!=BEEPER_ADDRESS
#error Beeper address and i2c key address must be identical
#else
#if BEEPER_TYPE==2
#define UI_I2C_KEY_ADDRESS BEEPER_ADDRESS
#endif
#endif
static TemperatureController *currHeaterForSetup; // pointer to extruder or heatbed temperature controller
#if UI_AUTORETURN_TO_MENU_AFTER != 0
millis_t ui_autoreturn_time = 0;
#endif
void beep(uint8_t duration, uint8_t count) {
#if FEATURE_BEEPER
#if BEEPER_TYPE!=0
#if BEEPER_TYPE==1 && defined(BEEPER_PIN) && BEEPER_PIN>=0
SET_OUTPUT(BEEPER_PIN);
#endif
#if BEEPER_TYPE==2
HAL::i2cStartWait(BEEPER_ADDRESS + I2C_WRITE);
#if UI_DISPLAY_I2C_CHIPTYPE==1
HAL::i2cWrite( 0x14); // Start at port a
#endif
#endif
for(uint8_t i = 0; i < count; i++) {
#if BEEPER_TYPE==1 && defined(BEEPER_PIN) && BEEPER_PIN>=0
#if defined(BEEPER_TYPE_INVERTING) && BEEPER_TYPE_INVERTING
WRITE(BEEPER_PIN, LOW);
#else
WRITE(BEEPER_PIN, HIGH);
#endif
#else
#if UI_DISPLAY_I2C_CHIPTYPE==0
#if BEEPER_ADDRESS == UI_DISPLAY_I2C_ADDRESS
HAL::i2cWrite(uid.outputMask & ~BEEPER_PIN);
#else
HAL::i2cWrite(~BEEPER_PIN);
#endif
#endif
#if UI_DISPLAY_I2C_CHIPTYPE==1
HAL::i2cWrite((BEEPER_PIN) | uid.outputMask);
HAL::i2cWrite(((BEEPER_PIN) | uid.outputMask) >> 8);
#endif
#endif
HAL::delayMilliseconds(duration);
#if BEEPER_TYPE==1 && defined(BEEPER_PIN) && BEEPER_PIN>=0
#if defined(BEEPER_TYPE_INVERTING) && BEEPER_TYPE_INVERTING
WRITE(BEEPER_PIN, HIGH);
#else
WRITE(BEEPER_PIN, LOW);
#endif
#else
#if UI_DISPLAY_I2C_CHIPTYPE==0
#if BEEPER_ADDRESS == UI_DISPLAY_I2C_ADDRESS
HAL::i2cWrite((BEEPER_PIN) | uid.outputMask);
#else
HAL::i2cWrite(255);
#endif
#endif
#if UI_DISPLAY_I2C_CHIPTYPE==1
HAL::i2cWrite( uid.outputMask);
HAL::i2cWrite(uid.outputMask >> 8);
#endif
#endif
HAL::delayMilliseconds(duration);
}
#if BEEPER_TYPE==2
HAL::i2cStop();
#endif
#endif
#endif
}
bool UIMenuEntry::showEntry() const {
bool ret = true;
uint16_t f, f2;
f = HAL::readFlashByte((PGM_P)&filter);
if(f != 0)
ret = (f & Printer::menuMode) == f;
if(ret && (f2 = HAL::readFlashWord((PGM_P)&nofilter)) != 0)
ret = (f2 & Printer::menuMode) == 0;
return ret;
}
#if UI_DISPLAY_TYPE != NO_DISPLAY
UIDisplay uid;
// Menu up sign - code 1
// ..*.. 4
// .***. 14
// *.*.* 21
// ..*.. 4
// ..*.. 4
// ..*.. 4
// ***.. 28
// ..... 0
const uint8_t character_back[8] PROGMEM = {4, 14, 21, 4, 4, 4, 28, 0};
// Degrees sign - code 2
// ..*.. 4
// .*.*. 10
// ..*.. 4
// ..... 0
// ..... 0
// ..... 0
// ..... 0
// ..... 0
const uint8_t character_degree[8] PROGMEM = {4, 10, 4, 0, 0, 0, 0, 0};
// selected - code 3
// ..... 0
// ***** 31
// ***** 31
// ***** 31
// ***** 31
// ***** 31
// ***** 31
// ..... 0
// ..... 0
const uint8_t character_selected[8] PROGMEM = {0, 31, 31, 31, 31, 31, 0, 0};
// unselected - code 4
// ..... 0
// ***** 31
// *...* 17
// *...* 17
// *...* 17
// *...* 17
// ***** 31
// ..... 0
// ..... 0
const uint8_t character_unselected[8] PROGMEM = {0, 31, 17, 17, 17, 31, 0, 0};
// unselected - code 5
// ..*.. 4
// .*.*. 10
// .*.*. 10
// .*.*. 10
// .*.*. 10
// .***. 14
// ***** 31
// ***** 31
// .***. 14
const uint8_t character_temperature[8] PROGMEM = {4, 10, 10, 10, 14, 31, 31, 14};
// unselected - code 6
// ..... 0
// ***.. 28
// ***** 31
// *...* 17
// *...* 17
// ***** 31
// ..... 0
// ..... 0
const uint8_t character_folder[8] PROGMEM = {0, 28, 31, 17, 17, 31, 0, 0};
// printer ready - code 7
// *...* 17
// .*.*. 10
// ..*.. 4
// *...* 17
// ..*.. 4
// .*.*. 10
// *...* 17
// *...* 17
const byte character_ready[8] PROGMEM = {17, 10, 4, 17, 4, 10, 17, 17};
const long baudrates[] PROGMEM = {9600, 14400, 19200, 28800, 38400, 56000, 57600, 76800, 111112, 115200, 128000, 230400, 250000, 256000,
460800, 500000, 921600, 1000000, 1500000, 0
};
#define LCD_ENTRYMODE 0x04 /**< Set entrymode */
/** @name GENERAL COMMANDS */
/*@{*/
#define LCD_CLEAR 0x01 /**< Clear screen */
#define LCD_HOME 0x02 /**< Cursor move to first digit */
/*@}*/
/** @name ENTRYMODES */
/*@{*/
#define LCD_ENTRYMODE 0x04 /**< Set entrymode */
#define LCD_INCREASE LCD_ENTRYMODE | 0x02 /**< Set cursor move direction -- Increase */
#define LCD_DECREASE LCD_ENTRYMODE | 0x00 /**< Set cursor move direction -- Decrease */
#define LCD_DISPLAYSHIFTON LCD_ENTRYMODE | 0x01 /**< Display is shifted */
#define LCD_DISPLAYSHIFTOFF LCD_ENTRYMODE | 0x00 /**< Display is not shifted */
/*@}*/
/** @name DISPLAYMODES */
/*@{*/
#define LCD_DISPLAYMODE 0x08 /**< Set displaymode */
#define LCD_DISPLAYON LCD_DISPLAYMODE | 0x04 /**< Display on */
#define LCD_DISPLAYOFF LCD_DISPLAYMODE | 0x00 /**< Display off */
#define LCD_CURSORON LCD_DISPLAYMODE | 0x02 /**< Cursor on */
#define LCD_CURSOROFF LCD_DISPLAYMODE | 0x00 /**< Cursor off */
#define LCD_BLINKINGON LCD_DISPLAYMODE | 0x01 /**< Blinking on */
#define LCD_BLINKINGOFF LCD_DISPLAYMODE | 0x00 /**< Blinking off */
/*@}*/
/** @name SHIFTMODES */
/*@{*/
#define LCD_SHIFTMODE 0x10 /**< Set shiftmode */
#define LCD_DISPLAYSHIFT LCD_SHIFTMODE | 0x08 /**< Display shift */
#define LCD_CURSORMOVE LCD_SHIFTMODE | 0x00 /**< Cursor move */
#define LCD_RIGHT LCD_SHIFTMODE | 0x04 /**< Right shift */
#define LCD_LEFT LCD_SHIFTMODE | 0x00 /**< Left shift */
/*@}*/
/** @name DISPLAY_CONFIGURATION */
/*@{*/
#define LCD_CONFIGURATION 0x20 /**< Set function */
#define LCD_8BIT LCD_CONFIGURATION | 0x10 /**< 8 bits interface */
#define LCD_4BIT LCD_CONFIGURATION | 0x00 /**< 4 bits interface */
#define LCD_2LINE LCD_CONFIGURATION | 0x08 /**< 2 line display */
#define LCD_1LINE LCD_CONFIGURATION | 0x00 /**< 1 line display */
#define LCD_5X10 LCD_CONFIGURATION | 0x04 /**< 5 X 10 dots */
#define LCD_5X7 LCD_CONFIGURATION | 0x00 /**< 5 X 7 dots */
#define LCD_SETCGRAMADDR 0x40
#define lcdPutChar(value) lcdWriteByte(value,1)
#define lcdCommand(value) lcdWriteByte(value,0)
static const uint8_t LCDLineOffsets[] PROGMEM = UI_LINE_OFFSETS;
static const char versionString[] PROGMEM = UI_VERSION_STRING;
#if UI_DISPLAY_TYPE == DISPLAY_I2C
// ============= I2C LCD Display driver ================
inline void lcdStartWrite() {
HAL::i2cStartWait(UI_DISPLAY_I2C_ADDRESS + I2C_WRITE);
#if UI_DISPLAY_I2C_CHIPTYPE == 1
HAL::i2cWrite( 0x14); // Start at port a
#endif
}
inline void lcdStopWrite() {
HAL::i2cStop();
}
void lcdWriteNibble(uint8_t value) {
#if UI_DISPLAY_I2C_CHIPTYPE==0
value |= uid.outputMask;
#if UI_DISPLAY_D4_PIN==1 && UI_DISPLAY_D5_PIN==2 && UI_DISPLAY_D6_PIN==4 && UI_DISPLAY_D7_PIN==8
HAL::i2cWrite((value) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(value);
#else
uint8_t v = (value & 1 ? UI_DISPLAY_D4_PIN : 0) | (value & 2 ? UI_DISPLAY_D5_PIN : 0) | (value & 4 ? UI_DISPLAY_D6_PIN : 0) | (value & 8 ? UI_DISPLAY_D7_PIN : 0);
HAL::i2cWrite((v) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(v);
#
#endif
#endif
#if UI_DISPLAY_I2C_CHIPTYPE==1
unsigned int v = (value & 1 ? UI_DISPLAY_D4_PIN : 0) | (value & 2 ? UI_DISPLAY_D5_PIN : 0) | (value & 4 ? UI_DISPLAY_D6_PIN : 0) | (value & 8 ? UI_DISPLAY_D7_PIN : 0) | uid.outputMask;
unsigned int v2 = v | UI_DISPLAY_ENABLE_PIN;
HAL::i2cWrite(v2 & 255);
HAL::i2cWrite(v2 >> 8);
HAL::i2cWrite(v & 255);
HAL::i2cWrite(v >> 8);
#endif
}
void lcdWriteByte(uint8_t c, uint8_t rs) {
#if UI_DISPLAY_I2C_CHIPTYPE==0
uint8_t mod = (rs ? UI_DISPLAY_RS_PIN : 0) | uid.outputMask; // | (UI_DISPLAY_RW_PIN);
#if UI_DISPLAY_D4_PIN==1 && UI_DISPLAY_D5_PIN==2 && UI_DISPLAY_D6_PIN==4 && UI_DISPLAY_D7_PIN==8
uint8_t value = (c >> 4) | mod;
HAL::i2cWrite((value) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(value);
value = (c & 15) | mod;
HAL::i2cWrite((value) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(value);
#else
uint8_t value = (c & 16 ? UI_DISPLAY_D4_PIN : 0) | (c & 32 ? UI_DISPLAY_D5_PIN : 0) | (c & 64 ? UI_DISPLAY_D6_PIN : 0) | (c & 128 ? UI_DISPLAY_D7_PIN : 0) | mod;
HAL::i2cWrite((value) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(value);
value = (c & 1 ? UI_DISPLAY_D4_PIN : 0) | (c & 2 ? UI_DISPLAY_D5_PIN : 0) | (c & 4 ? UI_DISPLAY_D6_PIN : 0) | (c & 8 ? UI_DISPLAY_D7_PIN : 0) | mod;
HAL::i2cWrite((value) | UI_DISPLAY_ENABLE_PIN);
HAL::i2cWrite(value);
#endif
#endif
#if UI_DISPLAY_I2C_CHIPTYPE==1
unsigned int mod = (rs ? UI_DISPLAY_RS_PIN : 0) | uid.outputMask; // | (UI_DISPLAY_RW_PIN);
unsigned int value = (c & 16 ? UI_DISPLAY_D4_PIN : 0) | (c & 32 ? UI_DISPLAY_D5_PIN : 0) | (c & 64 ? UI_DISPLAY_D6_PIN : 0) | (c & 128 ? UI_DISPLAY_D7_PIN : 0) | mod;
unsigned int value2 = (value) | UI_DISPLAY_ENABLE_PIN;
HAL::i2cWrite(value2 & 255);
HAL::i2cWrite(value2 >> 8);
HAL::i2cWrite(value & 255);
HAL::i2cWrite(value >> 8);
value = (c & 1 ? UI_DISPLAY_D4_PIN : 0) | (c & 2 ? UI_DISPLAY_D5_PIN : 0) | (c & 4 ? UI_DISPLAY_D6_PIN : 0) | (c & 8 ? UI_DISPLAY_D7_PIN : 0) | mod;
value2 = (value) | UI_DISPLAY_ENABLE_PIN;
HAL::i2cWrite(value2 & 255);
HAL::i2cWrite(value2 >> 8);
HAL::i2cWrite(value & 255);
HAL::i2cWrite(value >> 8);
#endif
}
void initializeLCD() {
HAL::delayMilliseconds(235);
lcdStartWrite();
HAL::i2cWrite(uid.outputMask & 255);
#if UI_DISPLAY_I2C_CHIPTYPE==1
HAL::i2cWrite(uid.outputMask >> 8);
#endif
HAL::delayMicroseconds(20);
lcdWriteNibble(0x03);
HAL::delayMicroseconds(6000); // I have one LCD for which 4500 here was not long enough.
// second try
lcdWriteNibble(0x03);
HAL::delayMicroseconds(180); // wait
// third go!
lcdWriteNibble(0x03);
HAL::delayMicroseconds(180);
// finally, set to 4-bit interface
lcdWriteNibble(0x02);
HAL::delayMicroseconds(180);
// finally, set # lines, font size, etc.
lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7);
lcdCommand(LCD_CLEAR); //- Clear Screen
HAL::delayMilliseconds(4); // clear is slow operation
lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter)
lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
uid.createChar(1, character_back);
uid.createChar(2, character_degree);
uid.createChar(3, character_selected);
uid.createChar(4, character_unselected);
uid.createChar(5, character_temperature);
uid.createChar(6, character_folder);
uid.createChar(7, character_ready);
lcdStopWrite();
}
#endif
#if UI_DISPLAY_TYPE == DISPLAY_4BIT || UI_DISPLAY_TYPE == DISPLAY_8BIT
void lcdWriteNibble(uint8_t value) {
WRITE(UI_DISPLAY_D4_PIN, value & 1);
WRITE(UI_DISPLAY_D5_PIN, value & 2);
WRITE(UI_DISPLAY_D6_PIN, value & 4);
WRITE(UI_DISPLAY_D7_PIN, value & 8);
DELAY1MICROSECOND;
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH);// enable pulse must be >450ns
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
HAL::delayMicroseconds(UI_DELAYPERCHAR);
}
void lcdWriteByte(uint8_t c, uint8_t rs) {
#if false && UI_DISPLAY_RW_PIN >= 0 // not really needed
SET_INPUT(UI_DISPLAY_D4_PIN);
SET_INPUT(UI_DISPLAY_D5_PIN);
SET_INPUT(UI_DISPLAY_D6_PIN);
SET_INPUT(UI_DISPLAY_D7_PIN);
WRITE(UI_DISPLAY_RW_PIN, HIGH);
WRITE(UI_DISPLAY_RS_PIN, LOW);
uint8_t busy;
do {
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH);
DELAY1MICROSECOND;
busy = READ(UI_DISPLAY_D7_PIN);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
DELAY2MICROSECOND;
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH);
DELAY2MICROSECOND;
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
DELAY2MICROSECOND;
} while (busy);
SET_OUTPUT(UI_DISPLAY_D4_PIN);
SET_OUTPUT(UI_DISPLAY_D5_PIN);
SET_OUTPUT(UI_DISPLAY_D6_PIN);
SET_OUTPUT(UI_DISPLAY_D7_PIN);
WRITE(UI_DISPLAY_RW_PIN, LOW);
#endif
WRITE(UI_DISPLAY_RS_PIN, rs);
WRITE(UI_DISPLAY_D4_PIN, c & 0x10);
WRITE(UI_DISPLAY_D5_PIN, c & 0x20);
WRITE(UI_DISPLAY_D6_PIN, c & 0x40);
WRITE(UI_DISPLAY_D7_PIN, c & 0x80);
#if FEATURE_CONTROLLER == CONTROLLER_RADDS
HAL::delayMicroseconds(10);
#else
HAL::delayMicroseconds(2);
#endif
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
#if FEATURE_CONTROLLER == CONTROLLER_RADDS
HAL::delayMicroseconds(10);
#else
HAL::delayMicroseconds(2);
#endif
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
WRITE(UI_DISPLAY_D4_PIN, c & 0x01);
WRITE(UI_DISPLAY_D5_PIN, c & 0x02);
WRITE(UI_DISPLAY_D6_PIN, c & 0x04);
WRITE(UI_DISPLAY_D7_PIN, c & 0x08);
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
HAL::delayMicroseconds(100);
}
#ifdef TRY_AUTOREPAIR_LCD_ERRORS
#define HAS_AUTOREPAIR
/* Fast repair function for displays loosing their settings.
Do not call this if your display has no problems.
*/
void repairLCD() {
// Now we pull both RS and R/W low to begin commands
WRITE(UI_DISPLAY_RS_PIN, LOW);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
//put the LCD into 4 bit mode
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
// at this point we are in 8 bit mode but of course in this
// interface 4 pins are dangling unconnected and the values
// on them don't matter for these instructions.
WRITE(UI_DISPLAY_RS_PIN, LOW);
HAL::delayMicroseconds(20);
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough.
// second try
//lcdWriteNibble(0x03);
//HAL::delayMicroseconds(5000); // wait
// third go!
//lcdWriteNibble(0x03);
//HAL::delayMicroseconds(160);
// finally, set to 4-bit interface
lcdWriteNibble(0x02);
HAL::delayMicroseconds(160);
// finally, set # lines, font size, etc.
lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7);
lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter)
lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
uid.createChar(1, character_back);
uid.createChar(2, character_degree);
uid.createChar(3, character_selected);
uid.createChar(4, character_unselected);
uid.createChar(5, character_temperature);
uid.createChar(6, character_folder);
uid.createChar(7, character_ready);
}
#endif
void initializeLCD() {
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way before 4.5V.
// is this delay long enough for all cases??
HAL::delayMilliseconds(235);
SET_OUTPUT(UI_DISPLAY_D4_PIN);
SET_OUTPUT(UI_DISPLAY_D5_PIN);
SET_OUTPUT(UI_DISPLAY_D6_PIN);
SET_OUTPUT(UI_DISPLAY_D7_PIN);
SET_OUTPUT(UI_DISPLAY_RS_PIN);
#if UI_DISPLAY_RW_PIN > -1
SET_OUTPUT(UI_DISPLAY_RW_PIN);
#endif
SET_OUTPUT(UI_DISPLAY_ENABLE_PIN);
// Now we pull both RS and R/W low to begin commands
WRITE(UI_DISPLAY_RS_PIN, LOW);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
//put the LCD into 4 bit mode
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
// at this point we are in 8 bit mode but of course in this
// interface 4 pins are dangling unconnected and the values
// on them don't matter for these instructions.
WRITE(UI_DISPLAY_RS_PIN, LOW);
HAL::delayMicroseconds(20);
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough.
// second try
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000); // wait
// third go!
lcdWriteNibble(0x03);
HAL::delayMicroseconds(160);
// finally, set to 4-bit interface
lcdWriteNibble(0x02);
HAL::delayMicroseconds(160);
// finally, set # lines, font size, etc.
lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7);
lcdCommand(LCD_CLEAR); //- Clear Screen
HAL::delayMilliseconds(3); // clear is slow operation
lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter)
lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
uid.createChar(1, character_back);
uid.createChar(2, character_degree);
uid.createChar(3, character_selected);
uid.createChar(4, character_unselected);
uid.createChar(5, character_temperature);
uid.createChar(6, character_folder);
uid.createChar(7, character_ready);
}
// ----------- end direct LCD driver
#endif
#if UI_DISPLAY_TYPE == DISPLAY_SR
// Native LCD driver for displays connected using shift register (2-wire or 3-wire)
//
// Options:
// #define UI_DISPLAY_TYPE DISPLAY_SR
// #define UI_DISPLAY_DATA_PIN 29
// #define UI_DISPLAY_CLOCK_PIN 28
// #define UI_DISPLAY_ENABLE_PIN -1 // or undefined for 2-wire, pin number for 3-wire
//
// Non-latching shift register (e.g. 74LS164) outputs:
// - Q0 - unused
// - Q1 - unused
// - Q2 - LCD RS
// - Q3 - LCD D4
// - Q4 - LCD D5
// - Q5 - LCD D6
// - Q6 - LCD D7
// - Q7 - LCD ENABLE (via AND gate for 2-wire version, unused for 3-wire)
//
// More info about this:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
// More schematics including latching (74HC595) and non-latching (74LS164) shift registers:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics
// Shift a bit into shift register
static void lcdShiftBit(uint8_t bit) {
WRITE(UI_DISPLAY_DATA_PIN, bit);
WRITE(UI_DISPLAY_CLOCK_PIN, 1);
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_CLOCK_PIN, 0);
HAL::delayMicroseconds(2);
}
// Write a nibble into LCD via SR
void lcdWriteNibble(uint8_t value, uint8_t rs = 0) {
#if !(defined(UI_DISPLAY_ENABLE_PIN) && (UI_DISPLAY_ENABLE_PIN > -1))
// Clear shift register by shifting zero bits (for 2-wire only)
for (uint8_t i = 0; i < 8; ++i)
lcdShiftBit(0);
#endif
// Shift ENABLE bit to AND gate (for 2-wire version). It will be
// set to high for LCD when both Q7 and DATA/EN output are high.
lcdShiftBit(1); // Q7: AND gate
// Shift 4 data bits from value
lcdShiftBit(value & 8); // Q6: LCD D7
lcdShiftBit(value & 4); // Q5: LCD D6
lcdShiftBit(value & 2); // Q4: LCD D5
lcdShiftBit(value & 1); // Q3: LCD D4
// Shift RS bit
lcdShiftBit(rs); // Q2: LCD RS
// Shift 2 unused bits (last must be 0 for 2-wire version)
lcdShiftBit(0); // Q1
lcdShiftBit(0); // Q0, shifts 1 to Q7 that allows EN output
// Strobe ENABLE bit to write data into the LCD using AND gate
// for 2-wire version or dedicated pin for 3-wire
#if defined(UI_DISPLAY_ENABLE_PIN) && (UI_DISPLAY_ENABLE_PIN > -1)
WRITE(UI_DISPLAY_ENABLE_PIN, 1);
#else
WRITE(UI_DISPLAY_DATA_PIN, 1);
#endif
HAL::delayMicroseconds(2);
#if defined(UI_DISPLAY_ENABLE_PIN) && (UI_DISPLAY_ENABLE_PIN > -1)
WRITE(UI_DISPLAY_ENABLE_PIN, 0);
#else
WRITE(UI_DISPLAY_DATA_PIN, 0);
#endif
HAL::delayMicroseconds(UI_DELAYPERCHAR);
}
// Write a byte into LCD via SR
void lcdWriteByte(uint8_t c, uint8_t rs) {
lcdWriteNibble(c >> 4, rs);
lcdWriteNibble(c, rs);
}
// Initialize LCD via SR
void initializeLCD(bool refresh = false) {
if (!refresh) {
// Init LCD pins
SET_OUTPUT(UI_DISPLAY_DATA_PIN);
SET_OUTPUT(UI_DISPLAY_CLOCK_PIN);
WRITE(UI_DISPLAY_DATA_PIN, 0);
WRITE(UI_DISPLAY_CLOCK_PIN, 0);
#if defined(UI_DISPLAY_ENABLE_PIN) && (UI_DISPLAY_ENABLE_PIN > -1)
SET_OUTPUT(UI_DISPLAY_ENABLE_PIN);
WRITE(UI_DISPLAY_ENABLE_PIN, 0);
#endif
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way before 4.5V.
// is this delay long enough for all cases??
HAL::delayMilliseconds(235);
}
// Put the LCD into 4 bit mode
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// We start in 8 bit mode, try to set 4 bit mode
// at this point we are in 8 bit mode but of course in this
// interface 4 pins are dangling unconnected and the values
// on them don't matter for these instructions.
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough.
// Second try
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000);
// Third go!
lcdWriteNibble(0x03);
HAL::delayMicroseconds(160);
// Finally, set to 4-bit interface
lcdWriteNibble(0x02);
HAL::delayMicroseconds(160);
// finally, set # lines, font size, etc.
lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7);
if (!refresh) {
lcdCommand(LCD_CLEAR);
HAL::delayMilliseconds(3); // clear is slow operation
}
lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF);
lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF);
uid.createChar(1, character_back);
uid.createChar(2, character_degree);
uid.createChar(3, character_selected);
uid.createChar(4, character_unselected);
uid.createChar(5, character_temperature);
uid.createChar(6, character_folder);
uid.createChar(7, character_ready);
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
}
#ifdef TRY_AUTOREPAIR_LCD_ERRORS
#define HAS_AUTOREPAIR
// Fast repair function for displays loosing their settings.
// Do not call this if your display has no problems.
void repairLCD() {
// Almost the same as for init except GPIO init and LCD clear
initializeLCD(true);
}
#endif
#endif // UI_DISPLAY_TYPE == DISPLAY_SR
#if UI_DISPLAY_TYPE < DISPLAY_ARDUINO_LIB || UI_DISPLAY_TYPE == DISPLAY_SR
void UIDisplay::printRow(uint8_t r, char *txt, char *txt2, uint8_t changeAtCol) {
changeAtCol = RMath::min(UI_COLS, changeAtCol);
uint8_t col = 0;
// Set row
if(r >= UI_ROWS) return;
#if UI_DISPLAY_TYPE == DISPLAY_I2C
lcdStartWrite();
#endif
lcdWriteByte(128 + HAL::readFlashByte((const char *)&LCDLineOffsets[r]), 0); // Position cursor
char c;
while((c = *txt) != 0x00 && col < changeAtCol) {
txt++;
lcdPutChar(c);
col++;
}
while(col < changeAtCol) {
lcdPutChar(' ');
col++;
}
if(txt2 != NULL) {
while((c = *txt2) != 0x00 && col < UI_COLS) {
txt2++;
lcdPutChar(c);
col++;
}
while(col < UI_COLS) {
lcdPutChar(' ');
col++;
}
}
#if UI_DISPLAY_TYPE == DISPLAY_I2C
lcdStopWrite();
#endif
#if UI_HAS_KEYS==1 && UI_HAS_I2C_ENCODER>0
uiCheckSlowEncoder();
#endif
}
#endif
#if UI_DISPLAY_TYPE == DISPLAY_ARDUINO_LIB
// Use LiquidCrystal library instead
#include <LiquidCrystal.h>
LiquidCrystal lcd(UI_DISPLAY_RS_PIN, UI_DISPLAY_RW_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_D4_PIN, UI_DISPLAY_D5_PIN, UI_DISPLAY_D6_PIN, UI_DISPLAY_D7_PIN);
void UIDisplay::createChar(uint8_t location, const uint8_t charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
uint8_t data[8];
for (int i = 0; i < 8; i++) {
data[i] = pgm_read_byte(&(charmap[i]));
}
lcd.createChar(location, data);
}
void UIDisplay::printRow(uint8_t r, char *txt, char *txt2, uint8_t changeAtCol) {
changeAtCol = RMath::min(UI_COLS, changeAtCol);
uint8_t col = 0;
// Set row
if(r >= UI_ROWS) return;
lcd.setCursor(0, r);
char c;
while((c = *txt) != 0x00 && col < changeAtCol) {
txt++;
lcd.write(c);
col++;
}
while(col < changeAtCol) {
lcd.write(' ');
col++;
}
if(txt2 != NULL) {
while((c = *txt2) != 0x00 && col < UI_COLS) {
txt2++;
lcd.write(c);
col++;
}
while(col < UI_COLS) {
lcd.write(' ');
col++;
}
}
#if UI_HAS_KEYS==1 && UI_HAS_I2C_ENCODER>0
uiCheckSlowEncoder();
#endif
}
void initializeLCD() {
lcd.begin(UI_COLS, UI_ROWS);
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
uid.createChar(1, character_back);
uid.createChar(2, character_degree);
uid.createChar(3, character_selected);
uid.createChar(4, character_unselected);
}
// ------------------ End LiquidCrystal library as LCD driver
#endif // UI_DISPLAY_TYPE == DISPLAY_ARDUINO_LIB
#if UI_DISPLAY_TYPE == DISPLAY_U8G
//u8glib
#if defined(U8GLIB_ST7920) || defined(U8GLIB_SSD1306_SW_SPI)
#define UI_SPI_SCK UI_DISPLAY_D4_PIN
#define UI_SPI_MOSI UI_DISPLAY_ENABLE_PIN
#define UI_SPI_CS UI_DISPLAY_RS_PIN
#endif
#include "u8glib_ex.h"
#include "logo.h"
u8g_t u8g;
u8g_uint_t u8_tx = 0, u8_ty = 0;
void u8PrintChar(char c) {
switch((uint8_t)c) {
case 0x7E: // right arrow
u8g_SetFont(&u8g, u8g_font_6x12_67_75);
u8_tx += u8g_DrawGlyph(&u8g, u8_tx, u8_ty, 0x52);
u8g_SetFont(&u8g, UI_FONT_DEFAULT);
break;
case CHAR_SELECTOR:
u8g_SetFont(&u8g, u8g_font_6x12_67_75);
u8_tx += u8g_DrawGlyph(&u8g, u8_tx, u8_ty, 0xb7);
u8g_SetFont(&u8g, UI_FONT_DEFAULT);
break;
case CHAR_SELECTED:
u8g_SetFont(&u8g, u8g_font_6x12_67_75);
u8_tx += u8g_DrawGlyph(&u8g, u8_tx, u8_ty, 0xb6);
u8g_SetFont(&u8g, UI_FONT_DEFAULT);
break;
case 253: //shift one pixel to right
u8_tx++;
break;
default:
u8_tx += u8g_DrawGlyph(&u8g, u8_tx, u8_ty, c);
}
}
void printU8GRow(uint8_t x, uint8_t y, char *text) {
//if(!u8g_IsBBXIntersection(&u8g,0,y-UI_LCD_WIDTH,UI_FONT_HEIGHT,UI_LCD_WIDTH,UI_FONT_HEIGHT+2)) return; // row not visible
char c;
u8_tx = x;
u8_ty = y;
while((c = *(text++)) != 0) u8PrintChar(c); //version compatible with position adjust
// x += u8g_DrawGlyph(&u8g,x,y,c);
}
void UIDisplay::printRow(uint8_t r, char *txt, char *txt2, uint8_t changeAtCol) {
changeAtCol = RMath::min(UI_COLS, changeAtCol);
uint8_t col = 0;
// Set row
if(r >= UI_ROWS) return;
int y = r * UI_FONT_HEIGHT;
#ifdef UI_HEAD
y += UI_FONT_HEIGHT;
#endif
if(!u8g_IsBBXIntersection(&u8g, 0, y, UI_LCD_WIDTH, UI_FONT_HEIGHT + 2)) return; // row not visible
u8_tx = 0;
u8_ty = y + UI_FONT_HEIGHT; //set position
bool highlight = ((uint8_t)(*txt) == CHAR_SELECTOR) || ((uint8_t)(*txt) == CHAR_SELECTED);
if(highlight) {
u8g_SetColorIndex(&u8g, 1);
u8g_draw_box(&u8g, 0, y + 1, u8g_GetWidth(&u8g), UI_FONT_HEIGHT + 1);
u8g_SetColorIndex(&u8g, 0);
}
char c;
while((c = *(txt++)) != 0 && col < changeAtCol) {
u8PrintChar(c);
col++;
}
if(txt2 != NULL) {
col = changeAtCol;
u8_tx = col * UI_FONT_WIDTH; //set position
while((c = *(txt2++)) != 0 && col < UI_COLS) {
u8PrintChar(c);
col++;
}
}
if(highlight) {
u8g_SetColorIndex(&u8g, 1);
}
#if UI_HAS_KEYS==1 && UI_HAS_I2C_ENCODER>0
uiCheckSlowEncoder();
#endif
}
void initializeLCD() {
#ifdef U8GLIB_MINI12864_2X_SW_SPI
u8g_InitSPI(&u8g, &u8g_dev_uc1701_mini12864_2x_sw_spi, UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, UI_DISPLAY_D5_PIN, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_MINI12864_2X_HW_SPI
u8g_InitHWSPI(&u8g, &u8g_dev_uc1701_mini12864_2x_hw_spi, UI_DISPLAY_RS_PIN, UI_DISPLAY_D5_PIN, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_ST7920
u8g_InitSPI(&u8g, &u8g_dev_st7920_128x64_sw_spi, UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, U8G_PIN_NONE, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_SSD1306_I2C
u8g_InitI2C(&u8g, &u8g_dev_ssd1306_128x64_i2c, U8G_I2C_OPT_NONE);
#endif
#ifdef U8GLIB_SSD1306_SW_SPI
u8g_InitSPI(&u8g, &u8g_dev_ssd1306_128x64_sw_spi, UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, U8G_PIN_NONE, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_SH1106_SW_SPI
u8g_InitSPI(&u8g, &u8g_dev_sh1106_128x64_sw_spi, UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, U8G_PIN_NONE, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_KS0108_FAST
u8g_Init8Bit(&u8g, &u8g_dev_ks0108_128x64_fast, UI_DISPLAY_D0_PIN, UI_DISPLAY_D1_PIN, UI_DISPLAY_D2_PIN, UI_DISPLAY_D3_PIN, UI_DISPLAY_D4_PIN, UI_DISPLAY_D5_PIN, UI_DISPLAY_D6_PIN, UI_DISPLAY_D7_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_CS1, UI_DISPLAY_CS2,
UI_DISPLAY_DI, UI_DISPLAY_RW_PIN, UI_DISPLAY_RESET_PIN);
#endif
#ifdef U8GLIB_KS0108
u8g_Init8Bit(&u8g, &u8g_dev_ks0108_128x64, UI_DISPLAY_D0_PIN, UI_DISPLAY_D1_PIN, UI_DISPLAY_D2_PIN, UI_DISPLAY_D3_PIN, UI_DISPLAY_D4_PIN, UI_DISPLAY_D5_PIN, UI_DISPLAY_D6_PIN, UI_DISPLAY_D7_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_CS1, UI_DISPLAY_CS2,
UI_DISPLAY_DI, UI_DISPLAY_RW_PIN, UI_DISPLAY_RESET_PIN);
#endif
#ifdef U8GLIB_ST7565_NHD_C2832_HW_SPI
u8g_InitHWSPI(&u8g, &u8g_dev_st7565_nhd_c12864_hw_spi, UI_DISPLAY_RS_PIN, UI_DISPLAY_D5_PIN, U8G_PIN_NONE);
#endif
#ifdef U8GLIB_ST7565_NHD_C2832_SW_SPI
u8g_InitSPI(&u8g, &u8g_dev_st7565_nhd_c12864_sw_spi, UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, UI_DISPLAY_D5_PIN, U8G_PIN_NONE);
#endif
u8g_Begin(&u8g);
#ifdef LCD_CONTRAST
u8g_SetContrast(&u8g, LCD_CONTRAST);
#endif
#ifdef UI_ROTATE_180
u8g_SetRot180(&u8g);
#endif
u8g_FirstPage(&u8g);
do {
u8g_SetColorIndex(&u8g, 0);
} while( u8g_NextPage(&u8g) );
u8g_SetFont(&u8g, UI_FONT_DEFAULT);
u8g_SetColorIndex(&u8g, 1);
uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds();
}
// ------------------ End u8GLIB library as LCD driver
#endif // UI_DISPLAY_TYPE == DISPLAY_U8G
#if UI_DISPLAY_TYPE == DISPLAY_GAMEDUINO2
#include "gameduino2.h"
#endif
UIDisplay::UIDisplay() {
}
void UIDisplay::initialize() {
oldMenuLevel = -2;
#ifdef COMPILE_I2C_DRIVER
uid.outputMask = UI_DISPLAY_I2C_OUTPUT_START_MASK;
#if UI_DISPLAY_I2C_CHIPTYPE==0 && BEEPER_TYPE==2 && BEEPER_PIN>=0
#if BEEPER_ADDRESS == UI_DISPLAY_I2C_ADDRESS
uid.outputMask |= BEEPER_PIN;
#endif
#endif
HAL::i2cInit(UI_I2C_CLOCKSPEED);
#if UI_DISPLAY_I2C_CHIPTYPE==1
// set direction of pins
HAL::i2cStart(UI_DISPLAY_I2C_ADDRESS + I2C_WRITE);
HAL::i2cWrite(0); // IODIRA
HAL::i2cWrite(~(UI_DISPLAY_I2C_OUTPUT_PINS & 255));
HAL::i2cWrite(~(UI_DISPLAY_I2C_OUTPUT_PINS >> 8));
HAL::i2cStop();
// Set pull ups according to UI_DISPLAY_I2C_PULLUP
HAL::i2cStart(UI_DISPLAY_I2C_ADDRESS + I2C_WRITE);
HAL::i2cWrite(0x0C); // GPPUA
HAL::i2cWrite(UI_DISPLAY_I2C_PULLUP & 255);
HAL::i2cWrite(UI_DISPLAY_I2C_PULLUP >> 8);
HAL::i2cStop();
#endif
#endif
flags = 0;
menuLevel = 0;
shift = -2;
menuPos[0] = 0;
lastAction = 0;
delayedAction = 0;
lastButtonAction = 0;
activeAction = 0;
statusMsg[0] = 0;
uiInitKeys();
cwd[0] = '/';
cwd[1] = 0;
folderLevel = 0;
UI_STATUS_F(Com::translatedF(UI_TEXT_PRINTER_READY_ID));
#if UI_DISPLAY_TYPE != NO_DISPLAY
initializeLCD();
#if defined(USER_KEY1_PIN) && USER_KEY1_PIN > -1
UI_KEYS_INIT_BUTTON_LOW(USER_KEY1_PIN);