void AlarmPurgeAll(void) { Int16 j; Int16 stopAt = numAlarms; for (j=0; j<stopAt; j++) ClearAlarm(0); }
static Boolean AckAlarm(Int16 alarmID) { alarm[alarmID].ack = true; if (alarm[alarmID].level == alarmMessage || alarm[alarmID].level == alarmInfo) { ClearAlarm(alarmID); return true; } return false; }
void AlarmSetCondition(MessageDialogDataType *md, AlarmLevelType level) { Int16 j; /* * check existing alarms * */ LOGENTRY; for (j=0; j< numAlarms; j++) { if (StrCompare(md->message, alarm[j].data->message) == 0) { /* * found the same alarm, check if it's being cleared or if we should * increase the alarm level * */ LOGTAG("Found existing alarm"); LOGSTR(alarm[j].data->message); if (level == alarmOff) { /* * clear the alarm * */ ClearAlarm(j); MessageDialogDataFree(md); LOGEXIT; return; } /* * increase alarm level? * */ if (alarm[j].level < level) { alarm[j].level = level; alarm[j].time = PFGetSeconds(); alarm[j].returnedCounter = MAX_RETURNS; } MessageDialogDataFree(md); LOGEXIT; return; } } /* * the code above should have removed the existing alarm condition * if level == alarmOff, so just return from here * */ if (level == alarmOff) { MessageDialogDataFree(md); LOGEXIT; return; } /* * new alarm * */ ModErrThrowIf(numAlarms == MAX_ALARMS); alarm[numAlarms].level = level; alarm[numAlarms].data = md; alarm[numAlarms].ack = false; alarm[numAlarms].time = PFGetSeconds(); alarm[numAlarms].returnedCounter = MAX_RETURNS; numAlarms++; LOGEXIT; }
/*! * \brief thread that checks the alarms every 10 seconds * * \author Matthijs */ THREAD(AlarmThread, args) { //time struct datetime can't be found when placed in main.h tm datetime; u_long flags; X12RtcGetClock(&datetime); for(;;) { int succes = X12RtcGetStatus(&flags); int i; for(i = 0; i <=10; i++) { NutSleep(1000); } //power fail if(flags == 0) { //printf("\n ========== Power Fail ========== \n"); X12RtcClearStatus(0); } //alarm A if(flags == 32) { printf("\n ========== Alarm 0 =========== \n"); //get current alarm time to compare to the weekendtime, if weekendtime is //equal to currentAlarm and the day of the week is friday. The alarm should //not go off. tm currentAlarm; int iets = 0; X12RtcGetAlarm(0, ¤tAlarm, &iets); int alarmASeconds = 0; alarmASeconds = (currentAlarm.tm_hour * 360) + (currentAlarm.tm_min * 6) + (currentAlarm.tm_sec / 10); int weekendtimeSeconds = 0; weekendtimeSeconds = (weekendtime.hour * 360) + (weekendtime.minute * 6) + (weekendtime.second / 10); printf("\nalarmASeconds: %d, weekendtimeSeconds: %d", alarmASeconds, weekendtimeSeconds); if((alarmASeconds != weekendtimeSeconds) && checkWeekend() == 1) { printf("\nHet is VRIJDAG!!! alarm is niet gelijk aan de weekendtijd en moet dus nog geset worden\n SOUND IS PLAYING"); //SoundA(); startSnoozeThreadA(); } else if(((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 3))) { printf("\nalarm is niet gelijk aan de weekendtijd en het is weekend, dus set"); } else if(((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 3))) { printf("\nalarm is gelijk aan de weekendtijd en het is weekend,\n SOUND IS PLAYING"); //SoundA(); startSnoozeThreadA(); //if the alarm goes off and it is sunday set the alarm back to its //original settings if(checkWeekend() == 3) { printf("het is blijkbaar zondag dus terug naar doordeweekse tijd"); setAlarmA(alarmA.tm_hour, alarmA.tm_min, alarmA.tm_sec); } } else if(checkWeekend() == 0) { printf("\nhet is doordeweeks,\nSOUND IS PLAYING"); startSnoozeThreadA(); //SoundA(); } //else //{ // printf("weekendAlarm gaat af!!!"); //} //when checkWeekend returns 1(Friday) or 2(Saturday) it means that it //will be weekend the next day. Therefore we set the alarm to the weekend //settings. Problem is that most likely the alarm in the weekends will go //off later then it would during the week. This problem is solved underneath //the if(checkWeekend() == 3){}. int currentTime = (datetime.tm_hour * 360) + (datetime.tm_min * 6) + (datetime.tm_sec / 10); if(checkWeekend() > 0 && checkWeekend() < 3) { printf("alarmA set to weekend time"); setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second); } else if(checkWeekend() == 3 && (currentTime <= weekendtimeSeconds)) { setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second); } X12RtcClearStatus(32); } //alarm B if(flags == 64) { printf("\n ============ Alarm 1================== \n"); startSnoozeThreadB(); ClearAlarm('b'); X12RtcClearStatus(64); alarmBArray[currentAlarm.index].set = 0; alarmBStruct newSet = checkFirst(); X12RtcSetAlarm(1, &newSet.timeSet, 31); currentAlarm = newSet; } //both alarms if(flags == 96) { //kijkt of alarm a of b nog niet heeft geluid, en speelt die dan printf("\n ========== Alarm 0 en 1 ========= \n"); //kijkt welke van de 2 nog niet is afgegaan en speelt die dan nog af SoundA(); X12RtcClearStatus(32); SoundB(); X12RtcClearStatus(64); } if(succes == 0) { //succes } else { //error } } }