Skip to content

Commit

Permalink
Merge pull request #47 from JeaneLG/forkInt
Browse files Browse the repository at this point in the history
Bug Fix: alarm time 2 is not executed if it is before alarm time 1 on…
No Time for test but what i see looks good.
BIG THX to JeaneLG https://github.com/JeaneLG
  • Loading branch information
beabel authored May 14, 2024
2 parents 46335f4 + 47bca52 commit aa1f151
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions radiowecker/radiowecker.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ typedef struct {
uint8_t enabled;//flag to activate the station
} Station;

#define STATIONS 30 //number of stations in the list
#define STATIONS 30 // number of stations in the list
#define MINUTES_PER_DAY 1440 // minutes a day has

//gloabal variables
Station stationlist[STATIONS]; //list of available stations
Expand Down Expand Up @@ -81,27 +82,27 @@ void findNextAlarm() {
uint8_t mask;
if (getLocalTime(&ti)) { //get current date and time
wd = weekday; //variable to iterate over weekdays starting with today
alarmday = 8; //alarmday = 8 means no alarm
alarmday = 8; //alarmday = 8 means no alarm
alarmtime = MINUTES_PER_DAY + 1; // set alarmtime to a value higher it could have
mask = 1 << wd; //mask to filter weekday to be tested
//test if alarm settings 1 matchs
if ((alarmday == 8) && ((alarmday1 & mask) != 0) && (alarm1 > minutes))
if (((alarmday1 & mask) != 0) && (alarm1 > minutes))
{ alarmtime = alarm1; alarmday = wd;}
//test if alarm settings 2 matchs
if ((alarmday == 8) && ((alarmday2 & mask) != 0) && (alarm2 > minutes))
//test if alarm settings 2 matchs and if the alarm is before a possibly set alarm 1
if (((alarmday2 & mask) != 0) && (alarm2 > minutes) && (alarmtime > alarm2))
{ alarmtime = alarm2; alarmday = wd;}
if (alarmday == 8) { //if no alarm continue search
do {
wd++; //next weekday
if (wd > 7) wd = 0;
mask = 1 << wd;
//test if alarm settings 1 matchs
if ((alarmday == 8) && ((alarmday1 & mask) != 0) ) { alarmtime = alarm1; alarmday = wd;}
//test if alarm settings 1 matchs
if ((alarmday == 8) && ((alarmday2 & mask) != 0) ) { alarmtime = alarm2; alarmday = wd;}
if ((alarmday1 & mask) != 0) { alarmtime = alarm1; alarmday = wd;}
//test if alarm settings 2 matchs
if (((alarmday2 & mask) != 0) && (alarmtime > alarm2)) { alarmtime = alarm2; alarmday = wd;}

} while ((alarmday == 8) && (wd != weekday)); //continue until an valid alarm was found or a week is over
}

Serial.printf("Next alarm %i on %i\n",alarmtime,alarmday);
}
}
Expand Down

0 comments on commit aa1f151

Please sign in to comment.