-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdisplay.cpp
More file actions
1309 lines (1145 loc) · 32.6 KB
/
Copy pathdisplay.cpp
File metadata and controls
1309 lines (1145 loc) · 32.6 KB
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
/*
* VFD Deluxe
* (C) 2011-12 Akafugu Corporation
*
* This program 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 2 of the License, or (at your option) any later
* version.
*
* This program 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.
*
*/
#include "global.h"
#include "settings.h"
#include "display.h"
//#include "display_nixie.h"
#include "gps.h"
#include <Wire.h>
#include <WireRtcLib.h>
//void write_vfd_7seg(uint8_t digit, uint8_t segments);
//void write_vfd_standard(uint8_t digit, uint16_t segments);
//void write_vfd_16seg(uint8_t digit, uint16_t segments);
//void write_vfd_iv6(uint8_t digit, uint8_t segments);
//void write_vfd_iv17(uint8_t digit, uint16_t segments);
//void write_vfd_iv18(uint8_t digit, uint8_t segments);
//void write_vfd_iv22(uint8_t digit, uint8_t segments);
// nixie shields
//void write_nixie_6digit(uint8_t digit, uint8_t value);
//void write_vfd_8bit(uint8_t data);
//void clear_display(void);
//void clear_data();
//bool get_alarm_switch(void);
// see font-16seg.c
uint16_t calculate_segments_16(uint8_t character);
// see font-14seg.c
uint16_t calculate_segments_14(uint8_t character);
// see font-7seg.c
uint8_t calculate_segments_7(uint8_t character);
// HV5812 Data In (PF7 - A0)
#define DATA_HIGH DIRECT_PIN_HIGH(data_pin.reg, data_pin.bitmask)
#define DATA_LOW DIRECT_PIN_LOW(data_pin.reg, data_pin.bitmask)
// HV5812 Clock (PF5 - A2)
#define CLOCK_HIGH DIRECT_PIN_HIGH(clock_pin.reg, clock_pin.bitmask)
#define CLOCK_LOW DIRECT_PIN_LOW(clock_pin.reg, clock_pin.bitmask)
// HV5812 Latch / Strobe (PF6 - A1)
#define LATCH_ENABLE DIRECT_PIN_LOW(latch_pin.reg, latch_pin.bitmask)
#define LATCH_DISABLE DIRECT_PIN_HIGH(latch_pin.reg, latch_pin.bitmask)
pin_direct_t data_pin;
pin_direct_t clock_pin;
pin_direct_t latch_pin;
pin_direct_t blank_pin;
enum shield_t shield = SHIELD_NONE;
uint8_t digits = 6;
uint8_t segments = 7;
volatile char data[16]; // Digit data
//uint8_t us_counter = 0; // microsecond counter
uint8_t multiplex_counter = 0;
uint8_t multiplex_limit = 8;
uint8_t reverse_display = false;
#ifdef HAVE_GPS
uint8_t gps_counter = 0;
#endif
volatile uint8_t _scrolling = false;
static char sData[32]; // scroll message - 25 chars plus 8 spaces
const uint8_t scroll_len = 32;
volatile uint16_t scroll_counter = 0;
uint16_t scroll_time = 300; // a little over 3 chars/second
volatile uint8_t scroll_index = 0;
uint8_t scroll_limit = 0;
// globals from main.c
extern uint8_t g_alarm_switch;
// variables for controlling display blink
uint8_t blinking;
uint16_t blink_counter = 0;
volatile uint8_t display_on = 1;
uint8_t dimming;
uint16_t dimming_counter = 0;
volatile uint8_t dimming_on = 0;
extern uint8_t g_second_dots_on;
// dots [bit 0~5]
volatile uint8_t dots = 0;
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))
volatile uint16_t ms_counter = 0; // millisecond counter
volatile unsigned long _millis = 0;
unsigned long wMillis(void)
{
unsigned long m;
cli();
m = _millis;
sei();
return m;
}
void wDelay(unsigned long ms)
{
unsigned long t2 = wMillis() + ms;
while (t2 != wMillis()) ;
}
void clear_display(void);
void clear_data(void);
uint16_t _brightness = 511; // current brightness level 0-511
uint8_t brt_counter = 0;
void display_init(uint8_t data, uint8_t clock, uint8_t latch, uint8_t blank, uint8_t brightness)
{
// outputs
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(blank, OUTPUT);
data_pin.pin = data;
data_pin.reg = PIN_TO_OUTPUT_REG(data);
data_pin.bitmask = PIN_TO_BITMASK(data);
clock_pin.pin = data;
clock_pin.reg = PIN_TO_OUTPUT_REG(clock);
clock_pin.bitmask = PIN_TO_BITMASK(clock);
latch_pin.pin = latch;
latch_pin.reg = PIN_TO_OUTPUT_REG(latch);
latch_pin.bitmask = PIN_TO_BITMASK(latch);
blank_pin.pin = blank;
blank_pin.reg = PIN_TO_OUTPUT_REG(blank);
blank_pin.bitmask = PIN_TO_BITMASK(blank);
LATCH_ENABLE;
clear_display();
clear_data();
#ifdef HAVE_ATMEGA328
// TIMER 2 overflow interrupt
//cli();
TCCR2B = 0;
// enable Timer2 overflow interrupt:
TIMSK2 |= (1<<TOIE2);
// Set CS00 bit so timer runs at clock speed:
TCCR2B |= (1<<CS22)|(1<<CS21); // Set Prescaler to clk/8 : 1 click = 1us. CS21=1
#elif defined(HAVE_LEONARDO)
// we use 2 timers - one set for PWM for brightness control, the other set to
// do interrupts for timing: display multiplex and millis();
TCCR1B = (1<<WGM13) | (1<<WGM12); // fast PWM
TCCR1A = (1<<WGM11) | (1<<WGM10); // set for OCR1=TOP
OCR1A = 16000; // 16000000/16000 = 1,000 hz
TCNT1 = 0;
TCCR1B |= (1<<CS10); // connect at 1x to start counter
TIMSK1 |= (1<<OCIE1A); // enable Timer1 COMPA interrupt:
// TCCR3B = (1<<WGM32); // fast PWM for display brightness control
// TCCR3A = (1<<WGM30); // set for 8 bit
// TCNT3 = 0;
// TCCR3B |= (1<<CS30); // connect at 1x to start counter
// TIMSK3 |= (1<<TOIE3); // enable Timer1 overflow interrupt:
// Set up PWM on PD7/OC4D (digital 6)
// TCCR4A = 0;
// TCCR4B = 0;
TCCR4C = (1<<COM4D1) | (1<<COM4D0) | (1<<PWM4D);
// COM4D1 + COM4D0 = Set on Compare Match, Clear when TCNT4 = 0x000.
// PWM4D = Enable PWM mode
TCCR4D = 0; // (1<<WGM40); // fast pwm
// TCCR4D = (1<<WGM40); // Phase & frequency correct PWM
// TC4H = 1; // set OCR4C High byte for 9-bit TOP
TC4H = 3; // set OCR4C High byte for 10-bit TOP
OCR4C = 255; // clear on compare match value (1023)
OCR4D = 255; // set maximum brightness
TCNT4 = 0; // start count
TCCR4B = (1<<CS40); // Start Timer 4 at 1x
// TCCR4B = (1<<CS41); // Start Timer 4 at fcpu/2
// DT4 = 0XFF; // insert some dead time to see effect
// TIMSK4 |= (1<<OCIE4A); // no interrupt needed for Timer4
#endif
set_brightness(brightness);
}
// Brightness is set by setting the PWM duty cycle for the blank
// pin of the VFD driver.
// these are approximately logarithmic values for the pwm setting (wbp)
//uint16_t brt[] = {1, 3, 15, 27, 42, 59, 79, 103, 135, 179, 255}; // 11 values (0-10)
//uint16_t brt[] = {1, 3, 24, 50, 80, 114, 155, 204, 268, 357, 511}; // 11 values (0-10)
uint16_t brt[] = {1, 7, 22, 52, 100, 172, 270, 400, 567, 773, 1023}; // 11 values (0-10), 10 bit, gamma (2.8, -0.5)
// double each successive pwm value ?
//uint16_t brt[] = {1, 2, 3, 5, 7, 15, 31, 63, 127, 255, 511}; // 11 values (0-10)
// brightness value: 0 (low) - 10 (high)
// fixme: BLANK must always be set to GND when driving Nixies
void set_brightness(uint8_t brightness) {
if (brightness > 10) brightness = 10;
settings.brightness = brightness; // update global so it stays consistent 16nov12/wbp
// save_settings();
// _brightness = brt[brightness-1];
_brightness = brt[brightness];
TC4H = _brightness>>8; // set high order byte value for 10-bit comparand
OCR4D = _brightness; // set PWM comparand for given brightness
TCNT4 = 0; // restart timer counter
// digitalWrite(blank_pin.pin, LOW); // blanking off
PORTD &= B01111111; // set PD7 LOW
}
int get_digits(void)
{
return digits;
}
#ifdef HAVE_SHIELD_AUTODETECT
// detect which shield is connected
void detect_shield()
{
pinMode(PinMap::sig0, INPUT);
pinMode(PinMap::sig1, INPUT);
pinMode(PinMap::sig2, INPUT);
// Turn on pull-ups
digitalWrite(PinMap::sig0, HIGH);
digitalWrite(PinMap::sig1, HIGH);
digitalWrite(PinMap::sig2, HIGH);
// read shield bits
uint8_t sig =
((digitalRead(PinMap::sig0) ? 0b1 : 0) |
(digitalRead(PinMap::sig1) ? 0b10 : 0) |
(digitalRead(PinMap::sig2) ? 0b100 : 0 ));
// Serial.print("Signature = ");
// Serial.println(sig);
switch (sig) {
case(1): // IV-17 shield
shield = SHIELD_IV17;
digits = 4;
multiplex_limit = 4;
//mpx_count = 4;
g_has_dots = false;
reverse_display = false;
segments = 16;
break;
case(2): // IV-6 shield
shield = SHIELD_IV6;
digits = 6;
multiplex_limit = 6;
//mpx_count = 8;
g_has_dots = true;
reverse_display = false;
break;
case(5): // IV-17 6-digit shield
shield = SHIELD_IV17_6D;
digits = 6;
multiplex_limit = 6;
g_has_dots = false;
reverse_display = false;
pinMode(PinMap::extra1, OUTPUT);
pinMode(PinMap::extra2, OUTPUT);
digitalWrite(PinMap::extra1, LOW);
digitalWrite(PinMap::extra2, LOW);
break;
case(7): // IV-18 shield (note: save value as no shield - all bits on)
shield = SHIELD_IV18;
digits = 8;
multiplex_limit = 9; // 8 digits plus dot/dash
//mpx_count = 7;
g_has_dots = true;
reverse_display = true;
break;
default:
shield = SHIELD_NONE;
break;
}
}
#endif // HAVE_SHIELD_AUTODETECT
void set_shield(shield_t shield_type, uint8_t _digits /* = 4 */)
{
if (shield_type == SHIELD_7SEG) {
shield = SHIELD_7SEG;
digits = _digits;
multiplex_limit = 10; // ???
g_has_dots = true;
reverse_display = true;
}
#ifdef HAVE_14SEG_SUPPORT
else if (shield_type == SHIELD_14SEG) {
shield = SHIELD_14SEG;
digits = _digits;
g_has_dots = true;
reverse_display = true;
segments = 14;
}
#endif
else if (shield_type == SHIELD_16SEG) {
shield = SHIELD_16SEG;
digits = _digits;
multiplex_limit = digits;
g_has_dots = true;
reverse_display = true;
segments = 16;
}
else if (shield_type == SHIELD_IV6) {
shield = SHIELD_IV6;
digits = 6;
multiplex_limit = digits;
g_has_dots = true;
reverse_display = false;
}
else if (shield_type == SHIELD_IV17) {
shield = SHIELD_IV17;
digits = 4;
multiplex_limit = digits;
g_has_dots = true;
reverse_display = false;
segments = 16;
}
else if (shield_type == SHIELD_IV18) {
shield = SHIELD_IV18;
digits = 8;
multiplex_limit = digits+1;
g_has_dots = true;
reverse_display = true;
}
else if (shield_type == SHIELD_IN14) {
shield = SHIELD_IN14;
digits = 6;
multiplex_limit = digits;
g_has_dots = true;
reverse_display = true;
}
else if (shield_type == SHIELD_IN8_2) {
shield = SHIELD_IN8_2;
digits = 6;
multiplex_limit = digits;
g_has_dots = true;
reverse_display = true;
}
}
void clear_data()
{
for (uint8_t i = 0; i<16; i++) {
data[i] = ' ';
}
}
void clear_sData(void)
{
for (int i = 0; i<scroll_len; i++) {
sData[i] = ' ';
}
}
void set_blink(bool onOff)
{
blinking = onOff;
if (!blinking) display_on = 1;
// Serial.print("blink "); Serial.println(blinking);
}
void set_dimming(bool onOff)
{
dimming = onOff;
if (!dimming) {
TC4H = _brightness>>8; // set high order byte value for 10-bit comparand
OCR4D = _brightness; // restore brightness
}
}
void set_display(bool on)
{
display_on = on;
}
void flash_display(uint16_t ms) // flash display to show GPS update
{
display_on = false;
clear_display();
// _delay_ms(ms);
wDelay(ms);
display_on = true;
}
void button_timer(void);
// utility functions
// fixme: generalize this to print any length of number
uint8_t print_digits (int8_t num, uint8_t offset)
{
uint8_t ret = offset+2;
if (num < 0) {
data[offset-1] = '-'; // note assumption that offset is always positive!
num = -num;
}
if (num >= 100) {
ret = offset+3;
data[offset+2] = num % 10;
num /= 10;
}
data[offset+1] = num % 10;
num /= 10;
data[offset] = num % 10;
return ret;
}
uint8_t print_hour(uint8_t num, uint8_t offset, bool _24h_clock)
{
data[offset+1] = num % 10; // units
//num /= 10;
uint8_t h2 = num / 10 % 10; // tens
data[offset] = h2;
if (!_24h_clock && (h2 == 0)) {
data[offset] = ' '; // blank leading zero
}
return offset+2;
}
uint8_t print_ch(char ch, uint8_t offset)
{
data[offset++] = ch;
return offset;
}
uint8_t print_strn(const char* str, uint8_t offset, uint8_t n)
{
uint8_t i = 0;
while (n-- >= 0) {
data[offset++] = str[i++];
if (str[i] == '\0') break;
}
return offset;
}
// set dots based on mode and seconds
void print_dots(uint8_t mode, uint8_t seconds)
{
if (settings.show_dots) {
if (digits == 10 && mode == 0) {
sbi(dots, 3);
sbi(dots, 5);
}
else if (digits == 8 && mode == 0) {
sbi(dots, 2);
sbi(dots, 4);
}
else if (digits == 6 && mode == 0) {
sbi(dots, 1);
sbi(dots, 3);
}
else if (digits == 4 && seconds % 2 && mode == 0) {
sbi(dots, 1);
}
}
}
// shows time based on mode
// 4 digits: hour:min / sec
// 6 digits: hour:min:sec / hour-min
// 8 digits: hour:min:sec / hour-min-sec
void show_time(WireRtcLib::tm* t, bool _24h_clock, uint8_t mode)
{
dots = 0;
uint8_t offset = 0;
// uint8_t hour = _24h_clock ? t->hour : t->twelveHour;
uint8_t hour = _24h_clock ? t->hour : t->hour%12;
if (!_24h_clock && hour == 0) // show 12 for midnight and noon
hour = 12; // wbp
print_dots(mode, t->sec);
if (mode == 0) { // normal display mode
// nixie_print(hour, t->min, t->sec);
if (digits == 10) { // " HH.MM.SS "
offset = print_ch(' ', offset);
if (!_24h_clock && !t->am)
offset = print_ch('P', offset);
else
offset = print_ch(' ', offset);
offset = print_hour(hour, offset, _24h_clock);
offset = print_digits(t->min, offset);
offset = print_digits(t->sec, offset);
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
}
else if (digits == 8) { // "P HH.MM.SS "
if (!_24h_clock && !t->am)
offset = print_ch('P', offset);
else
offset = print_ch(' ', offset);
offset = print_ch(' ', offset); // shift time 1 space to rig
offset = print_hour(hour, offset, _24h_clock);
offset = print_digits(t->min, offset);
offset = print_digits(t->sec, offset);
offset = print_ch(' ', offset);
}
else if (digits == 6) { // "HH.MM.SS"
offset = print_hour(hour, offset, _24h_clock);
offset = print_digits(t->min, offset);
offset = print_digits(t->sec, offset);
}
else { // HH.MM
offset = print_hour(hour, offset, _24h_clock);
offset = print_digits(t->min, offset);
}
}
else if (mode == 1) { // extra display mode
// nixie_print_compact(hour, t->min, t->sec);
if (digits == 10) { // " HH-MM-SS "
offset = print_ch('-', offset);
offset = print_hour(hour, offset, _24h_clock);
offset = print_ch('-', offset);
offset = print_digits(t->min, offset);
offset = print_ch('-', offset);
offset = print_digits(t->sec, offset);
offset = print_ch('-', offset);
}
else if (digits == 8) { // "HH-MM-SS"
offset = print_hour(hour, offset, _24h_clock);
offset = print_ch('-', offset);
offset = print_digits(t->min, offset);
offset = print_ch('-', offset);
offset = print_digits(t->sec, offset);
}
else if (digits == 6) { // " HH-MM"
offset = print_hour(hour, offset, _24h_clock);
offset = print_ch('-', offset);
offset = print_digits(t->min, offset);
if (!_24h_clock && !t->am)
offset = print_ch('P', offset);
else
offset = print_ch(' ', offset);
}
else { // HH.MM
if (_24h_clock) {
offset = print_ch(' ', offset);
offset = print_digits(t->sec, offset);
offset = print_ch(' ', offset);
}
else {
if (t->am)
offset = print_ch('A', offset);
else
offset = print_ch('P', offset);
offset = print_ch('M', offset);
offset = print_digits(t->sec, offset);
}
}
}
}
// shows time - used when setting time
void show_time_setting(uint8_t hour, uint8_t min, uint8_t sec)
{
// nixie_print_compact(hour, min, sec);
dots = 0;
uint8_t offset = 0;
switch (digits) {
case 8:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 6:
offset = print_digits(hour, offset);
offset = print_ch('-', offset);
offset = print_digits(min, offset);
offset = print_ch(' ', offset);
break;
case 4:
offset = print_digits(hour, offset);
offset = print_digits(min, offset);
}
}
void show_temp(int8_t t, uint8_t f)
{
dots = 0;
uint8_t offset = 0;
// nixie_print(0, t, f);
switch (digits) {
case 10:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 8:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 6:
offset = print_ch(' ', offset);
offset = print_digits(t, offset);
offset = print_digits(f, offset);
offset = print_ch('C', offset);
break;
case 4:
offset = print_digits(t, offset);
offset = print_ch('&', offset);
offset = print_ch('C', offset);
}
if (digits == 10) dots = (1<<3);
else if (digits == 8) dots = (1<<3);
else if (digits == 6) dots = (1<<2);
else if (digits == 4) dots = 0;
}
void show_humidity(uint8_t hum)
{
dots = 0;
uint8_t offset = 0;
// nixie_print(0, 0, hum);
switch (digits) {
case 10:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 8:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 6:
offset = print_ch(' ', offset);
offset = print_digits(hum, offset);
offset = print_ch('R', offset);
offset = print_ch('H', offset);
break;
case 4:
offset = print_digits(hum, offset);
offset = print_ch(' ', offset);
offset = print_ch('H', offset);
}
}
void show_pressure(uint8_t pressure)
{
dots = 0;
uint8_t offset = 0;
uint8_t temp = pressure % 10;
uint8_t temp2 = pressure/= 10;
// nixie_print(0, temp2, temp);
switch (digits) {
case 10:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 8:
offset = print_ch(' ', offset);
offset = print_ch(' ', offset);
// fall-through
case 6:
offset = print_digits(pressure, offset);
offset = print_ch('k', offset);
offset = print_ch('P', offset);
offset = print_ch('a', offset);
break;
case 4:
offset = print_digits(pressure, offset);
offset = print_ch('P', offset);
}
}
void set_string(const char* str, uint8_t offset /* =0 */)
{
if (!str) return;
dots = 0;
clear_data();
for (int i = offset; i <= digits-1; i++) {
if (!*str) break;
data[i] = *(str++);
}
}
void set_string(const char* str)
{
set_string(str, 0);
}
void set_scroll(char* str)
{
uint8_t i = 0;
if (!str) return;
dots = 0;
clear_sData();
for (i = 0; i <25; i++) {
if (!*str) break;
sData[i] = *(str++);
}
scroll_limit = i+1;
scroll_index = 0;
// display_scroll(0);
scroll_counter = scroll_time; // start scrolling
_scrolling = true;
// while (scrolling) // wait for scrolling to finish
// ;
}
// shows setting string
void show_setting_string(const char* short_str, const char* long_str, const char* value, bool show_setting)
{
// data[0] = data[1] = data[2] = data[3] = data[4] = data[5] = data[6] = data[7] = ' ';
clear_data();
if (get_digits() == 8) {
set_string(short_str);
print_strn(value, 4, 3);
}
else if (get_digits() == 6) {
if (show_setting)
print_strn(value, 2, 3);
else
set_string(long_str);
}
else {
if (show_setting)
print_strn(value, 0, 3);
else
set_string(short_str);
}
}
#ifdef FEATURE_AUTO_DATE
// scroll the date - called every 100 ms
void scroll_date(WireRtcLib::tm* te_, uint8_t region)
{
dots = 0;
// uint8_t di;
char sl;
char sd[13]; // = " 03/14/1947";
sd[0] = sd[1] = ' ';
// clr_sData();
if (shield == SHIELD_IV17)
sl = '/';
else
sl = '-';
switch (region) {
case FORMAT_DMY:
sd[2] = te_->mday / 10 + '0';
sd[3] = te_->mday % 10 + '0';
sd[4] = sd[7] = sl;
sd[5] = te_->mon / 10 + '0';
sd[6] = te_->mon % 10 + '0';
sd[8] = '2';
sd[9] = '0';
sd[10] = te_->year / 10 + '0';
sd[11] = te_->year % 10 + '0';
break;
case FORMAT_MDY:
sd[2] = te_->mon / 10 + '0';
sd[3] = te_->mon % 10 + '0';
sd[4] = sd[7] = sl;
sd[5] = te_->mday / 10 + '0';
sd[6] = te_->mday % 10 + '0';
sd[8] = '2';
sd[9] = '0';
sd[10] = te_->year / 10 + '0';
sd[11] = te_->year % 10 + '0';
break;
case FORMAT_YMD:
default:
sd[2] = '2';
sd[3] = '0';
sd[4] = te_->year / 10 + '0';
sd[5] = te_->year % 10 + '0';
sd[6] = sd[9] = sl;
sd[7] = te_->mon / 10 + '0';
sd[8] = te_->mon % 10 + '0';
sd[10] = te_->mday / 10 + '0';
sd[11] = te_->mday % 10 + '0';
break;
}
sd[12] = 0; // null terminate
// Serial.print("date: "); Serial.println(sd);
set_scroll(sd);
}
#endif
void show_setting_int(const char* short_str, const char* long_str, int value, bool show_setting)
{
// Serial.print("show_setting_int ");
// Serial.println(value);
// data[0] = data[1] = data[2] = data[3] = data[4] = data[5] = data[6] = data[7] = ' ';
clear_data();
if (get_digits() == 8) {
set_string(long_str);
print_digits(value, 6);
}
else if (get_digits() == 6) {
set_string(long_str);
print_digits(value, 4);
}
else {
if (show_setting)
print_digits(value, 2);
else
set_string(short_str);
}
}
void show_set_time(void)
{
if (get_digits() == 8)
set_string("Set Time");
else if (get_digits() == 6)
set_string(" Time ");
else
set_string("Time");
}
void show_set_alarm(void)
{
if (get_digits() == 8)
set_string("Set Alrm");
else if (get_digits() == 6)
set_string("Alarm");
else
set_string("Alrm");
}
// Write 8 bits to HV5812 driver
void write_vfd_8bit(uint8_t data)
{
// shift out MSB first
for (uint8_t i = 0; i < 8; i++) {
if (!!(data & (1 << (7 - i))))
DATA_HIGH;
else
DATA_LOW;
CLOCK_HIGH;
CLOCK_LOW;
}
}
void write_vfd_7seg(uint8_t digit, uint8_t segments)
{
// temporary correction for incorrectly wired display
uint8_t x = 0;
if (segments & (1<<0)) x |= (1<<0);
if (segments & (1<<1)) x |= (1<<1);
if (segments & (1<<5)) x |= (1<<2);
if (segments & (1<<6)) x |= (1<<3);
if (segments & (1<<2)) x |= (1<<4);
if (segments & (1<<4)) x |= (1<<5);
if (segments & (1<<3)) x |= (1<<6);
if (segments & (1<<7)) x |= (1<<7);
segments = x;
uint8_t segments_hi = 0;
if (dots & (1<<digit))
segments_hi |= (1<<0);
//segments |= (1<<7); // DP is at bit 7
write_vfd_8bit(segments_hi);
write_vfd_8bit(segments);
if (digit > 7) {
write_vfd_8bit(1<<(digit-8));
write_vfd_8bit(0);
}
else {
write_vfd_8bit(0);
write_vfd_8bit(1<<digit);
}
LATCH_DISABLE;
LATCH_ENABLE;
}
// fixme: need to determine placement of dots
// fixme: need to determine placement of second dot (if present)
void write_vfd_standard(uint8_t digit, uint16_t segments)
{
uint16_t d = 1<<digit;
write_vfd_8bit(segments >> 8);
write_vfd_8bit(segments);
write_vfd_8bit(d >> 8);
write_vfd_8bit(d);
LATCH_DISABLE;
LATCH_ENABLE;
}
// Writes to the HV5812 driver for IV-6
// HV1~6: Digit grids, 6 bits
// HV7~14: VFD segments, 8 bits
// HV15~20: NC
void write_vfd_iv6(uint8_t digit, uint8_t segments)
{
if (dots & (1<<digit))
segments |= (1<<7); // DP is at bit 7
uint32_t val = (1 << digit) | ((uint32_t)segments << 6);
write_vfd_8bit(0); // unused upper byte: for HV518P only
write_vfd_8bit(val >> 16);
write_vfd_8bit(val >> 8);
write_vfd_8bit(val);
LATCH_DISABLE;
LATCH_ENABLE;
}
#define IV17_LEFT_DOT 0b00010000
#define IV17_RIGHT_DOT 0b00100000
// Writes to the HV5812 driver for IV-17
// HV1~4: Digit grids, 4 bits
// HV 5~2: VFD segments, 16-bits
void write_vfd_iv17(uint8_t digit, uint16_t segments)
{
uint32_t val = (1 << digit) | ((uint32_t)segments << 4);
//write_vfd_8bit(val >> 24);
write_vfd_8bit(0);
if (dots & (1<<digit))
write_vfd_8bit(val >> 16 | IV17_RIGHT_DOT);
else
write_vfd_8bit(val >> 16);
write_vfd_8bit(val >> 8);
write_vfd_8bit(val);
LATCH_DISABLE;
LATCH_ENABLE;
}
// Writes to the HV5812 driver for IV-17 6-digit
// HV1~4: Digit grids, 4 bits
// HV 5~2: VFD segments, 16-bits
void write_vfd_iv17_6d(uint8_t digit, uint16_t segments)
{
uint32_t val;
if (digit == 0) {
digitalWrite(PinMap::extra1, LOW);
digitalWrite(PinMap::extra2, HIGH);
val = ((uint32_t)segments << 4);
}
else if (digit == 5) {
digitalWrite(PinMap::extra1, HIGH);
digitalWrite(PinMap::extra2, LOW);