@@ -89,13 +89,29 @@ const byte velThreshold = 100; //ms
89
89
// When an adj up/down input (btn or rot) follows another in less than this time, value will change more (10 vs 1).
90
90
// Recommend ~100 for rotaries. If you want to use this feature with buttons, extend to ~400.
91
91
92
+
93
+ // //////// Other global consts and vars used in multiple sections //////////
94
+
95
+ DS3231 ds3231; // an object to access the ds3231 specifically (temp, etc)
96
+ RTClib rtc; // an object to access a snapshot of the ds3231 rtc via now()
97
+ DateTime tod; // stores the now() snapshot for several functions to use
98
+ byte toddow; // stores the day of week as calculated from tod
99
+
100
+ // Software version
101
+ const byte vMaj = 1 ;
102
+ const byte vMin = 3 ;
103
+
92
104
// EEPROM locations for set values - default values are in initEEPROM()
93
- // const byte alarmTimeLoc = 0; //and 1 (word) in minutes past midnight.
94
- // const byte alarmOnLoc = 2; //byte
105
+ const byte alarmTimeLoc = 0 ; // and 1 (word) in minutes past midnight.
106
+ const byte alarmOnLoc = 2 ; // byte
95
107
const byte dayCountYearLoc = 3 ; // and 4 (word)
96
108
const byte dayCountMonthLoc = 5 ; // byte
97
109
const byte dayCountDateLoc = 6 ; // byte
98
110
111
+ // EEPROM locations for software version as of last run - to detect software upgrades that need EEPROM initializations
112
+ const byte vMajLoc = 14 ;
113
+ const byte vMinLoc = 15 ;
114
+
99
115
// EEPROM locations and default values for options menu
100
116
// Option numbers are 1-index, so arrays are padded to be 1-index too, for coding convenience. TODO change this
101
117
// Most vals (default, min, max) are 1-byte. In case of two-byte (max-min>255), high byte is loc, low byte is loc+1.
@@ -107,12 +123,7 @@ const word optsMin[] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
107
123
const word optsMax[] = {0 , 2 , 2 , 2 , 1 ,50 , 1 , 6 , 4 ,60 ,999 , 2 ,1439 ,1439 , 2 , 6 , 6 ,1439 ,1439 };
108
124
109
125
110
- // //////// Other global consts and vars used in multiple sections //////////
111
126
112
- DS3231 ds3231; // an object to access the ds3231 specifically (temp, etc)
113
- RTClib rtc; // an object to access a snapshot of the ds3231 rtc via now()
114
- DateTime tod; // stores the now() snapshot for several functions to use
115
- byte toddow; // stores the day of week as calculated from tod
116
127
117
128
// Hardware inputs and value setting
118
129
// AdaEncoder mainRot;
@@ -132,8 +143,6 @@ bool fnSetValVel; //whether it supports velocity setting (if max-min > 30)
132
143
word fnSetValDate[3 ]; // holder for newly set date, so we can set it in 3 stages but set the RTC only once
133
144
134
145
// Volatile running values
135
- word alarmTime = 0 ; // alarm time of day TODO move these to alarmTimeLoc and alarmOnLoc
136
- bool alarmOn = 0 ; // alarm switch
137
146
word soundRemain = 0 ; // alarm/timer sound timeout counter, seconds
138
147
word snoozeRemain = 0 ; // snooze timeout counter, seconds
139
148
word timerInitial = 0 ; // timer original setting, seconds - up to 18 hours (64,800 seconds - fits just inside a word)
@@ -148,7 +157,7 @@ void setup(){
148
157
Wire.begin ();
149
158
initOutputs ();
150
159
initInputs ();
151
- if (!enableSoftAlarmSwitch) alarmOn= 1 ; // TODO test and get rid of
160
+ if (!enableSoftAlarmSwitch) writeEEPROM (alarmOnLoc, 1 , false ) ; // TODO test and get rid of
152
161
if (readInput (mainSel)==LOW) initEEPROM ();
153
162
}
154
163
@@ -503,8 +512,8 @@ void initEEPROM(){
503
512
ds3231.setMinute (0 );
504
513
ds3231.setSecond (0 );
505
514
// Set the default values that aren't part of the options menu
506
- // writeEEPROM(alarmTimeLoc,420,true); //7am - word
507
- // writeEEPROM(alarmOnLoc,enableSoftAlarmSwitch==0?1:0,false); //off, or on if no software switch spec'd
515
+ writeEEPROM (alarmTimeLoc,420 ,true ); // 7am - word
516
+ writeEEPROM (alarmOnLoc,enableSoftAlarmSwitch==0 ?1 :0 ,false ); // off, or on if no software switch spec'd
508
517
writeEEPROM (dayCountYearLoc,2018 ,true );
509
518
writeEEPROM (dayCountMonthLoc,1 ,false );
510
519
writeEEPROM (dayCountDateLoc,1 ,false );
@@ -600,7 +609,7 @@ void checkRTC(bool force){
600
609
// at 2am, check for DST change
601
610
if (tod.minute ()==0 && tod.hour ()==2 ) autoDST ();
602
611
// check if we should trigger the alarm - TODO weekday limiter
603
- if (tod.hour ()*60 +tod.minute ()==alarmTime && alarmOn && false ) {
612
+ if (tod.hour ()*60 +tod.minute ()==readEEPROM (alarmTimeLoc, true ) && readEEPROM (alarmOnLoc, false ) && false ) {
604
613
fnSetPg = 0 ; fn = fnIsTime; soundRemain = alarmDur*60 ;
605
614
}
606
615
// checkDigitCycle();
@@ -627,7 +636,7 @@ void checkRTC(bool force){
627
636
// If alarm snooze has time on it, decrement and trigger beeper if we reach zero (and alarm is still on)
628
637
if (snoozeRemain>0 ) {
629
638
snoozeRemain--;
630
- if (snoozeRemain<=0 && alarmOn ) { fnSetPg = 0 ; fn = fnIsTime; soundRemain = alarmDur*60 ; }
639
+ if (snoozeRemain<=0 && readEEPROM (alarmOnLoc, false ) ) { fnSetPg = 0 ; fn = fnIsTime; soundRemain = alarmDur*60 ; }
631
640
}
632
641
} // end natural second
633
642
@@ -679,9 +688,9 @@ void setDST(char dir){
679
688
680
689
void switchAlarm (char dir){
681
690
if (enableSoftAlarmSwitch){
682
- if (dir==1 ) alarmOn= 1 ;
683
- if (dir==-1 ) alarmOn= 0 ;
684
- if (dir==0 ) alarmOn = !alarmOn ;
691
+ if (dir==1 ) writeEEPROM (alarmOnLoc, 1 , false ) ;
692
+ if (dir==-1 ) writeEEPROM (alarmOnLoc, 0 , false ) ;
693
+ if (dir==0 ) writeEEPROM (alarmOnLoc,! readEEPROM (alarmOnLoc, false ), false ) ;
685
694
}
686
695
}
687
696
0 commit comments