-
Notifications
You must be signed in to change notification settings - Fork 459
/
LCD.cpp
2745 lines (2657 loc) · 104 KB
/
LCD.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
#include "Arduino.h"
#include "config.h"
#include "def.h"
#include "types.h"
#include "MultiWii.h"
#include "Alarms.h"
#include "EEPROM.h"
#include "Output.h"
#include "RX.h"
#include "Serial.h"
#include "Sensors.h"
#include "LCD.h"
void __u8Inc(void * var, int16_t inc);
void __s8Inc(void * var, int16_t inc);
void __u16Inc(void * var, int16_t inc);
void __s16Inc(void * var, int16_t inc);
void __nullInc(void * var, int16_t inc);
void __u8Fmt(void * var, uint8_t mul, uint8_t dec);
void __u16Fmt(void * var, uint8_t mul, uint8_t dec);
void __s8BitsFmt(void * var, uint8_t mul, uint8_t dec);
void __s16Fmt(void * var, uint8_t mul, uint8_t dec);
void __uAuxFmt(void * var, uint8_t mul, uint8_t dec, uint8_t aux);
void __uAuxFmt1(void * var, uint8_t mul, uint8_t dec);
void __uAuxFmt2(void * var, uint8_t mul, uint8_t dec);
void __uAuxFmt3(void * var, uint8_t mul, uint8_t dec);
void __uAuxFmt4(void * var, uint8_t mul, uint8_t dec);
void __upMFmt(void * var, uint8_t mul, uint8_t dec);
void serviceCheckPLog(void);
void i2c_clear_OLED(void);
void LCDnextline(void);
void i2c_OLED_DIGOLE_send_string(const char *string);
// ************************************************************************************************************
// LCD & display & monitoring
// ************************************************************************************************************
// in any of the following cases an LCD is required and
// the primitives for exactly one of the available types are setup
#if defined(LCD_CONF) || defined(LCD_TELEMETRY) || defined(HAS_LCD)
static char line1[17],line2[17];
static char template7[7] = " .... ";
static char template3[3] = ". ";
#ifdef DISPLAY_FONT_DSIZE
static uint8_t line_is_valid = 0;
#endif
#if ( defined(LOG_PERMANENT) && defined(DISPLAY_MULTILINE) )
static uint8_t lnr = 0;
#endif
#define LCD_FLUSH {/*UartSendData();*/ delay(30); }
char digit10000(uint16_t v) {return '0' + v / 10000;}
char digit1000(uint16_t v) {return '0' + v / 1000 - (v/10000) * 10;}
char digit100(uint16_t v) {return '0' + v / 100 - (v/1000) * 10;}
char digit10(uint16_t v) {return '0' + v / 10 - (v/100) * 10;}
char digit1(uint16_t v) {return '0' + v - (v/10) * 10;}
#if defined(OLED_I2C_128x64)
// ########################################
// # i2c OLED display funtion primitives #
// ########################################
#define OLED_address 0x3C // OLED at address 0x3C in 7bit
char LINE_FILL_STRING[] = " "; // Used by clear_OLED() 128 bits / 6 bytes = 21 chars per row
unsigned char CHAR_FORMAT = 0; // use to INVERSE characters
// use INVERSE CHAR_FORMAT = 0b01111111;
// use NORMAL CHAR_FORMAT = 0;
static char buffer; // buffer to read bytes from ROM, using pgm_read_byte macro. NB! avr/pgmspace.h must be included prog_uchar LOGO[] PROGMEM = { // My first attempt to flash a logo....
const uint8_t PROGMEM LOGO[] = { // logo....
0x00, 0x00, 0x02, 0xFE, 0xFE, 0x0E, 0xFC, 0xF8, 0xC0, 0x00, 0xC0, 0xF8, 0xFC, 0x0E, 0xFE, 0xFE,
0xFE, 0x02, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x30, 0xF0, 0xF0, 0x00, 0x00, 0x00,
0x02, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x30, 0xF8, 0xFE, 0x30, 0x30, 0x30, 0x00, 0x00, 0x30, 0xF6,
0xF6, 0x00, 0x00, 0x00, 0x02, 0x06, 0x1E, 0xFE, 0xFE, 0xC2, 0x00, 0xC2, 0xFE, 0x7E, 0xFE, 0xC2,
0x00, 0xC2, 0xFE, 0xFE, 0x3E, 0x06, 0x02, 0x00, 0x30, 0xF6, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x30,
0xF6, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x1F, 0x1F, 0x10, 0x00, 0x83, 0x9F, 0x9F, 0x9F, 0x83, 0x80, 0x90, 0x9F, 0x9F,
0x9F, 0x10, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x18, 0x18, 0x18, 0x0C, 0x1F, 0x1F, 0x10, 0x00, 0x00,
0x10, 0x1F, 0x1F, 0x10, 0x00, 0x80, 0x80, 0x8F, 0x9F, 0x98, 0x9E, 0x8F, 0x80, 0x80, 0x90, 0x1F,
0x1F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x1E, 0x1F, 0x03, 0x00, 0x07, 0x1F,
0x1E, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x1F, 0x10, 0x00, 0x00, 0x00, 0x10,
0x1F, 0x1F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xF8, 0x3C, 0x0E, 0x07, 0x03, 0x03, 0x01, 0x81, 0xC1, 0xC1, 0xC1, 0xC1, 0x81, 0x01,
0x03, 0x03, 0x07, 0x0E, 0x3C, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0,
0xF8, 0x3C, 0x0E, 0x07, 0x03, 0x03, 0x01, 0x81, 0xC1, 0xC1, 0xC1, 0xC1, 0x81, 0x01, 0x03, 0x03,
0x07, 0x0E, 0x3C, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3E, 0xF8, 0xC0,
0xFC, 0x0E, 0xFC, 0xC0, 0xF8, 0x3E, 0x06, 0x00, 0xFE, 0xFE, 0x00, 0x06, 0xFF, 0xFF, 0x86, 0x86,
0x00, 0xFF, 0xFF, 0x0C, 0x06, 0x06, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0x7F, 0xF0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x0C, 0x0F, 0x07, 0x00,
0x00, 0x00, 0x80, 0xC0, 0xF0, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,
0x7F, 0xF0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00,
0x80, 0xC0, 0xF0, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC1, 0xC1,
0x80, 0x80, 0x00, 0x01, 0x01, 0x00, 0x00, 0xC0, 0xC1, 0xC1, 0xC0, 0xC0, 0xC0, 0xC1, 0xC1, 0xC1,
0x80, 0x01, 0x01, 0x00, 0x00, 0x00, 0x81, 0x81, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x03, 0x03, 0x01, 0x03, 0x07, 0x0E, 0x1C, 0x38, 0xF0, 0xE0, 0xE0, 0xF0, 0x38, 0x1C, 0x0E,
0x07, 0x03, 0x01, 0x03, 0x03, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0x07, 0x03, 0x01, 0x01, 0xE1, 0xE1, 0xE1,
0xE3, 0xE7, 0xE7, 0xE6, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x71, 0x71, 0x71, 0x71, 0x7B, 0x7F,
0x3F, 0x1F, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x39, 0x71, 0x71, 0x71, 0xE3, 0xE7, 0xE7, 0x86,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x30, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x38, 0x30, 0x70, 0xE0, 0xF0, 0xB8, 0x1C, 0x0E, 0x07, 0x03, 0x01, 0x01, 0x03, 0x07, 0x0E, 0x1C,
0xB8, 0xF0, 0xE0, 0x70, 0x30, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x38, 0x30,
0x70, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x0E, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
0x0E, 0x0F, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x0F, 0x1E, 0x1C, 0x1C, 0x1C, 0x1C, 0x1E, 0x0F, 0x0F, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFE, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xFC, 0xCC, 0xCC, 0xFC, 0x78, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xFC, 0xCC, 0xCC, 0xFC, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x80, 0x40, 0x20, 0x20, 0x20, 0x40,
0x80, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0xF0, 0x08, 0x04, 0x04, 0x04, 0x08,
0xF0, 0x00, 0x00, 0xE0, 0x5C, 0x44, 0x44, 0x44, 0x84, 0x04, 0x00, 0x00, 0x10, 0x08, 0x04, 0x04,
0x04, 0x8C, 0x70, 0x00, 0x00, 0x30, 0x48, 0x84, 0x84, 0x84, 0x48, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x07, 0x0F, 0x1C, 0x38, 0x30, 0x70, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x70, 0x30, 0x38, 0x1C, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x07, 0x0F, 0x1C, 0x38, 0x30, 0x70, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x30,
0x38, 0x1C, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, 0x07, 0x00, 0x00, 0x0F, 0x12, 0x22, 0x22, 0x22, 0x12,
0x0B, 0x00, 0x00, 0x01, 0x0E, 0x30, 0x0E, 0x01, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10,
0x0F, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, 0x00, 0x20, 0x30, 0x28, 0x24,
0x22, 0x21, 0x20, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, 0x00, 0x00, 0x00
};
const uint8_t PROGMEM myFont[][5] = { // Refer to "Times New Roman" Font Database... 5 x 7 font
{ 0x00,0x00,0x00,0x00,0x00},
{ 0x00,0x00,0x4F,0x00,0x00}, // ( 1) ! - 0x0021 Exclamation Mark
{ 0x00,0x07,0x00,0x07,0x00}, // ( 2) " - 0x0022 Quotation Mark
{ 0x14,0x7F,0x14,0x7F,0x14}, // ( 3) # - 0x0023 Number Sign
{ 0x24,0x2A,0x7F,0x2A,0x12}, // ( 4) $ - 0x0024 Dollar Sign
{ 0x23,0x13,0x08,0x64,0x62}, // ( 5) % - 0x0025 Percent Sign
{ 0x36,0x49,0x55,0x22,0x50}, // ( 6) & - 0x0026 Ampersand
{ 0x00,0x05,0x03,0x00,0x00}, // ( 7) ' - 0x0027 Apostrophe
{ 0x00,0x1C,0x22,0x41,0x00}, // ( 8) ( - 0x0028 Left Parenthesis
{ 0x00,0x41,0x22,0x1C,0x00}, // ( 9) ) - 0x0029 Right Parenthesis
{ 0x14,0x08,0x3E,0x08,0x14}, // ( 10) * - 0x002A Asterisk
{ 0x08,0x08,0x3E,0x08,0x08}, // ( 11) + - 0x002B Plus Sign
{ 0x00,0x50,0x30,0x00,0x00}, // ( 12) , - 0x002C Comma
{ 0x08,0x08,0x08,0x08,0x08}, // ( 13) - - 0x002D Hyphen-Minus
{ 0x00,0x60,0x60,0x00,0x00}, // ( 14) . - 0x002E Full Stop
{ 0x20,0x10,0x08,0x04,0x02}, // ( 15) / - 0x002F Solidus
{ 0x3E,0x51,0x49,0x45,0x3E}, // ( 16) 0 - 0x0030 Digit Zero
{ 0x00,0x42,0x7F,0x40,0x00}, // ( 17) 1 - 0x0031 Digit One
{ 0x42,0x61,0x51,0x49,0x46}, // ( 18) 2 - 0x0032 Digit Two
{ 0x21,0x41,0x45,0x4B,0x31}, // ( 19) 3 - 0x0033 Digit Three
{ 0x18,0x14,0x12,0x7F,0x10}, // ( 20) 4 - 0x0034 Digit Four
{ 0x27,0x45,0x45,0x45,0x39}, // ( 21) 5 - 0x0035 Digit Five
{ 0x3C,0x4A,0x49,0x49,0x30}, // ( 22) 6 - 0x0036 Digit Six
{ 0x01,0x71,0x09,0x05,0x03}, // ( 23) 7 - 0x0037 Digit Seven
{ 0x36,0x49,0x49,0x49,0x36}, // ( 24) 8 - 0x0038 Digit Eight
{ 0x06,0x49,0x49,0x29,0x1E}, // ( 25) 9 - 0x0039 Dight Nine
{ 0x00,0x36,0x36,0x00,0x00}, // ( 26) : - 0x003A Colon
{ 0x00,0x56,0x36,0x00,0x00}, // ( 27) ; - 0x003B Semicolon
{ 0x08,0x14,0x22,0x41,0x00}, // ( 28) < - 0x003C Less-Than Sign
{ 0x14,0x14,0x14,0x14,0x14}, // ( 29) = - 0x003D Equals Sign
{ 0x00,0x41,0x22,0x14,0x08}, // ( 30) > - 0x003E Greater-Than Sign
{ 0x02,0x01,0x51,0x09,0x06}, // ( 31) ? - 0x003F Question Mark
{ 0x32,0x49,0x79,0x41,0x3E}, // ( 32) @ - 0x0040 Commercial At
{ 0x7E,0x11,0x11,0x11,0x7E}, // ( 33) A - 0x0041 Latin Capital Letter A
{ 0x7F,0x49,0x49,0x49,0x36}, // ( 34) B - 0x0042 Latin Capital Letter B
{ 0x3E,0x41,0x41,0x41,0x22}, // ( 35) C - 0x0043 Latin Capital Letter C
{ 0x7F,0x41,0x41,0x22,0x1C}, // ( 36) D - 0x0044 Latin Capital Letter D
{ 0x7F,0x49,0x49,0x49,0x41}, // ( 37) E - 0x0045 Latin Capital Letter E
{ 0x7F,0x09,0x09,0x09,0x01}, // ( 38) F - 0x0046 Latin Capital Letter F
{ 0x3E,0x41,0x49,0x49,0x7A}, // ( 39) G - 0x0047 Latin Capital Letter G
{ 0x7F,0x08,0x08,0x08,0x7F}, // ( 40) H - 0x0048 Latin Capital Letter H
{ 0x00,0x41,0x7F,0x41,0x00}, // ( 41) I - 0x0049 Latin Capital Letter I
{ 0x20,0x40,0x41,0x3F,0x01}, // ( 42) J - 0x004A Latin Capital Letter J
{ 0x7F,0x08,0x14,0x22,0x41}, // ( 43) K - 0x004B Latin Capital Letter K
{ 0x7F,0x40,0x40,0x40,0x40}, // ( 44) L - 0x004C Latin Capital Letter L
{ 0x7F,0x02,0x0C,0x02,0x7F}, // ( 45) M - 0x004D Latin Capital Letter M
{ 0x7F,0x04,0x08,0x10,0x7F}, // ( 46) N - 0x004E Latin Capital Letter N
{ 0x3E,0x41,0x41,0x41,0x3E}, // ( 47) O - 0x004F Latin Capital Letter O
{ 0x7F,0x09,0x09,0x09,0x06}, // ( 48) P - 0x0050 Latin Capital Letter P
{ 0x3E,0x41,0x51,0x21,0x5E}, // ( 49) Q - 0x0051 Latin Capital Letter Q
{ 0x7F,0x09,0x19,0x29,0x46}, // ( 50) R - 0x0052 Latin Capital Letter R
{ 0x46,0x49,0x49,0x49,0x31}, // ( 51) S - 0x0053 Latin Capital Letter S
{ 0x01,0x01,0x7F,0x01,0x01}, // ( 52) T - 0x0054 Latin Capital Letter T
{ 0x3F,0x40,0x40,0x40,0x3F}, // ( 53) U - 0x0055 Latin Capital Letter U
{ 0x1F,0x20,0x40,0x20,0x1F}, // ( 54) V - 0x0056 Latin Capital Letter V
{ 0x3F,0x40,0x38,0x40,0x3F}, // ( 55) W - 0x0057 Latin Capital Letter W
{ 0x63,0x14,0x08,0x14,0x63}, // ( 56) X - 0x0058 Latin Capital Letter X
{ 0x07,0x08,0x70,0x08,0x07}, // ( 57) Y - 0x0059 Latin Capital Letter Y
{ 0x61,0x51,0x49,0x45,0x43}, // ( 58) Z - 0x005A Latin Capital Letter Z
{ 0x00,0x7F,0x41,0x41,0x00}, // ( 59) [ - 0x005B Left Square Bracket
{ 0x02,0x04,0x08,0x10,0x20}, // ( 60) \ - 0x005C Reverse Solidus
{ 0x00,0x41,0x41,0x7F,0x00}, // ( 61) ] - 0x005D Right Square Bracket
{ 0x04,0x02,0x01,0x02,0x04}, // ( 62) ^ - 0x005E Circumflex Accent
{ 0x40,0x40,0x40,0x40,0x40}, // ( 63) _ - 0x005F Low Line
{ 0x01,0x02,0x04,0x00,0x00}, // ( 64) ` - 0x0060 Grave Accent
{ 0x20,0x54,0x54,0x54,0x78}, // ( 65) a - 0x0061 Latin Small Letter A
{ 0x7F,0x48,0x44,0x44,0x38}, // ( 66) b - 0x0062 Latin Small Letter B
{ 0x38,0x44,0x44,0x44,0x20}, // ( 67) c - 0x0063 Latin Small Letter C
{ 0x38,0x44,0x44,0x48,0x7F}, // ( 68) d - 0x0064 Latin Small Letter D
{ 0x38,0x54,0x54,0x54,0x18}, // ( 69) e - 0x0065 Latin Small Letter E
{ 0x08,0x7E,0x09,0x01,0x02}, // ( 70) f - 0x0066 Latin Small Letter F
{ 0x06,0x49,0x49,0x49,0x3F}, // ( 71) g - 0x0067 Latin Small Letter G
{ 0x7F,0x08,0x04,0x04,0x78}, // ( 72) h - 0x0068 Latin Small Letter H
{ 0x00,0x44,0x7D,0x40,0x00}, // ( 73) i - 0x0069 Latin Small Letter I
{ 0x20,0x40,0x44,0x3D,0x00}, // ( 74) j - 0x006A Latin Small Letter J
{ 0x7F,0x10,0x28,0x44,0x00}, // ( 75) k - 0x006B Latin Small Letter K
{ 0x00,0x41,0x7F,0x40,0x00}, // ( 76) l - 0x006C Latin Small Letter L
{ 0x7C,0x04,0x18,0x04,0x7C}, // ( 77) m - 0x006D Latin Small Letter M
{ 0x7C,0x08,0x04,0x04,0x78}, // ( 78) n - 0x006E Latin Small Letter N
{ 0x38,0x44,0x44,0x44,0x38}, // ( 79) o - 0x006F Latin Small Letter O
{ 0x7C,0x14,0x14,0x14,0x08}, // ( 80) p - 0x0070 Latin Small Letter P
{ 0x08,0x14,0x14,0x18,0x7C}, // ( 81) q - 0x0071 Latin Small Letter Q
{ 0x7C,0x08,0x04,0x04,0x08}, // ( 82) r - 0x0072 Latin Small Letter R
{ 0x48,0x54,0x54,0x54,0x20}, // ( 83) s - 0x0073 Latin Small Letter S
{ 0x04,0x3F,0x44,0x40,0x20}, // ( 84) t - 0x0074 Latin Small Letter T
{ 0x3C,0x40,0x40,0x20,0x7C}, // ( 85) u - 0x0075 Latin Small Letter U
{ 0x1C,0x20,0x40,0x20,0x1C}, // ( 86) v - 0x0076 Latin Small Letter V
{ 0x3C,0x40,0x30,0x40,0x3C}, // ( 87) w - 0x0077 Latin Small Letter W
{ 0x44,0x28,0x10,0x28,0x44}, // ( 88) x - 0x0078 Latin Small Letter X
{ 0x0C,0x50,0x50,0x50,0x3C}, // ( 89) y - 0x0079 Latin Small Letter Y
{ 0x44,0x64,0x54,0x4C,0x44}, // ( 90) z - 0x007A Latin Small Letter Z
{ 0x00,0x08,0x36,0x41,0x00}, // ( 91) { - 0x007B Left Curly Bracket
{ 0x00,0x00,0x7F,0x00,0x00}, // ( 92) | - 0x007C Vertical Line
{ 0x00,0x41,0x36,0x08,0x00}, // ( 93) } - 0x007D Right Curly Bracket
{ 0x02,0x01,0x02,0x04,0x02}, // ( 94) ~ - 0x007E Tilde
{ 0x3E,0x55,0x55,0x41,0x22}, // ( 95) C - 0x0080 <Control>
{ 0x00,0x00,0x00,0x00,0x00}, // ( 96) - 0x00A0 No-Break Space
{ 0x00,0x00,0x79,0x00,0x00}, // ( 97) ! - 0x00A1 Inverted Exclamation Mark
{ 0x18,0x24,0x74,0x2E,0x24}, // ( 98) c - 0x00A2 Cent Sign
{ 0x48,0x7E,0x49,0x42,0x40}, // ( 99) L - 0x00A3 Pound Sign
{ 0x5D,0x22,0x22,0x22,0x5D}, // (100) o - 0x00A4 Currency Sign
{ 0x15,0x16,0x7C,0x16,0x15}, // (101) Y - 0x00A5 Yen Sign
{ 0x00,0x00,0x77,0x00,0x00}, // (102) | - 0x00A6 Broken Bar
{ 0x0A,0x55,0x55,0x55,0x28}, // (103) - 0x00A7 Section Sign
{ 0x00,0x01,0x00,0x01,0x00}, // (104) " - 0x00A8 Diaeresis
{ 0x00,0x0A,0x0D,0x0A,0x04}, // (105) - 0x00AA Feminine Ordinal Indicator
{ 0x08,0x14,0x2A,0x14,0x22}, // (106) << - 0x00AB Left-Pointing Double Angle Quotation Mark
{ 0x04,0x04,0x04,0x04,0x1C}, // (107) - 0x00AC Not Sign
{ 0x00,0x08,0x08,0x08,0x00}, // (108) - - 0x00AD Soft Hyphen
{ 0x01,0x01,0x01,0x01,0x01}, // (109) - 0x00AF Macron
{ 0x00,0x02,0x05,0x02,0x00}, // (110) - 0x00B0 Degree Sign
{ 0x44,0x44,0x5F,0x44,0x44}, // (111) +- - 0x00B1 Plus-Minus Sign
{ 0x00,0x00,0x04,0x02,0x01}, // (112) ` - 0x00B4 Acute Accent
{ 0x7E,0x20,0x20,0x10,0x3E}, // (113) u - 0x00B5 Micro Sign
{ 0x06,0x0F,0x7F,0x00,0x7F}, // (114) - 0x00B6 Pilcrow Sign
{ 0x00,0x18,0x18,0x00,0x00}, // (115) . - 0x00B7 Middle Dot
{ 0x00,0x40,0x50,0x20,0x00}, // (116) - 0x00B8 Cedilla
{ 0x00,0x0A,0x0D,0x0A,0x00}, // (117) - 0x00BA Masculine Ordinal Indicator
{ 0x22,0x14,0x2A,0x14,0x08}, // (118) >> - 0x00BB Right-Pointing Double Angle Quotation Mark
{ 0x17,0x08,0x34,0x2A,0x7D}, // (119) /4 - 0x00BC Vulgar Fraction One Quarter
{ 0x17,0x08,0x04,0x6A,0x59}, // (120) /2 - 0x00BD Vulgar Fraction One Half
{ 0x30,0x48,0x45,0x40,0x20}, // (121) ? - 0x00BE Inverted Question Mark
{ 0x42,0x00,0x42,0x00,0x42}, // (122) - 0x00BF Bargraph - 0
{ 0x7E,0x42,0x00,0x42,0x00}, // (123) - 0x00BF Bargraph - 1
{ 0x7E,0x7E,0x00,0x42,0x00}, // (124) - 0x00BF Bargraph - 2
{ 0x7E,0x7E,0x7E,0x42,0x00}, // (125) - 0x00BF Bargraph - 3
{ 0x7E,0x7E,0x7E,0x7E,0x00}, // (126) - 0x00BF Bargraph - 4
{ 0x7E,0x7E,0x7E,0x7E,0x7E}, // (127) - 0x00BF Bargraph - 5
};
void i2c_OLED_send_cmd(uint8_t command) {
TWBR = ((F_CPU / 400000L) - 16) / 2; // change the I2C clock rate
i2c_writeReg(OLED_address, 0x80, (uint8_t)command);
}
void i2c_OLED_send_byte(uint8_t val) {
TWBR = ((F_CPU / 400000L) - 16) / 2; // change the I2C clock rate
i2c_writeReg(OLED_address, 0x40, (uint8_t)val);
}
void i2c_OLED_init(void){
i2c_OLED_send_cmd(0xae); //display off
i2c_OLED_send_cmd(0xa4); //SET All pixels OFF
// i2c_OLED_send_cmd(0xa5); //SET ALL pixels ON
delay(50);
i2c_OLED_send_cmd(0x20); //Set Memory Addressing Mode
i2c_OLED_send_cmd(0x02); //Set Memory Addressing Mode to Page addressing mode(RESET)
// i2c_OLED_send_cmd(0xa0); //colum address 0 mapped to SEG0 (POR)*** wires at bottom
i2c_OLED_send_cmd(0xa1); //colum address 127 mapped to SEG0 (POR) ** wires at top of board
// i2c_OLED_send_cmd(0xC0); // Scan from Right to Left (POR) *** wires at bottom
i2c_OLED_send_cmd(0xC8); // Scan from Left to Right ** wires at top
i2c_OLED_send_cmd(0xa6); // Set WHITE chars on BLACK backround
// i2c_OLED_send_cmd(0xa7); // Set BLACK chars on WHITE backround
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value
i2c_OLED_send_cmd(0xaf); // contrast value between 1 ( == dull) to 256 ( == bright)
// i2c_OLED_send_cmd(0xd3); // Display Offset :
// i2c_OLED_send_cmd(0x0); // 0
// delay(20);
// i2c_OLED_send_cmd(0x40); // Display start line [0;63] -> [0x40;0x7f]
// delay(20);
#ifdef DISPLAY_FONT_DSIZE
i2c_OLED_send_cmd(0xd6); // zoom
i2c_OLED_send_cmd(0x01); // on
#else
// i2c_OLED_send_cmd(0xd6); // zoom
// i2c_OLED_send_cmd(0x00); // off
#endif
delay(20);
i2c_OLED_send_cmd(0xaf); //display on
delay(20);
}
void i2c_OLED_send_char(unsigned char ascii){
unsigned char i;
for(i=0;i<5;i++){
buffer = pgm_read_byte(&(myFont[ascii - 32][i])); // call the macro to read ROM byte and put it in buffer
buffer ^= CHAR_FORMAT; // apply
i2c_OLED_send_byte(buffer);
}
i2c_OLED_send_byte(CHAR_FORMAT); // the gap
}
void i2c_OLED_send_string(const char *string){ // Sends a string of chars untill null terminator
unsigned char i=0;
while(*string){
for(i=0;i<5;i++){
buffer = pgm_read_byte(&(myFont[(*string)- 32][i])); // call the macro to read the ROM ASCII table
buffer ^= CHAR_FORMAT;
i2c_OLED_send_byte((unsigned char)buffer);
}
i2c_OLED_send_byte(CHAR_FORMAT); // the gap
*string++;
}
}
#ifndef SUPPRESS_OLED_I2C_128x64LOGO // Do we want the Logo displayed ?
void i2c_OLED_send_logo(void){
unsigned char i,j;
i2c_OLED_send_cmd(0xa6); //Set Normal Display
i2c_OLED_send_cmd(0xae); // Display OFF
i2c_OLED_send_cmd(0x20); // Set Memory Addressing Mode
i2c_OLED_send_cmd(0x00); // Set Memory Addressing Mode to Horizontal addressing mode
i2c_OLED_send_cmd(0xb0); // set page address to 0
i2c_OLED_send_cmd(0X40); // Display start line register to 0
i2c_OLED_send_cmd(0); // Set low col address to 0
i2c_OLED_send_cmd(0x10); // Set high col address to 0
for(uint16_t k=0; k<1024; k++) { // fill the display's RAM with graphic... 128*64 pixel picture
buffer = pgm_read_byte(&(LOGO[k]));
i2c_OLED_send_byte(buffer);
}
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction
i2c_OLED_send_cmd(0x0); // Set contrast value to 0
i2c_OLED_send_cmd(0xaf); // display on
for(j=0; j<2; j++){
for(i=0x01; i<0xff; i++){
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value
i2c_OLED_send_cmd(i); // Set contrast value
delay(1);
}
for(i=0xff; i>0x01; i--){
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value
i2c_OLED_send_cmd(i); // Set contrast value
delay(1);
}
}
i2c_OLED_init();
i2c_clear_OLED();
}
#if defined (OLED_I2C_128x64LOGO_PERMANENT)
void i2c_OLED_Put_Logo(void){
unsigned char i,j;
i2c_OLED_send_cmd(0xa6); //Set Normal Display
i2c_OLED_send_cmd(0xae); // Display OFF
i2c_OLED_send_cmd(0x20); // Set Memory Addressing Mode
i2c_OLED_send_cmd(0x00); // Set Memory Addressing Mode to Horizontal addressing mode
i2c_OLED_send_cmd(0xb0); // set page address to 0
i2c_OLED_send_cmd(0X40); // Display start line register to 0
i2c_OLED_send_cmd(0); // Set low col address to 0
i2c_OLED_send_cmd(0x10); // Set high col address to 0
for(int i=0; i<1024; i++) { // fill the display's RAM with graphic... 128*64 pixel picture
buffer = pgm_read_byte(&(LOGO[i]));
i2c_OLED_send_byte(buffer);
}
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction
i2c_OLED_send_cmd(250); // Here you can set the brightness 1 = dull, 255 is very bright
i2c_OLED_send_cmd(0xaf); // display on
}
#endif // OLED_I2C_128x64LOGO_PERMANENT
#endif // SUPPRESS_OLED_I2C_128x64LOGO
void i2c_OLED_set_XY(byte col, byte row) { // Not used in MW V2.0 but its here anyway!
i2c_OLED_send_cmd(0xb0+row); //set page address
i2c_OLED_send_cmd(0x00+(8*col&0x0f)); //set low col address
i2c_OLED_send_cmd(0x10+((8*col>>4)&0x0f)); //set high col address
}
void i2c_OLED_set_line(byte row) { // goto the beginning of a single row, compattible with LCD_CONFIG
i2c_OLED_send_cmd(0xb0+row); //set page address
i2c_OLED_send_cmd(0); //set low col address
i2c_OLED_send_cmd(0x10); //set high col address
}
void i2c_clear_OLED(void){
// unsigned char i;
// for(i=0;i<8;i++){
// i2c_OLED_set_XY(0,i);
// i2c_OLED_send_string(LINE_FILL_STRING);
// }
i2c_OLED_send_cmd(0xa6); //Set Normal Display
i2c_OLED_send_cmd(0xae); // Display OFF
i2c_OLED_send_cmd(0x20); // Set Memory Addressing Mode
i2c_OLED_send_cmd(0x00); // Set Memory Addressing Mode to Horizontal addressing mode
i2c_OLED_send_cmd(0xb0); // set page address to 0
i2c_OLED_send_cmd(0X40); // Display start line register to 0
i2c_OLED_send_cmd(0); // Set low col address to 0
i2c_OLED_send_cmd(0x10); // Set high col address to 0
for(uint16_t i=0; i<1024; i++) { // fill the display's RAM with graphic... 128*64 pixel picture
i2c_OLED_send_byte(0); // clear
}
i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction
i2c_OLED_send_cmd(200); // Here you can set the brightness 1 = dull, 255 is very bright
i2c_OLED_send_cmd(0xaf); // display on
}
#endif // OLED_I2C_128x64
#if defined(LCD_ETPP)
#define LCD_ETPP_ADDRESS 0x3B
// *********************
// i2c Eagle Tree Power Panel primitives
// *********************
void i2c_ETPP_init () {
i2c_rep_start(LCD_ETPP_ADDRESS<<1); // LCD_ETPP i2c address: 0x3B in 7 bit form. Shift left one bit and concatenate i2c write command bit of zero
i2c_write(0x00);// LCD_ETPP command register
i2c_write(0x24);// Function Set 001D0MSL D : data length for parallel interface only; M: 0 = 1x32 , 1 = 2x16; S: 0 = 1:18 multiplex drive mode, 1x32 or 2x16 character display, 1 = 1:9 multiplex drive mode, 1x16 character display; H: 0 = basic instruction set plus standard instruction set, 1 = basic instruction set plus extended instruction set
i2c_write(0x0C);// Display on 00001DCB D : 0 = Display Off, 1 = Display On; C : 0 = Underline Cursor Off, 1 = Underline Cursor On; B : 0 = Blinking Cursor Off, 1 = Blinking Cursor On
i2c_write(0x06);// Cursor Move 000001IS I : 0 = DDRAM or CGRAM address decrements by 1, cursor moves to the left, 1 = DDRAM or CGRAM address increments by 1, cursor moves to the right; S : 0 = display does not shift, 1 = display does shifts
LCDclear();
}
void i2c_ETPP_send_cmd (byte c) {
i2c_rep_start(LCD_ETPP_ADDRESS<<1); // I2C write direction
i2c_write(0x00);// LCD_ETPP command register
i2c_write(c);
}
void i2c_ETPP_send_char (char c) {
if (c > 0x0f) c |= 0x80; // LCD_ETPP uses character set "R", which has A->z mapped same as ascii + high bit; don't mess with custom chars.
i2c_rep_start(LCD_ETPP_ADDRESS<<1);// I2C write direction
i2c_write(0x40);// LCD_ETPP data register
i2c_write(c);
}
void i2c_ETPP_set_cursor (byte addr) {
i2c_ETPP_send_cmd(0x80 | addr); // High bit is "Set DDRAM" command, remaing bits are addr.
}
void i2c_ETPP_set_cursor (byte col, byte row) {
row = min(row,1);
col = min(col,15);
byte addr = col + row * 0x40; // Why 0x40? RAM in this controller has many more bytes than are displayed. In particular, the start of the second line (line 1 char 0) is 0x40 in DDRAM. The bytes between 0x0F (last char of line 1) and 0x40 are not displayable (unless the display is placed in marquee scroll mode)
i2c_ETPP_set_cursor(addr);
}
void i2c_ETPP_create_char (byte idx, uint8_t* array) {
i2c_ETPP_send_cmd(0x80); // CGRAM and DDRAM share an address register, but you can't set certain bits with the CGRAM address command. Use DDRAM address command to be sure high order address bits are zero.
i2c_ETPP_send_cmd(0x40 | byte(idx * 8));// Set CGRAM address
i2c_rep_start(LCD_ETPP_ADDRESS<<1);// I2C write direction
i2c_write(0x40);// LCD_ETPP data register
for (byte i = 0; i<8; i++) {i2c_write(*array); array++;}
}
static boolean charsInitialized; // chars for servo signals are initialized
void ETPP_barGraph(byte num, int val) { // num chars in graph; percent as 1 to 100
if (!charsInitialized) {
charsInitialized = true;
static byte bars[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15,};
static byte less[8] = {0x00, 0x04, 0x0C, 0x1C, 0x0C, 0x04, 0x00, 0x15,};
static byte grt [8] = {0x00, 0x04, 0x06, 0x07, 0x06, 0x04, 0x00, 0x15,};
byte pattern = 0x10;
for (int8_t i = 0; i <= 5; i++) {
for (int8_t j = 0; j < 7; j++) {
bars[j] = pattern;
}
i2c_ETPP_create_char(i, bars);
pattern >>= 1;
}
i2c_ETPP_create_char(6, less);
i2c_ETPP_create_char(7, grt);
}
static char bar[16];
for (int8_t i = 0; i < num; i++) {bar[i] = 5;}
if (val < -100 || val > 100) {bar[0] = 6; bar[num] = 7;} // invalid
else if (val < 0) {bar[0] = 6;} // <...
else if (val >= 100) {bar[3] = 7;} // ...>
else {bar[val/(100/num)] = (val%(100/num))/5;} // ..|.
for (int8_t i = 0; i < num; i++) {
i2c_ETPP_send_char(bar[i]);
}
}
#endif //LCD_ETPP
#if defined(LCD_LCD03) // LCD_LCD03
#define LCD_LCD03_ADDRESS 0x63
// *********************
// I2C LCD03 primitives
// *********************
void i2c_LCD03_init () {
i2c_rep_start(LCD_LCD03_ADDRESS<<1); // The LCD03 is located on the I2C bus at address 0xC6
i2c_write(0x00);// Command register
i2c_write(04);// Hide cursor
i2c_write(12);// Clear screen
i2c_write(19);// Backlight on
}
void i2c_LCD03_send_cmd (byte c) {
i2c_rep_start(LCD_LCD03_ADDRESS<<1);
i2c_write(0x00);
i2c_write(c);
}
void i2c_LCD03_send_char (char c) {
i2c_rep_start(LCD_LCD03_ADDRESS<<1);
i2c_write(0x00);
i2c_write(c);
}
void i2c_LCD03_set_cursor (byte col, byte row) {
row = min(row,1);
col = min(col,15);
i2c_LCD03_send_cmd(03); // set cursor (row, column)
i2c_LCD03_send_cmd(row+1);
i2c_LCD03_send_cmd(col+1);
}
#endif // LCD_LCD03
#if defined(LCD_LCD03S) // LCD_LCD03S
// *********************
// LCD03S serial primitives
// *********************
void serial_LCD03_init () {
SerialWrite(LCD_SERIAL_PORT, 0x00 );// Command register
SerialWrite(LCD_SERIAL_PORT, 04 );// Hide cursor
SerialWrite(LCD_SERIAL_PORT, 12 );// Clear screen
SerialWrite(LCD_SERIAL_PORT, 19 );// Backlight on
}
void serial_LCD03_send_cmd (byte c) {
SerialWrite(LCD_SERIAL_PORT, 0x00 );// Command register
SerialWrite(LCD_SERIAL_PORT, c );
}
void serial_LCD03_send_char (char c) {
//SerialWrite(LCD_SERIAL_PORT, 0x00 );// Command register
SerialWrite(LCD_SERIAL_PORT, c );
}
void serial_LCD03_set_cursor (byte col, byte row) {
row = min(row,1);
col = min(col,15);
serial_LCD03_send_cmd(03); // set cursor (row, column)
serial_LCD03_send_char(row+1);
serial_LCD03_send_char(col+1);
}
#endif // LCD_LCD03S
#if defined(OLED_DIGOLE) // OLED_DIGOLE
#define OLED_DIGOLE_ADDRESS 0x27 // 7bit address
// *********************
// I2C DIGOLE primitives
// *********************
void i2c_OLED_DIGOLE_init () {
i2c_OLED_DIGOLE_send_string("CL"); // clear screen
// delayMicroseconds(500);
// i2c_OLED_DIGOLE_send_string("BL"); // backlight _
// i2c_write(0x01); // _ on
i2c_OLED_DIGOLE_send_string("CT"); // contrast _
i2c_write(100); // contrast [0;100]
// i2c_write('C'); i2c_write('T'); i2c_write(100); // contrast [0;100]
//i2c_OLED_DIGOLE_send_string("DSS"); // display start screen _
//i2c_write(0); // _ off
//i2c_OLED_DIGOLE_send_string("CS"); // show cursor _
//i2c_write(0); // _ off
//i2c_OLED_DIGOLE_printString("123456789.123456789.");
// delayMicroseconds(500);
// i2c_OLED_DIGOLE_send_string("MCD"); // manual command
// i2c_write(0x81); //ssd1306: set contrast to _
// i2c_OLED_DIGOLE_send_string("MCD"); // manual data
// i2c_write(0xFF); // _ value [0;255]
// delayMicroseconds(500);
}
void i2c_OLED_DIGOLE_send_byte (byte c) {
i2c_rep_start(OLED_DIGOLE_ADDRESS<<1);
i2c_write(0x00);
i2c_write(c);
}
void i2c_OLED_DIGOLE_send_string(const char *string){ // Sends a string of chars but not the null terminator
i2c_rep_start(OLED_DIGOLE_ADDRESS<<1);
i2c_write(0x00);
while(*string){
i2c_write(*string);
*string++;
}
//delayMicroseconds(10);
}
void i2c_OLED_DIGOLE_printString(const char *string){ // prints a string of chars
// i2c_rep_start(OLED_DIGOLE_ADDRESS<<1);
// i2c_write(0x00);
// i2c_write('T');
// i2c_write('T');
i2c_OLED_DIGOLE_send_string("TT"); // type text _
while(*string){
i2c_write(*string);
*string++;
}
i2c_write(0x00);
//delayMicroseconds(10);
}
void i2c_OLED_DIGOLE_printChar(char c){ // prints a single char - should be printable
i2c_rep_start(OLED_DIGOLE_ADDRESS<<1);
i2c_write(0x00);
i2c_write('T');
i2c_write('T');
i2c_write(c);
i2c_write(0x00);
//delayMicroseconds(10);
}
void i2c_OLED_DIGOLE_clear(void) {
i2c_OLED_DIGOLE_send_string("CLSF"); // set font _
#ifdef DISPLAY_FONT_DSIZE
i2c_write(0); // _ one of 6,10,18,51,120,123,0 - font 0 is 5x16 linesxrows; font 10 is 7x21
#else
i2c_write(10);
#endif
}
#endif // OLED_DIGOLE
/* ------------------------------------------------------------------ */
void LCDprint(uint8_t i) {
#ifdef DISPLAY_FONT_DSIZE
if (! line_is_valid) return;
#endif
#if defined(LCD_SERIAL3W)
// 1000000 / 9600 = 104 microseconds at 9600 baud.
// we set it below to take some margin with the running interrupts
#define BITDELAY 102
LCDPIN_OFF;
delayMicroseconds(BITDELAY);
for (uint8_t mask = 0x01; mask; mask <<= 1) {
if (i & mask) {LCDPIN_ON;} else {LCDPIN_OFF;} // choose bit
delayMicroseconds(BITDELAY);
}
LCDPIN_ON //switch ON digital PIN 0
delayMicroseconds(BITDELAY);
#elif defined(LCD_TEXTSTAR) || defined(LCD_VT100) || defined(LCD_TTY)
SerialWrite(LCD_SERIAL_PORT, i );
#elif defined(LCD_ETPP)
i2c_ETPP_send_char(i);
#elif defined(LCD_LCD03)
i2c_LCD03_send_char(i);
#elif defined(LCD_LCD03S)
serial_LCD03_send_char(i);
#elif defined(OLED_I2C_128x64)
i2c_OLED_send_char(i);
#elif defined(OLED_DIGOLE)
i2c_OLED_DIGOLE_printChar(i);
#endif
}
void LCDprintChar(const char *s) {
#ifdef OLED_DIGOLE
#ifdef DISPLAY_FONT_DSIZE
if (! line_is_valid) return;
#endif
i2c_OLED_DIGOLE_printString(s);
#else
while (*s) {LCDprint(*s++);}
#endif
}
void LCDcrlf() {
#if ( defined(OLED_I2C_128x64)|| defined(LCD_VT100) || defined(OLED_DIGOLE) )
// do nothing - these displays use line positioning
#else
LCDprintChar("\r\n");
#endif
}
void LCDclear() {
#if defined(LCD_SERIAL3W)
LCDprint(0xFE);LCDprint(0x01);delay(10);LCDprint(0xFE);LCDprint(0x02);delay(10); // clear screen, cursor line 1, pos 0 for serial LCD Sparkfun - contrib by flyman777
#elif defined(LCD_TEXTSTAR)
LCDprint(0x0c);
#elif defined(LCD_VT100)
LCDcrlf();
LCDprint(0x1B); LCDprint(0x5B); LCDprintChar("2J"); //ED2
LCDcrlf();
LCDprint(0x1B); LCDprint(0x5B); LCDprintChar("1;1H");//cursor top left
#elif defined(LCD_TTY)
LCDcrlf();
#elif defined(LCD_ETPP)
i2c_ETPP_send_cmd(0x01); // Clear display command, which does NOT clear an Eagle Tree because character set "R" has a '>' at 0x20
for (byte i = 0; i<80; i++) i2c_ETPP_send_char(' ');// Blanks for all 80 bytes of RAM in the controller, not just the 2x16 display
#elif defined(LCD_LCD03)
i2c_LCD03_send_cmd(12); // clear screen
#elif defined(LCD_LCD03S)
serial_LCD03_send_cmd(12); // clear screen
#elif defined(OLED_I2C_128x64)
i2c_clear_OLED();
#elif defined(OLED_DIGOLE)
i2c_OLED_DIGOLE_clear();
#endif
#if ( defined(LOG_PERMANENT) && defined(DISPLAY_MULTILINE) )
lnr = 0;
#endif
}
void LCDsetLine(byte line) { // Line = 1 or 2 - vt100 has lines 1-99
#ifdef DISPLAY_FONT_DSIZE
if (line >=1 && line <= (MULTILINE_PRE+MULTILINE_POST)) {
line_is_valid = 1;
} else {
line_is_valid = 0;
return;
}
#endif
#if defined(LCD_SERIAL3W)
if (line==1) {LCDprint(0xFE);LCDprint(128);} else {LCDprint(0xFE);LCDprint(192);}
#elif defined(LCD_TEXTSTAR)
LCDcrlf(); LCDprint(0xfe);LCDprint('L');LCDprint(line);
#elif defined(LCD_VT100)
#ifndef DEBUG // sanity check for production only. Debug runs with all possible side effects
if (line<1 || line>(MULTILINE_PRE+MULTILINE_POST)) line = 1;
#endif
LCDcrlf();
LCDprint(0x1b); LCDprint(0x5b);
LCDprint( digit10(line) );
LCDprint( digit1(line) );
LCDprintChar(";1H"); //pos line 1
LCDprint(0x1b); LCDprint(0x5b); LCDprintChar("2K");//EL2
#elif defined(LCD_TTY)
LCDcrlf();
#elif defined(LCD_ETPP)
i2c_ETPP_set_cursor(0,line-1);
#elif defined(LCD_LCD03)
i2c_LCD03_set_cursor(0,line-1);
#elif defined(LCD_LCD03S)
serial_LCD03_set_cursor(0,line-1);
#elif defined(OLED_I2C_128x64)
// #ifndef DEBUG // sanity check for production only. Debug runs with all possible side effects
// if (line<1 || line>(MULTILINE_PRE+MULTILINE_POST)) line = 1;
// #endif
i2c_OLED_set_line(line-1);
#elif defined(OLED_DIGOLE)
i2c_OLED_DIGOLE_send_string("TP"); i2c_write(0);i2c_write(line-1); // first column is 0, line numbers start with 0
#endif
}
#if defined(LCD_VT100)
void LCDattributesBold() {LCDprint(0x1b); LCDprint(0x5b); LCDprintChar("1m");}
void LCDattributesReverse() {LCDprint(0x1b); LCDprint(0x5b); LCDprintChar("7m");}
void LCDattributesOff() {LCDprint(0x1b); LCDprint(0x5b); LCDprintChar("0m");}
void LCDalarmAndReverse() {LCDattributesReverse(); if (f.ARMED) { LCDprint(0x07); }; } // audio for errors only while armed
#elif defined(OLED_I2C_128x64)
void LCDattributesBold() {/*CHAR_FORMAT = 0b01111111; */}
void LCDattributesReverse() {CHAR_FORMAT = 0b01111111; }
void LCDattributesOff() {CHAR_FORMAT = 0; }
void LCDalarmAndReverse() {LCDattributesReverse(); }
#else
void LCDattributesBold() {}
void LCDattributesReverse() {}
void LCDattributesOff() {}
void LCDalarmAndReverse() {}
#endif
void LCDprintInt16(int16_t v) {
uint16_t unit;
char line[7]; // = " ";
if (v < 0 ) {
unit = -v;
line[0] = '-';
} else {
unit = v;
line[0] = ' ';
}
line[1] = digit10000(unit);
line[2] = digit1000(unit);
line[3] = digit100(unit);
line[4] = digit10(unit);
line[5] = digit1(unit);
line[6] = 0;
LCDprintChar(line);
}
void lcdprint_uint32(uint32_t v) {
static char line[14] = "-.---.---.---";
// 0 2 4 6 8 12
line[0] = '0' + v / 1000000000;
line[2] = '0' + v / 100000000 - (v/1000000000) * 10;
line[3] = '0' + v / 10000000 - (v/100000000) * 10;
line[4] = '0' + v / 1000000 - (v/10000000) * 10;
line[6] = '0' + v / 100000 - (v/1000000) * 10;
line[7] = '0' + v / 10000 - (v/100000) * 10;
line[8] = '0' + v / 1000 - (v/10000) * 10;
line[10] = '0' + v / 100 - (v/1000) * 10;
line[11] = '0' + v / 10 - (v/100) * 10;
line[12] = '0' + v - (v/10) * 10;
LCDprintChar(line);
}
void initLCD() {
blinkLED(20,30,1);
SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);
#if defined(LCD_SERIAL3W)
SerialEnd(0);
//init LCD
PINMODE_LCD;//TX PIN for LCD = Arduino RX PIN (more convenient to connect a servo plug on arduino pro mini)
#elif defined(LCD_TEXTSTAR)
// Cat's Whisker Technologies 'TextStar' Module CW-LCD-02
// http://cats-whisker.com/resources/documents/cw-lcd-02_datasheet.pdf
//LCDprint(0xFE);LCDprint(0x43);LCDprint(0x02); //cursor blink mode
LCDprint(0xFE);LCDprint('R');//reset
#elif defined(LCD_VT100)
//LCDprint(0x1b); LCDprint('c'); //RIS
#elif defined(LCD_TTY)
; // do nothing special to init the serial tty device
#elif defined(LCD_ETPP)
// Eagle Tree Power Panel - I2C & Daylight Readable LCD
i2c_ETPP_init();
#elif defined(LCD_LCD03)
// LCD03 - I2C LCD
// http://www.robot-electronics.co.uk/htm/Lcd03tech.htm
i2c_LCD03_init();
#elif defined(LCD_LCD03S)
// LCD03 - SERIAL LCD
// http://www.robot-electronics.co.uk/htm/Lcd03tech.htm
serial_LCD03_init();
#elif defined(OLED_I2C_128x64)
i2c_OLED_init();
#ifndef SUPPRESS_OLED_I2C_128x64LOGO
i2c_OLED_send_logo();
#if defined (OLED_I2C_128x64LOGO_PERMANENT)
i2c_OLED_Put_Logo();
#endif
#endif
#elif defined(OLED_DIGOLE)
i2c_OLED_DIGOLE_init();
#endif
#ifndef OLED_I2C_128x64LOGO_PERMANENT
LCDclear();
strcpy_P(line1,PSTR( BOARD_NAME )); // user defined macro
// 0123456789.123456
line1[12] = digit100(VERSION);
line1[14] = digit10(VERSION);
line1[15] = digit1(VERSION);
LCDattributesBold();
LCDsetLine(1); LCDprintChar(line1);
strcpy_P(line2,PSTR(" Unknown Modell"));
#if defined(TRI)
strcpy_P(line2,PSTR(" TRICopter"));
#elif defined(QUADP)
strcpy_P(line2,PSTR(" QUAD-P"));
#elif defined(QUADX)
strcpy_P(line2,PSTR(" QUAD-X"));
#elif defined(BI)
strcpy_P(line2,PSTR(" BICopter"));
#elif defined(Y6)
strcpy_P(line2,PSTR(" Y6"));
#elif defined(HEX6)
strcpy_P(line2,PSTR(" HEX6"));
#elif defined(FLYING_WING)
strcpy_P(line2,PSTR(" FLYING_WING"));
#elif defined(Y4)
strcpy_P(line2,PSTR(" Y4"));
#elif defined(HEX6X)
strcpy_P(line2,PSTR(" HEX6-X"));
#elif defined(HEX6H)
strcpy_P(line2,PSTR(" HEX6-H"));
#elif defined(OCTOX8)
strcpy_P(line2,PSTR(" OCTOX8"));
#elif defined(OCTOFLATP)
strcpy_P(line2,PSTR(" OCTOFLAT-P"));
#elif defined(OCTOFLATX)
strcpy_P(line2,PSTR(" OCTOFLAT-X"));
#elif defined (AIRPLANE)
strcpy_P(line2,PSTR(" AIRPLANE"));
#elif defined (HELI_120_CCPM)
strcpy_P(line2,PSTR(" HELI_120_CCPM"));
#elif defined (HELI_90_DEG)
strcpy_P(line2,PSTR(" HELI_90_DEG"));
#elif defined(VTAIL4)
strcpy_P(line2,PSTR(" VTAIL Quad"));
#endif
//LCDattributesBold();
LCDsetLine(2); LCDprintChar(line2);
LCDattributesOff();
delay(2500);
#endif // OLED_I2C_128x64LOGO_PERMANENT
#if defined(LCD_TEXTSTAR) || defined(LCD_VT100)
//delay(2500);
LCDclear();
#endif
#if defined(OLED_I2C_128x64) && !(defined(OLED_I2C_128x64LOGO_PERMANENT)) && defined(NEW_OLED_FONT) && !(defined(LCD_TELEMETRY))
// no need to diplay this, if LCD telemetry is enabled
// optional instruction on the display......
LCDsetLine(4); LCDprintChar("To ENTER CONFIG ");// 21 characters on each line
LCDsetLine(5); LCDprintChar("YAW RIGHT & PITCH FWD");
LCDsetLine(7); LCDprintChar("To SAVE CONFIG ");
LCDsetLine(8); LCDprintChar("YAW LEFT & PITCH FWD ");
#endif
// if (cycleTime == 0) { //Called from Setup()
// strcpy_P(line1,PSTR("Ready to Fly")); LCDsetLine(2); LCDprintChar(line1);
// } else {
// strcpy_P(line1,PSTR("Config All Parms")); LCDsetLine(2); LCDprintChar(line1);
// }
#ifdef LCD_TELEMETRY_STEP
// load the first page of the step sequence
LCDclear();
telemetry = telemetryStepSequence[telemetryStepIndex]; //[++telemetryStepIndex % strlen(telemetryStepSequence)];
#endif
}
#endif //Support functions for LCD_CONF and LCD_TELEMETRY
// -------------------- configuration menu to LCD over serial/i2c ----------------------------------
#ifdef LCD_CONF
static uint8_t reset_to_defaults;
typedef void (*formatter_func_ptr)(void *, uint8_t, uint8_t);
typedef void (*inc_func_ptr)(void *, int16_t);
/*typedef*/struct lcd_type_desc_t {
formatter_func_ptr fmt;
inc_func_ptr inc;
};
static lcd_type_desc_t LTU8 = {&__u8Fmt, &__u8Inc};
static lcd_type_desc_t LTS8 = {&__s8BitsFmt, &__s8Inc};
static lcd_type_desc_t LTU16 = {&__u16Fmt, &__u16Inc};
static lcd_type_desc_t LTS16 = {&__s16Fmt, &__s16Inc};
static lcd_type_desc_t LPMM = {&__upMFmt, &__nullInc};
//static lcd_type_desc_t LPMS = {&__upSFmt, &__nullInc};
static lcd_type_desc_t LAUX1 = {&__uAuxFmt1, &__u16Inc};
static lcd_type_desc_t LAUX2 = {&__uAuxFmt2, &__u16Inc};
static lcd_type_desc_t LAUX3 = {&__uAuxFmt3, &__u16Inc};
static lcd_type_desc_t LAUX4 = {&__uAuxFmt4, &__u16Inc};
/*typedef*/struct lcd_param_def_t {
lcd_type_desc_t * type;
uint8_t decimal;
uint8_t multiplier;
uint16_t increment;
};
//typedef struct lcd_param_t{
// char* paramText;
// void * var;
// lcd_param_def_t * def;
//};
// ************************************************************************************************************
// LCD Layout definition
// ************************************************************************************************************
// Descriptors
static lcd_param_def_t __P = {<U8, 1, 1, 1};
static lcd_param_def_t __I = {<U8, 3, 1, 1};
static lcd_param_def_t __D = {<U8, 0, 1, 1};
static lcd_param_def_t __RC = {<U8, 2, 1, 1};
static lcd_param_def_t __PM = {&LPMM, 1, 1, 0};
//static lcd_param_def_t __PS = {&LPMS, 1, 1, 0};
static lcd_param_def_t __PT = {<U8, 0, 1, 1};
static lcd_param_def_t __VB = {<U8, 1, 1, 0};
static lcd_param_def_t __L = {<U8, 0, 1, 0};
static lcd_param_def_t __FS = {<U8, 1, 1, 0};
static lcd_param_def_t __SE = {<U16, 0, 1, 10};
static lcd_param_def_t __SE1 = {<U16, 0, 1, 1};
static lcd_param_def_t __ST = {<S16, 0, 1, 10};
static lcd_param_def_t __AUX1 = {&LAUX1, 0, 1, 1};
static lcd_param_def_t __AUX2 = {&LAUX2, 0, 1, 8};
static lcd_param_def_t __AUX3 = {&LAUX3, 0, 1, 64};
static lcd_param_def_t __AUX4 = {&LAUX4, 0, 1, 512};
static lcd_param_def_t __BITS = {<S8, 0, 1, 1};
// Program Space Strings - These sit in program flash, not SRAM.
// 0123456789
const char PROGMEM lcd_param_text01 [] = "Pit&Roll P";
const char PROGMEM lcd_param_text02 [] = "Roll P";
const char PROGMEM lcd_param_text03 [] = "Roll I";
const char PROGMEM lcd_param_text04 [] = "Roll D";
const char PROGMEM lcd_param_text05 [] = "Pitch P";
const char PROGMEM lcd_param_text06 [] = "Pitch I";
const char PROGMEM lcd_param_text07 [] = "Pitch D";
const char PROGMEM lcd_param_text08 [] = "Yaw P";
const char PROGMEM lcd_param_text09 [] = "Yaw I";
const char PROGMEM lcd_param_text10 [] = "Yaw D";
#if BARO && (!defined(SUPPRESS_BARO_ALTHOLD))
const char PROGMEM lcd_param_text11 [] = "Alt P";
const char PROGMEM lcd_param_text12 [] = "Alt I";
const char PROGMEM lcd_param_text13 [] = "Alt D";
const char PROGMEM lcd_param_text14 [] = "Vel P";
const char PROGMEM lcd_param_text15 [] = "Vel I";
const char PROGMEM lcd_param_text16 [] = "Vel D";
#endif
const char PROGMEM lcd_param_text17 [] = "Ang/Hor P";
const char PROGMEM lcd_param_text18 [] = "Ang/Hor I";
const char PROGMEM lcd_param_text188[] = "Ang/Hor D";
const char PROGMEM lcd_param_text19 [] = "Mag P";