-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
3354 lines (2698 loc) · 79.8 KB
/
main.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
/*
Copyright (C) 2011 by Cogwheel, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// (bobc 20Aug2010)
// Beautification brought to you by astyle -A1
/*
*/
#include "WProgram.h"
#include "avr/wdt.h"
#include "TimerOne.h"
#include "MsTimer2.h"
#include "Spi.h"
#include <Print.h>
#define MAIN
#include "nixie_system.h"
#include "buildno.h"
#include "buttons.h"
#include "display.h"
#include "nvclk.h"
#include "eeprom.h"
#include "adc.h"
#include "sio.h"
#include "hv.h"
#include "led.h"
#include "dst.h"
#include "beep.h"
#undef int
#include <stdio.h>
#include <avr/pgmspace.h>
#undef D
// uncomment one or the other:
//#define D(...) // debugging off
#define D _D // debugging on
//
// main(void)
//
//
int main(void)
{
boolean dotest = 0;
Inits(); // one-time start-up initializations
ShowCmds(cmdVER); // boot-up banner on Serial
//report_free_mem(); // important ram consumption info
// start-up high-voltage
HV.State = hvStRampUp;
HV.SetPWM(HV.DutyCycleMaxValMinHV);
DispCycleInit();
// start-up scanning
Disp.ScanEnable();
//
// If a button is held down at power-up do configuration or tests
//
ButtonPowerUpState = Buttons.Eval(beaPowerUp);
{
boolean doreboot = 0;
switch (ButtonPowerUpState)
{
case confNoChange:
break;
case confIN17x7:
DoNVMemInit(confIN17x7);
DoNVClkInit();
doreboot++;
break;
case confTst:
dotest++;
break;
default: // unimplemented power-up configs are met with same 'recycle now'response
doreboot++;
break;
}
if (doreboot)
{
Led.SetPattern(".-. R");
SIO.TxConstSt(PSTR(": power cycle now"));
SIO.TxSt(EOL);
while(1) ;
}
}
Disp.BlankMask(0b00000000);
TransFxCur = tfxNone;
if (dotest)
{
EnterTestMode();
}
else
{
//
// normal start
//
DoTest(tstAllSameAnimate,0,0,0); // Exercise all elements of all tubes
DisplayChange(dispTests);
Beep.SetPattern("! ! ! -"); // dit, dit, dit, dah !
NVClk.GetHMS(TimeDigits);
}
//
// main loop
//
while (OrderPrevails) // never exited under normal circumstances..
{
unsigned char c;
while(!OneHundredHzFlag); // spin here to keep soft loop and isrs in sync
OneHundredHzFlag = 0; // isr will set it 100x/sec.
if (HzFlag) // 1x per second things
{
HzFlag = 0;
SecsCtr = (SECTENS*10) + SECONES;
MinsCtr = (MINTENS*10) + MINONES;
HrsCtr = Twelve2TwentyFour();
if ( !(AlarmHrs == 0 && AlarmMins == 0))// 00:00 means disabled
{
if (
AlarmHrs == HrsCtr &&
AlarmMins == MinsCtr &&
SecsCtr == 0 &&
!AlarmTriggered)
{
StartAlarm();
AlarmTriggered = 1;
Disp.StateLocked = 0;
DisplayChange(dispHrsMinsSecs);
}
}
// every minute
if (SecsCtr == 0)
{
if (AlarmSnoozeCtr && AlarmSnoozeCtr++ &&
AlarmSnoozeCtr == AlarmSnoozeVal && AlarmTriggered)
{
AlarmSnoozeCtr = 0;
StartAlarm();
}
}
NVMemManage();
if (SecondsSinceReset < 255)
SecondsSinceReset++; // prevent wrap;
if (TimeSinceLastCmdSecs < 255)
TimeSinceLastCmdSecs++; // prevent wrap;
// Every hour (xx:00:00.0)..
if ( CurDispMode & dispIsNorm &&
SECTENS == 0 && SECONES == 0 &&
MINONES == 0 && MINTENS == 0)
{
// deal w/on and off times
unsigned char ontime = NVClk.Read(nvadOnTime);
unsigned char offtime = NVClk.Read(nvadOffTime);
if (ontime != offtime)
{
if (HrsCtr == offtime)
{
DisplayChange(dispOff);
Disp.StateLocked = 1;
}
else if (HrsCtr == ontime)
{
Disp.StateLocked = 0;
DisplayChange(dispHrsMinsSecs);
}
}
UpdateMDY();
// Check DST
if ((NVClk.Read(nvadDSTOn) == 1) && HrsCtr == 2)
{
// Start DST
if ( DST.StartNow(NVClk.GetMM(), NVClk.GetDD(), NVClk.GetDOW()))
{
NVClk.Write(nvadDSTFellBack,0);
NVClk.SetH(3);
SIO.TxConstSt(PSTR(":dst adj forward 1h")) ;
SIO.TxSt(EOL);
if (CurDispMode == dispHrsMinsSecs)
DisplayChange(dispHrsMinsSecs); // refreshes display
}
// End DST
else if (NVClk.Read(nvadDSTFellBack) != 1 &&
DST.EndNow(NVClk.GetMM(), NVClk.GetDD(), NVClk.GetDOW()))
{
NVClk.Write(nvadDSTFellBack,1);
NVClk.SetH(1);
SIO.TxConstSt(PSTR(":dst adj back 1h")) ;
SIO.TxSt(EOL);
if (CurDispMode == dispHrsMinsSecs)
DisplayChange(dispHrsMinsSecs); // refreshes display
}
}
}
// done with startup, switch to dispHrsMinsSecs mode
if (SecondsSinceReset == STARTUP_INTERVAL && !dotest)
{
HV.DutyCycleUserVal= NVClk.ReadWord(nvadHVUserVal);
TransFxCur = TransFxVal;
DisplayChange(dispHrsMinsSecs);
Led.SetPattern(0);
Led.BeepAlso = 0;
TimeSinceLastCmdSecs = DISPLAY_TIMEOUT_INTERVAL+1; // prevent first time.
}
// if we've been left in an alternate mode, flip back to dispHrsMinsSecs
if (CurDispMode != dispHrsMinsSecs &&
TimeSinceLastCmdSecs == DISPLAY_TIMEOUT_INTERVAL &&
!dotest)
DisplayChange(dispHrsMinsSecs);
if (TimeSinceLastCmdSecs > 5 && !dotest)
{
if (TimSetIntervalSecsCtr)
TimSetIntervalSecsCtr--;
if (!(TimSetIntervalSecsCtr)) // periodically set time from NVClk
{
NVClk.GetHMS(TimeDigits);
if (CurDispMode & dispIsNorm)
{
if (NVClk.IsIn12HourMode())
IndicatePM(NVClk.IsPM());
else
IndicatePM(0);
}
TimSetIntervalSecsCtr = TimSetIntervalSecs;
}
// Cycle Display with other things besides time, periodically
if (DispCycIntvl)
{
unsigned char mod,offset;
offset = 3;
switch(DispCycIntvl)
{
// dcy implementation:
//
case 4:
mod = 10;
break; // every 10 secs
case 2:
mod = 20;
break; // every 20 secs
case 3:
mod = 30;
break; // every 30 secs
case 1:
mod = 60;
offset = 33;
break; // every 60 seconds
}
if (!((SecsCtr-offset)%mod))
{
DispCycDwellCtr = DispCycDwellVal-1; // triggers next block of code
DispCycleCur = 1;
}
if (DispCycDwellCtr) DispCycDwellCtr++;
if (DispCycDwellCtr == DispCycDwellVal)
{
if ((DispCycle[DispCycleCur]) == dispNone)
DispCycleReset();
else
{
DisplayChange(DispCycle[DispCycleCur]);
DispCycDwellCtr = 1;
DispCycleCur++;
if ((DispCycle[DispCycleCur]) == dispOff) // skip over off (it is there for the buttons)
DispCycleCur++;
}
}
} // DispCycIntvl
}
} // HzFlag
if (TenHzFlag)
{
TenHzFlag = 0;
if (Buttons.AnyEvent && (CurDispMode & dispIsNorm))
NormButtonEventHandler();
else if ((Buttons.AnyEvent | Buttons.AnyPressedCtr) && (CurDispMode & dispIsSetHMS))
{
SetTimeButtonEventHandler();
TimeSinceLastCmdSecs = 0;
}
else if ((Buttons.AnyEvent | Buttons.AnyPressedCtr) && (CurDispMode & dispIsSetOptions))
{
SetOptionsButtonEventHandler();
TimeSinceLastCmdSecs = 0;
}
else if (Buttons.AnyEvent && (CurDispMode & dispIsTest))
{
TestButtonEventHandler();
}
}
SIO.Check();
SIO.IWork();
} // while(OrderPrevails)
return 0; // notreached
}
//
// void ChimeBusiness(void)
//
// Called from main(), takes care of audible alerts and chimes
//
//
void ChimeBusiness(void)
{
boolean dobeep = 0;
if (TenthsCtr == 0)
Beep.SyncWithSeconds = 1; // set
if (AlarmTriggered)
return;
//
// Chime
//
if ( !(CurDispMode == dispOff && Disp.StateLocked) &&
(TenthsCtr == 0) &&
(CurDispMode & dispIsNorm) &&
( SecsCtr == 55 ||
SecsCtr == 10 ||
SecsCtr == 25 ||
SecsCtr == 40)
)
{
switch(ChimeIntvl)
{
case 0: // not at all
break;
case 1: // on the hour
if (MinsCtr == 59 && SecsCtr == 55)
dobeep = 1;
break;
case 2: // half hour
if ((MinsCtr == 59 || MinsCtr == 29) && SecsCtr == 55)
dobeep = 1;
break;
case 3: // quarter hour
if ((MinsCtr == 59 || MinsCtr == 29 || MinsCtr == 14 || MinsCtr == 44) && SecsCtr == 55)
dobeep = 1;
break;
case 4: // every 15 secs. Ultra annoying.
dobeep = 1;
break;
}
if (dobeep)
{
Beep.SyncWithSecondsEnabled = 1;
Beep.SetPattern("! ! ! -");
}
}
}
//
// void DispWriteHMS(void)
//
// Write current time to display buffer
//
void DispWriteHMS(void)
{
unsigned char DispCtr;
for (DispCtr = 0; DispCtr < Disp.NumDevs; DispCtr++)
{
Disp.Devs[DispCtr].NewVal = TimeDigits[DispCtr] & 0b00001111;
}
}
//
// void DoTest(unsigned char TestNo, int Val1, int Val2, int Val3)
//
// Executes Testno. Val1, Val2, and Val3 are optional parameters to the test
//
//
void DoTest(unsigned char TestNo, int Val1, int Val2, int Val3)
{
unsigned char count;
if (TestNo != tstJustOne)
{
Disp.ScanEnable();
Disp.Blink();
}
Beep.SetPattern(0);
for(count = 0; count < Disp.NumDevs; count++) Disp.Devs[count].NewVal = 0;
switch(TestNo)
{
// 0:HV 1:AllSame 2:JustOne 3:JustOneSeq 4:Ramp 5:Random 6:AllSameAnimate 7:RandomAnimate 8:Beep
case tstHV:
Disp.ScanOffTimer = 0;
Disp.ScanDisable();
Disp.Devs[0].NewVal = 0;
Disp.ScanCtr = 255;
Disp.Mux();
HV.SetPWM(((unsigned int)(Val1&0x0FFF)));
//SIOPrintf(":HVPWM: %d",HV.DutyCycleCurVal);
break;
case tstAllSame:
for(count = 0; count < Disp.NumDevs; count++)
Disp.Devs[count].NewVal = Val1;
break;
case tstJustOne:
case tstJustOneSeq:
Disp.ScanOffTimer = 0;
Disp.ScanDisable();
Disp.ScanCtr = Val1;
Disp.Devs[Disp.ScanCtr].NewVal = Val2;
--Disp.ScanCtr;
Disp.Mux();
TestManageCtr = TestManageDiv = Val3;
break;
case tstRandom:
Disp.Devs[0].NewVal = 0;
Disp.Devs[1].NewVal = 9;
Disp.Devs[2].NewVal = 1;
Disp.Devs[3].NewVal = 8;
Disp.Devs[4].NewVal = 2;
Disp.Devs[5].NewVal = 7;
Disp.Devs[6].NewVal = 3;
Disp.Devs[7].NewVal = 6;
break;
case tstRamp:
HV.State = hvStRampDown;
break;
case tstAllSameAnimate:
TestManageCtr = TestManageDiv = Val1;
break;
case tstRandomAnimate:
for(count = 0; count < Disp.NumDevs; count++)
if (++Disp.Devs[count].NewVal >= Disp.NumDevs)
break;
case tstBeep:
Beep.Val = Val1;
Beep.SyncWithSecondsEnabled = 1;
switch(Val2)
{
case 0:
Beep.SetPattern("! R");
break;
case 1:
Beep.SetPattern("|||||| R");
break;
case 2:
Beep.SetPattern("- R");
break;
case 3:
Beep.SetPattern("_ R");
break;
case 4:
Beep.SetPattern("! ! ! - ");
break;
}
break;
case tstWipe:
Disp.WipeRateVal = Val1;
break;
default:
break;
}
Disp.CurTest = TestNo;
Disp.CurTestVal = Val1;
}
//
// void TestHundredHzChores(void)
//
// Called from on OneHundredHzFlag, performs various display dynamic test pattern functions
// Mostly animations in certain modes
//
void TestHundredHzChores()
{
unsigned char count;
//
// Skipping logic for doing things less than 1x per call
//
// Set TestManageDiv to zero and things happe 1x per call
//
// Set TestManageDiv to 1 things will happen every other call, etc..
//
if (TestManageDiv)
if (!(--TestManageCtr))
TestManageCtr = TestManageDiv;
else
return;
switch(Disp.CurTest)
{
case tstRamp:
if (HV.State == hvStAdjusted)
HV.State = hvStRampDown;
else if (HV.State == hvStOff)
HV.State = hvStRampUp;
break;
case tstJustOne:
if (TimeSinceLastCmdSecs >= 15)
Disp.CurTest = tstJustOneSeq;
break;
case tstJustOneSeq:
#if 1
if (Disp.ScanCtr == 0)
for(count = 0; count < Disp.NumDevs; count++)
if (++Disp.Devs[count].NewVal >= Disp.NumElems)
Disp.Devs[count].NewVal = 0;
#endif
Disp.Mux();
break;
case tstAllSameAnimate:
for(count = 0; count < Disp.NumDevs; count++)
if (++Disp.Devs[count].NewVal >= Disp.NumElems)
Disp.Devs[count].NewVal = 0;
break;
case tstRandomAnimate:
for(count = 0; count < Disp.NumDevs; count++)
if (++Disp.Devs[count].NewVal >= Disp.NumElems)
break;
default:
break;
}
}
// void TimeKeeping(opt)
//
// Called from TenHzNonMaskableChores(), performs actual abstract,
// hw-independent aspect of time keeping functions
//
// Generally, the processor keeps the time itself, but depends on
// regular resets from the NVClk
//
// opt - tkoIncBySecs : increments by seconds. Used when setting
// time from buttons.
//
//
void TimeKeeping12(unsigned char tkoption)
{
TenthsCtr = TENTHS;
if ( tkoption == tkoIncByTenSecs ||
(tkoption == tkoNorm && (++TENTHS > 9 )))
{
TENTHS = 0;
if ( tkoption == tkoIncByTenSecs ||
(tkoption == tkoNorm && (++SECONES > 9 )))
{
SECONES = 0;
if (++SECTENS > 5)
{
SECTENS = 0;
if (++MINONES > 9)
{
MINONES = 0;
if (++MINTENS > 5)
{
MINTENS = 0;
if (HRTENS < 1) // 01 02 03 04 05 06 07 08 09
{
if (++HRONES > 9)
{
HRONES = 0;
HRTENS = 1;
}
}
else // 10 11 -> 12 12->1
{
unsigned char OldHours = HRTENS*10 + HRONES;
if (++HRONES > 2)
{
HRTENS = 0;
HRONES = 1;
}
if (OldHours == 11 && HRTENS*10 + HRONES == 12)
{
if (NVClk.IsIn12HourMode())
{
if (Disp.IsPM)
{
Disp.IsPM = 0;
IndicatePM(0);
}
else
{
Disp.IsPM = 1;
IndicatePM(1);
}
}
}
}
}
}
}
}
}
}
//
// void TimeKeeping24(unsigned char tkoption)
//
// Same role as TimeKeeping12(), but for 12 hour mode
//
//
void TimeKeeping24(unsigned char tkoption)
{
TenthsCtr = TENTHS;
if ( tkoption == tkoIncByTenSecs ||
(tkoption == tkoNorm && (++TENTHS > 9 )))
{
TENTHS = 0;
if ( tkoption == tkoIncByTenSecs ||
(tkoption == tkoNorm && (++SECONES > 9 )))
{
SECONES = 0;
if (++SECTENS > 5)
{
SECTENS = 0;
if (++MINONES > 9)
{
MINONES = 0;
if (++MINTENS > 5)
{
MINTENS = 0;
++HRONES;
if ( (HRTENS <= 1 && HRONES > 9) || // handles 00 through 19
( HRTENS == 2 && HRONES > 3 ) ) // handles 20 through 23
{
HRONES = 0;
if (++HRTENS > 2)
HRTENS = 0;
}
}
}
}
}
}
}
//
// void TimeKeeping(unsigned char tkoption)
//
//
// Calls TimeKeeping12() or TimeKeeping24() as appropriate
//
//
void TimeKeeping(unsigned char tkoption)
{
if (NVClk.IsIn12HourMode())
TimeKeeping12(tkoption);
else
TimeKeeping24(tkoption);
}
//
// void TenHzNonMaskableChores(void)
//
// Called 10x/second from OneKhzIrup();
// Takes care of things that must get done 10/x per second no matter what.
// Less critical things get done in the top while(OrderPrevails) loop
// in main()
//
inline void TenHzNonMaskableChores(void)
{
// HzFlag is the soft seconds indicator that other code watches for
if (!(--SecDivCtr))
{
//D("TenHzNonMaskableChores, SecDivCtr:%d",SecDivCtr);
SecDivCtr = 10;
HzFlag = 1;
}
// restart a/d sampling on high voltage
if (HVADC.DoneFlag)
{
HVADC.Restart();
HVADC.DoneFlag = 0;
}
// Disp.ScanOffTimer allows us to blink the display
if (Disp.ScanOffTimer)
{
if (Disp.ScanOffTimer++ == 3)
{
Disp.ScanOffTimer = 0;
Disp.ScanEnable();
}
}
if (CurDispMode != dispSetHrsMinsSecs)
TimeKeeping(tkoNorm);
switch(CurDispMode)
{
case dispOff:
break;
case dispHrsMinsSecs:
DispWriteHMS();
break;
case dispSetHrsMinsSecs:
DispWriteHMS();
break;
case dispSetOptions:
break;
default:
break;
}
ChimeBusiness();
}
//
// void OneKhzIrup(void)
//
// Called off of Timer2 -generated interrupt
//
void OneKhzIrup(void)
{
const char OneHundredHzDiv = 5;
static unsigned char OneHundredHzCtr = OneHundredHzDiv;
const char TenHzDiv = 50;
static unsigned char TenHzCtr = TenHzDiv;
static bool FiveHundredHzTog;
// We could have gotten away w/a 500khz irup if it weren't
// for the need to get a reasonable high pitch out of the
// beeper TODO in future hardware: Add dedicated or at least louder
// hw for noise-making
if (Beep.Enable)
{
if (!Beep.Ctr--)
{
digitalWrite(pinBeep1, LOW);
digitalWrite(pinBeep2, HIGH);
Beep.Ctr = Beep.Val;
}
else
{
digitalWrite(pinBeep1, HIGH);
digitalWrite(pinBeep2, LOW);
}
}
if (!FiveHundredHzTog)
{
FiveHundredHzTog = 1;
return;
}
FiveHundredHzTog = 0;
// from here down gets executed 500x/sec
if (Disp.ScanEnabled)
Disp.Mux();
// TenHz Things
if (!(--TenHzCtr))
{
TenHzNonMaskableChores();
TenHzCtr = TenHzDiv;
TenHzFlag = 1; // indication to do soft TenHz Chores
}
// 100Hz things
if (!(--OneHundredHzCtr))
{
Led.HundredHzChores();
Beep.HundredHzChores();
Disp.HundredHzChores();
HV.HundredHzChores();
Buttons.HundredHzChores();
if (CurDispMode == dispTests)
TestHundredHzChores();
OneHundredHzCtr = OneHundredHzDiv;
// pretty important this is the last thing
// to happen here so main() keeps synced
OneHundredHzFlag = 1;
}
}
//
// void DSTGetSettings(void)
//
// Obtain DST Settings from NVmem
//
void DSTGetSettings(void)
{
/*
DST.StartDayOfWeekCount = dstLast;
DST.StartDayOfWeek = dstSunday; // sunday
DST.StartMonth = dstMarch; // in march
*/
DST.StartDayOfWeekCount = NVClk.Read(nvadDSTStartDayOfWeekCount);
DST.StartDayOfWeek = NVClk.Read(nvadDSTStartDayOfWeek );
DST.StartMonth = NVClk.Read(nvadDSTStartMonth );
DST.EndDayOfWeekCount = NVClk.Read(nvadDSTEndDayOfWeekCount );
DST.EndDayOfWeek = NVClk.Read(nvadDSTEndDayOfWeek );
DST.EndMonth = NVClk.Read(nvadDSTEndMonth );
}
//
// void IndicatePM(boolean On)
//
//
// On : 1 indicate somehow that it is PM
// : 0 AM
//
//
// This just turns the LED on if PM is set *if* the
// ledMode is set to ledAMPM
//
// This enables us to override the function of the LED for
// other things.
//
//
void IndicatePM(boolean On)
{
if (Led.Mode == ledAMPM)
{
if (On)
digitalWrite(pinLED, LOW);
else
digitalWrite(pinLED, HIGH);
}
}
//
// void DoCmd(unsigned int hash, char *cparg)
//
// Execute an operational command
//
// unsigned int hash : command id
// unsigned char *cparg : parameter
//
void DoCmd(unsigned char cmdid, char *cparg)
{
char *cp,copt1,copt2,copt3;
int iopt1,iopt2,iopt3,iopt4, iopt5, iopt6;
boolean paramvalid = 0;
boolean showcmd = 0;
boolean cmdvalid = 0;
unsigned char invalids = 0;