forked from RF1000community/Repetier-Firmware
/
ui.cpp
5248 lines (4851 loc) · 194 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 the Repetier-Firmware for RF devices from Conrad Electronic SE.
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
#include "Repetier.h"
extern const int8_t encoder_table[16] PROGMEM;
#include <math.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#if UI_PRINT_AUTORETURN_TO_MENU_AFTER || UI_MILL_AUTORETURN_TO_MENU_AFTER
millis_t g_nAutoReturnTime = 0;
bool g_nAutoReturnMessage = false;
#endif // UI_PRINT_AUTORETURN_TO_MENU_AFTER || UI_MILL_AUTORETURN_TO_MENU_AFTER
char g_nYesNo = 0; // 0 = no, 1 = yes
volatile char g_nContinueButtonPressed = 0;
char g_nServiceRequest = 0;
void beep(uint8_t duration, uint8_t count) {
#if FEATURE_BEEPER && defined(BEEPER_PIN) && BEEPER_PIN >= 0
if (!Printer::enableBeeper) {
// we shall not beep
return;
}
SET_OUTPUT(BEEPER_PIN);
#ifndef BEEPER_TYPE_INVERTING
#define BEEPER_TYPE_INVERTING false
#endif // BEEPER_TYPE_INVERTING
for (uint8_t i = 0; i < count; i++) {
#if BEEPER_TYPE_INVERTING
WRITE(BEEPER_PIN, LOW);
HAL::delayMilliseconds(duration);
WRITE(BEEPER_PIN, HIGH);
#else
WRITE(BEEPER_PIN, HIGH);
HAL::delayMilliseconds(duration);
WRITE(BEEPER_PIN, LOW);
#endif // BEEPER_TYPE_INVERTING
HAL::delayMilliseconds(duration);
}
#endif // FEATURE_BEEPER && defined(BEEPER_PIN) && BEEPER_PIN>=0
} // beep
bool UIMenuEntry::showEntry() const {
bool ret = true;
uint8_t f, f2;
f = HAL::readFlashByte((const prog_char*)&filter);
if (f != 0)
ret = (f & Printer::menuMode) != 0;
f2 = HAL::readFlashByte((const prog_char*)&nofilter);
if (ret && f2 != 0) {
ret = (f2 & Printer::menuMode) == 0;
}
return ret;
} // showEntry
#if UI_DISPLAY_TYPE != 0
UIDisplay uid;
char displayCache[UI_ROWS][MAX_COLS + 1];
// Menu up sign - code 1
// ..*.. 4
// .***. 14
// *.*.* 21
// ..*.. 4
// ***.. 28
// ..... 0
// ..... 0
// ..... 0
const uint8_t character_back[8] PROGMEM = { 4, 14, 21, 4, 28, 0, 0, 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 };
const byte c1[8] PROGMEM = {
B00000,
B00000,
B00000,
B00000,
B00001,
B00010,
B00011,
B00011
};
const byte c2[8] PROGMEM = {
B00000,
B00000,
B00101,
B01011,
B01111,
B10111,
B11111,
B11110
};
const byte c3[8] PROGMEM = {
B00000,
B01001,
B10110,
B01111,
B11111,
B11111,
B00111,
B00011
};
const byte c4[8] PROGMEM = {
B01111,
B01011,
B01111,
B01111,
B10111,
B10111,
B01111,
B10111
};
const byte c7[8] PROGMEM = {
B01111,
B10111,
B01011,
B00111,
B00001,
B00011,
B00000,
B00000
};
const byte c8[8] PROGMEM = {
B00000,
B11000,
B11000,
B11100,
B11110,
B11111,
B11111,
B00111
};
const byte c9[8] PROGMEM = {
B00000,
B00000,
B00001,
B00011,
B10111,
B11111,
B11111,
B11110
};
bool normalchars = false;
#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 == 1 || UI_DISPLAY_TYPE == 2
UIDisplay::UIDisplay() {
locked = 0;
} // UIDisplay
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);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
} // lcdWriteNibble
void lcdWriteByte(uint8_t c, uint8_t rs) {
#if UI_DISPLAY_RW_PIN < 0
HAL::delayMicroseconds(UI_DELAYPERCHAR);
#else
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);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
busy = READ(UI_DISPLAY_D7_PIN);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
} 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 // UI_DISPLAY_RW_PIN<0
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);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
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);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");
} // lcdWriteByte
void initCspecchars() {
uid.createChar(1, c1);
uid.createChar(2, c2);
uid.createChar(3, c3);
uid.createChar(4, c4);
uid.createChar(5, c7);
uid.createChar(6, c8);
uid.createChar(7, c9);
normalchars = false;
}
void initNSpecchars() {
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);
normalchars = true;
}
void UIDisplay::initializeLCD(bool normal) {
// bring all display pins into a defined state
SET_INPUT(UI_DISPLAY_D4_PIN);
SET_INPUT(UI_DISPLAY_D5_PIN);
SET_INPUT(UI_DISPLAY_D6_PIN);
SET_INPUT(UI_DISPLAY_D7_PIN);
SET_INPUT(UI_DISPLAY_RS_PIN);
#if UI_DISPLAY_RW_PIN > -1
SET_INPUT(UI_DISPLAY_RW_PIN);
#endif // UI_DISPLAY_RW_PIN>-1
SET_INPUT(UI_DISPLAY_ENABLE_PIN);
// 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(500);
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 // UI_DISPLAY_RW_PIN>-1
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(10);
lcdWriteNibble(0x03);
HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough.
// second try
lcdWriteNibble(0x03);
HAL::delayMicroseconds(150); // wait
// third go!
lcdWriteNibble(0x03);
HAL::delayMicroseconds(150);
// finally, set to 4-bit interface
lcdWriteNibble(0x02);
HAL::delayMicroseconds(150);
// finally, set # lines, font size, etc.
lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7);
lcdCommand(LCD_CLEAR); //- Clear Screen
HAL::delayMilliseconds(2); // 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();
if (normal) {
initNSpecchars();
}
} // initializeLCD
// ----------- end direct LCD driver
void UIDisplay::printRow(uint8_t r, char* txt, char* txt2, uint8_t changeAtCol) {
#if MAX_COLS < UI_COLS && FEATURE_SEE_DISPLAY
#error if you set MAX_COLS to a tiny value you risk overflows. Probably not only within FEATURE_SEE_DISPLAY
#endif
changeAtCol = RMath::min((uint8_t)UI_COLS, changeAtCol);
uint8_t col = 0;
// Set row
if (r >= UI_ROWS)
return;
lcdWriteByte(128 + HAL::readFlashByte((const char*)&LCDLineOffsets[r]), 0); // Position cursor
char c;
while ((c = *txt) != 0x00 && col < changeAtCol) {
txt++;
lcdPutChar(c);
#if FEATURE_SEE_DISPLAY
//cache whatever you write to the display!
displayCache[r][col] = c;
#endif //FEATURE_SEE_DISPLAY
col++;
}
while (col < changeAtCol) {
lcdPutChar(' ');
#if FEATURE_SEE_DISPLAY
//cache whatever you write to the display!
displayCache[r][col] = ' ';
#endif //FEATURE_SEE_DISPLAY
col++;
}
if (txt2 != NULL) {
while ((c = *txt2) != 0x00 && col < UI_COLS) {
txt2++;
lcdPutChar(c);
#if FEATURE_SEE_DISPLAY
//cache whatever you write to the display!
displayCache[r][col] = c;
#endif //FEATURE_SEE_DISPLAY
col++;
}
while (col < UI_COLS) {
lcdPutChar(' ');
#if FEATURE_SEE_DISPLAY
//cache whatever you write to the display!
displayCache[r][col] = ' ';
#endif //FEATURE_SEE_DISPLAY
col++;
}
}
#if FEATURE_SEE_DISPLAY
//if we had sdcard files last we would see more than 20 bytes. Keep 0 at end.
displayCache[r][col] = 0;
#endif //FEATURE_SEE_DISPLAY
} // printRow
#endif // UI_DISPLAY_TYPE==1 || UI_DISPLAY_TYPE==2
void UIDisplay::ui_init_keys() {
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_1); // push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_2); // push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_3); // push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_4); // push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_5); // push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E1); // PINJ.2, 80, X12.1 - push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E2); // PINJ.4, 81, X12.2 - push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E3); // PINJ.5, 82, X12.3 - push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E4); // PINJ.6, 83, X12.4 - push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E5); // PINH.7, 85, X12.6 - push button, connects gnd to pin
UI_KEYS_INIT_BUTTON_LOW(ENABLE_KEY_E6); // PINH.2, 86, X12.7 - push button, connects gnd to pin
} // ui_init_keys
void UIDisplay::ui_check_keys(int& action) {
UI_KEYS_BUTTON_LOW(ENABLE_KEY_1, UI_ACTION_OK); // push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_2, UI_ACTION_NEXT); // push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_5, UI_ACTION_PREVIOUS); // push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_4, UI_ACTION_BACK); // push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_3, UI_ACTION_RIGHT); // push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E1, UI_ACTION_RF_HEAT_BED_UP); // PINJ.2, 80, X12.1 - push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E2, UI_ACTION_RF_HEAT_BED_DOWN); // PINJ.4, 81, X12.2 - push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E3, UI_ACTION_RF_EXTRUDER_RETRACT); // PINJ.5, 82, X12.3 - push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E4, UI_ACTION_RF_EXTRUDER_OUTPUT); // PINJ.6, 83, X12.4 - push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E5, UI_ACTION_RF_CONTINUE); // PINH.7, 85, X12.6 - push button, connects gnd to pin
UI_KEYS_BUTTON_LOW(ENABLE_KEY_E6, UI_ACTION_RF_PAUSE); // PINH.2, 86, X12.7 - push button, connects gnd to pin
} // ui_check_keys
void UIDisplay::initialize() {
flags = 0;
exitmenu();
shift = -2;
lastAction = 0;
lastButtonAction = 0;
activeAction = 0;
statusMsg[0] = 0;
messageLine1 = NULL;
messageLine2 = NULL;
messageLine3 = NULL;
messageLine4 = NULL;
ui_init_keys();
#if SDSUPPORT
cwd[0] = '/';
cwd[1] = 0;
folderLevel = 0;
#endif // SDSUPPORT
initializeLCD(false);
initCspecchars();
for (uint8_t y = 0; y < UI_ROWS; y++)
displayCache[y][0] = 0;
printRowP(0, PSTR(BIGC0));
printRowP(1, PSTR(BIGC1));
#if UI_ROWS > 3
printRowP(UI_ROWS - 2, PSTR(BIGC2));
#endif // UI_ROWS>3
#if UI_ROWS > 2
printRowP(UI_ROWS - 1, PSTR(BIGC3));
#endif // UI_ROWS>2
if (READ(5) == 0 && READ(11) == 0 && READ(42) == 0) {
g_nServiceRequest = 1;
}
} // initialize
#if UI_DISPLAY_TYPE == 1 || UI_DISPLAY_TYPE == 2
void UIDisplay::createChar(uint8_t location, const uint8_t charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
lcdCommand(LCD_SETCGRAMADDR | (location << 3));
for (int i = 0; i < 8; i++) {
lcdPutChar(pgm_read_byte(&(charmap[i])));
}
} // createChar
#endif // UI_DISPLAY_TYPE==1 || UI_DISPLAY_TYPE==2
void UIDisplay::printRowP(uint8_t r, PGM_P txt) {
if (r >= UI_ROWS)
return;
col = 0;
addStringP(txt);
printCols[col] = 0;
printRow(r, printCols, NULL, UI_COLS);
} // printRowP
void UIDisplay::addInt(int value, uint8_t digits, char fillChar) {
if (col >= MAX_COLS)
return;
uint8_t dig = 0, neg = 0;
if (value < 0) {
value = -value;
neg = 1;
dig++;
}
char buf[7]; // Assumes 8-bit chars plus zero byte.
char* str = &buf[6];
buf[6] = 0;
do {
unsigned int m = value;
value /= 10;
char c = m - 10 * value;
*--str = c + '0';
dig++;
} while (value);
if (neg)
printCols[col++] = '-';
if (digits < 6)
while (dig < digits) {
*--str = fillChar; //' ';
dig++;
}
while (*str && col < MAX_COLS) {
printCols[col++] = *str;
str++;
}
} // addInt
void UIDisplay::addLong(long value, char digits) {
if (col >= MAX_COLS)
return;
uint8_t dig = 0, neg = 0;
if (value < 0) {
neg = 1;
value = -value;
dig++;
}
char buf[13]; // Assumes 8-bit chars plus zero byte.
char* str = &buf[12];
buf[12] = 0;
do {
unsigned long m = value;
value /= 10;
char c = m - 10 * value;
*--str = c + '0';
dig++;
} while (value);
if (neg)
printCols[col++] = '-';
if (digits <= 11)
while (dig < digits) {
*--str = ' ';
dig++;
}
while (*str && col < MAX_COLS) {
printCols[col++] = *str;
str++;
}
} // addLong
const float roundingTable[] PROGMEM = { 0.5, 0.05, 0.005, 0.0005, 0.00005 };
void UIDisplay::addFloat(float number, char fixdigits, uint8_t digits) {
if (col >= MAX_COLS)
return;
// Handle negative numbers
if (number < 0.0) {
printCols[col++] = '-';
if (col >= MAX_COLS)
return;
number = -number;
fixdigits--;
}
digits = (digits <= 4 ? digits : 4);
number += pgm_read_float(&roundingTable[digits]); // for correct rounding
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
float remainder = number - (float)int_part;
addLong(int_part, fixdigits);
if (col >= UI_COLS)
return;
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
printCols[col++] = '.';
}
// Extract digits from the remainder one at a time
while (col < MAX_COLS && digits-- > 0) {
remainder *= 10.0;
uint8_t toPrint = uint8_t(remainder);
printCols[col++] = '0' + toPrint;
remainder -= toPrint;
}
} // addFloat
void UIDisplay::addStringP(FSTRINGPARAM(text)) {
while (col < MAX_COLS) {
uint8_t c = HAL::readFlashByte(text++);
if (c == 0)
return;
printCols[col++] = c;
}
} // addStringP
UI_STRING(ui_text_on, UI_TEXT_ON)
UI_STRING(ui_text_off, UI_TEXT_OFF)
UI_STRING(ui_text_0, UI_TEXT_0)
UI_STRING(ui_text_1, UI_TEXT_1)
UI_STRING(ui_text_white, UI_TEXT_WHITE)
UI_STRING(ui_text_color, UI_TEXT_COLOR)
UI_STRING(ui_text_manual, UI_TEXT_MANUAL)
UI_STRING(ui_text_unknown, UI_TEXT_UNKNOWN)
UI_STRING(ui_text_na, UI_TEXT_NA)
UI_STRING(ui_yes, UI_TEXT_YES)
UI_STRING(ui_no, UI_TEXT_NO)
UI_STRING(ui_ok, UI_TEXT_OK)
UI_STRING(ui_fail, UI_TEXT_FAIL)
UI_STRING(ui_neetfix, UI_TEXT_O_SCAN_NEEDFIX)
UI_STRING(ui_up, UI_TEXT_UP)
UI_STRING(ui_down, UI_TEXT_DOWN)
UI_STRING(ui_selected, UI_TEXT_SEL)
UI_STRING(ui_unselected, UI_TEXT_NOSEL)
UI_STRING(ui_text_print_mode, UI_TEXT_PRINT_MODE)
UI_STRING(ui_text_mill_mode, UI_TEXT_MILL_MODE)
UI_STRING(ui_text_z_single, UI_TEXT_Z_SINGLE)
UI_STRING(ui_text_z_circuit, UI_TEXT_Z_CIRCUIT)
UI_STRING(ui_text_z_mode_min, UI_TEXT_Z_MODE_MIN)
UI_STRING(ui_text_z_mode_surface, UI_TEXT_Z_MODE_SURFACE)
UI_STRING(ui_text_z_mode_gcode, UI_TEXT_Z_MODE_GCODE)
UI_STRING(ui_text_z_mode_z_origin, UI_TEXT_Z_MODE_Z_ORIGIN)
UI_STRING(ui_text_hotend_v1, UI_TEXT_HOTEND_V1)
UI_STRING(ui_text_hotend_v2, UI_TEXT_HOTEND_V2)
UI_STRING(ui_text_miller_one_track, UI_TEXT_MILLER_ONE_TRACK)
UI_STRING(ui_text_miller_two_tracks, UI_TEXT_MILLER_TWO_TRACKS)
UI_STRING(ui_text_z_compensation_active, UI_TEXT_Z_COMPENSATION_ACTIVE)
; // needed because the development tool does not recognize the ; within UI_STRING definition right.
void UIDisplay::parse(char* txt, bool ram) {
int ivalue = 0;
float fvalue = 0;
while (col < MAX_COLS) {
char c = (ram ? *(txt++) : pgm_read_byte(txt++));
if (c == 0)
break; // finished
if (c != '%') {
printCols[col++] = c;
continue;
}
// dynamic parameter, parse meaning and replace
char c1 = (ram ? *(txt++) : pgm_read_byte(txt++));
char c2 = (ram ? *(txt++) : pgm_read_byte(txt++));
switch (c1) {
case '%': {
if (c2 == '%' && col < MAX_COLS)
printCols[col++] = '%'; // %%% : The % char
break;
}
case '1': {
if (c2 == '1') { // %11 : Kill Line if Millingmode and use following string for display, else stop here
#if FEATURE_MILLING_MODE
if (Printer::operatingMode == OPERATING_MODE_MILL) {
for (uint8_t n = 0; n < MAX_COLS + 1; n++)
printCols[n] = 0; //clear all text
col = 0; //reset linemarker
} else
#endif // FEATURE_MILLING_MODE
{ //this is not milling mode: stop here
if (col < MAX_COLS)
printCols[col++] = 0; //write 0 to end of string
col = MAX_COLS; //end while
}
}
break;
}
case 'a': // Acceleration settings
{
if (c2 == 'x')
addFloat(Printer::maxAccelerationMMPerSquareSecond[X_AXIS], 5, 0); // %ax : X acceleration during print moves
else if (c2 == 'y')
addFloat(Printer::maxAccelerationMMPerSquareSecond[Y_AXIS], 5, 0); // %ay : Y acceleration during print moves
else if (c2 == 'z')
addFloat(Printer::maxAccelerationMMPerSquareSecond[Z_AXIS], 5, 0); // %az : Z acceleration during print moves
else if (c2 == 'X')
addFloat(Printer::maxTravelAccelerationMMPerSquareSecond[X_AXIS], 5, 0); // %aX : X acceleration during travel moves
else if (c2 == 'Y')
addFloat(Printer::maxTravelAccelerationMMPerSquareSecond[Y_AXIS], 5, 0); // %aY : Y acceleration during travel moves
else if (c2 == 'Z')
addFloat(Printer::maxTravelAccelerationMMPerSquareSecond[Z_AXIS], 5, 0); // %aZ : Z acceleration during travel moves
else if (c2 == 'j')
addFloat(Printer::maxXYJerk, 3, 1); // %aj : Max. jerk
else if (c2 == 'J')
addFloat(Printer::maxZJerk, 3, 2); // %aJ : Max. Z-jerk
break;
}
case 'd': {
if (c2 == 'o')
addStringP(Printer::debugEcho() ? ui_text_on : ui_text_off); // %do : Debug echo state
else if (c2 == 'i')
addStringP(Printer::debugInfo() ? ui_text_on : ui_text_off); // %di : Debug info state
else if (c2 == 'e')
addStringP(Printer::debugErrors() ? ui_text_on : ui_text_off); // %de : Debug error state
else if (c2 == 'd')
addStringP(Printer::debugDryrun() ? ui_text_on : ui_text_off); // %dd : Debug dry run state
else if (c2 == 'b')
addStringP(Printer::enableBeeper ? ui_text_on : ui_text_off); // %db : beeper state
break;
}
case 'D': {
if (c2 == 'x')
addLong(g_nScanXStepSizeMM, 3); // %Dx : scan step size x
else if (c2 == 'y')
addLong(g_nScanYStepSizeMM, 3); // %Dy : scan step size y
break;
}
#if FEATURE_HEAT_BED_Z_COMPENSATION
case 'H': {
if (c2 == 'B')
addLong(g_nActiveHeatBed, 1); // %HB : active heat bed z matrix
else if (c2 == 'O')
addFloat((float)g_offsetZCompensationSteps * Printer::axisMMPerSteps[Z_AXIS] * 1000.0f, 3, 0); // %HO : active heat bed min z offset in um
break;
}
#endif // FEATURE_HEAT_BED_Z_COMPENSATION
#if FEATURE_WORK_PART_Z_COMPENSATION
case 'W': {
if (c2 == 'P')
addLong(g_nActiveWorkPart, 1); // %WP : active work part z matrix
break;
}
#endif // FEATURE_WORK_PART_Z_COMPENSATION
case 'e': // Extruder temperature
{
if (c2 == 'r') // %er : Extruder relative mode
{
addStringP(Printer::relativeExtruderCoordinateMode ? ui_yes : ui_no);
break;
}
#if FEATURE_MILLING_MODE
if (Printer::operatingMode == OPERATING_MODE_MILL) {
// we do not maintain temperatures in milling mode
addStringP(PSTR(" "));
break;
}
#endif // FEATURE_MILLING_MODE
if (c2 == 'w') { //%ew : tell me which sensor(s) are defect.
bool addone = false;
for (uint8_t controller = 0; controller < NUM_TEMPERATURE_LOOPS; controller++) {
TemperatureController* act = tempController[controller];
if (act->isSensorDefect() || act->isSensorDecoupled()) {
if (addone)
addStringP(Com::tSlash);
addone = true;
if (controller < NUM_EXTRUDER) {
if (col < MAX_COLS)
printCols[col++] = 'E';
addInt(controller, 1);
} else if (controller <= NUM_EXTRUDER) {
addStringP(PSTR("Bed"));
} else {
addStringP(PSTR("Opt"));
}
}
}
break;
}
if (Printer::isAnyTempsensorDefect()) {
uint8_t countDefect = 0;
uint8_t countDecoupled = 0;
for (uint8_t controller = 0; controller < NUM_TEMPERATURE_LOOPS; controller++) {
TemperatureController* act = tempController[controller];
if (act->isSensorDefect()) {
countDefect++;
}
if (act->isSensorDecoupled()) {
countDecoupled++;
}
}
if (countDecoupled > countDefect) {
addStringP(PSTR("dec"));
} else {
addStringP(PSTR("def"));
}
break;
}
if (!(Printer::flag2 & PRINTER_FLAG2_GOT_TEMPS)) {
// avoid to show the current temperatures before we have measured them
addStringP(PSTR(" ? "));
break;
}
if (c2 == 'c') {
fvalue = Extruder::current->tempControl.currentTemperatureC; // %ec : Current extruder temperature
} else if (c2 >= '0' && c2 <= '9') {
uint8_t nr = c2 - '0';
fvalue = extruder[nr].tempControl.currentTemperatureC; // %e0..9 : Temp. of extruder 0..9
}
#if HAVE_HEATED_BED
else if (c2 == 'b') {
fvalue = Extruder::getHeatedBedTemperature(); // %eb : Current heated bed temperature
}
#endif // HAVE_HEATED_BED
addFloat(fvalue, 3, 0);
break;
}
case 'E': // Target extruder temperature
{
#if FEATURE_MILLING_MODE
if (Printer::operatingMode == OPERATING_MODE_MILL) {
// we do not maintain temperatures in milling mode
addStringP(PSTR(" "));
break;
}
#endif // FEATURE_MILLING_MODE
if (c2 == 'c') {
fvalue = Extruder::current->tempControl.targetTemperatureC; // %Ec : Target temperature of current extruder
} else if (c2 >= '0' && c2 <= '9') {
fvalue = extruder[c2 - '0'].tempControl.targetTemperatureC; // %E0-9 : Target temperature of extruder 0..9
}
#if HAVE_HEATED_BED
else if (c2 == 'b') {
fvalue = heatedBedController.targetTemperatureC; // %Eb : Target temperature of heated bed
}