Skip to content

Commit 67eadfb

Browse files
committed
Working on alarm values and versioning in EEPROM
1 parent aeb98bc commit 67eadfb

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

sixtube_lm/sixtube_lm.ino

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,29 @@ const byte velThreshold = 100; //ms
8989
// When an adj up/down input (btn or rot) follows another in less than this time, value will change more (10 vs 1).
9090
// Recommend ~100 for rotaries. If you want to use this feature with buttons, extend to ~400.
9191

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+
92104
//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
95107
const byte dayCountYearLoc = 3; //and 4 (word)
96108
const byte dayCountMonthLoc = 5; //byte
97109
const byte dayCountDateLoc = 6; //byte
98110

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+
99115
//EEPROM locations and default values for options menu
100116
//Option numbers are 1-index, so arrays are padded to be 1-index too, for coding convenience. TODO change this
101117
//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,
107123
const word optsMax[] = {0, 2, 2, 2, 1,50, 1, 6, 4,60,999, 2,1439,1439, 2, 6, 6,1439,1439};
108124

109125

110-
////////// Other global consts and vars used in multiple sections //////////
111126

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
116127

117128
// Hardware inputs and value setting
118129
//AdaEncoder mainRot;
@@ -132,8 +143,6 @@ bool fnSetValVel; //whether it supports velocity setting (if max-min > 30)
132143
word fnSetValDate[3]; //holder for newly set date, so we can set it in 3 stages but set the RTC only once
133144

134145
// Volatile running values
135-
word alarmTime = 0; //alarm time of day TODO move these to alarmTimeLoc and alarmOnLoc
136-
bool alarmOn = 0; //alarm switch
137146
word soundRemain = 0; //alarm/timer sound timeout counter, seconds
138147
word snoozeRemain = 0; //snooze timeout counter, seconds
139148
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(){
148157
Wire.begin();
149158
initOutputs();
150159
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
152161
if(readInput(mainSel)==LOW) initEEPROM();
153162
}
154163

@@ -503,8 +512,8 @@ void initEEPROM(){
503512
ds3231.setMinute(0);
504513
ds3231.setSecond(0);
505514
//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
508517
writeEEPROM(dayCountYearLoc,2018,true);
509518
writeEEPROM(dayCountMonthLoc,1,false);
510519
writeEEPROM(dayCountDateLoc,1,false);
@@ -600,7 +609,7 @@ void checkRTC(bool force){
600609
//at 2am, check for DST change
601610
if(tod.minute()==0 && tod.hour()==2) autoDST();
602611
//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) {
604613
fnSetPg = 0; fn = fnIsTime; soundRemain = alarmDur*60;
605614
}
606615
//checkDigitCycle();
@@ -627,7 +636,7 @@ void checkRTC(bool force){
627636
//If alarm snooze has time on it, decrement and trigger beeper if we reach zero (and alarm is still on)
628637
if(snoozeRemain>0) {
629638
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; }
631640
}
632641
} //end natural second
633642

@@ -679,9 +688,9 @@ void setDST(char dir){
679688

680689
void switchAlarm(char dir){
681690
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);
685694
}
686695
}
687696

0 commit comments

Comments
 (0)