|
|
@@ -28,10 +28,11 @@ int checkAlarms(){
|
|
|
int check = 0;
|
|
|
for (i = 0; i < n; i++){
|
|
|
setState(i);
|
|
|
+ eenmaligAlarmCheck(i);
|
|
|
if (alarm[i].time.tm_year == 0){
|
|
|
alarm[i].state = 0;
|
|
|
}
|
|
|
- if (alarm[i].state == 1){
|
|
|
+ if (alarm[i].state == 1 || alarm[i].state == 4){
|
|
|
check = 1;
|
|
|
}
|
|
|
}
|
|
|
@@ -68,10 +69,14 @@ void setSnooze(int idx){
|
|
|
struct _tm ct;
|
|
|
X12RtcGetClock(&ct);
|
|
|
|
|
|
- alarm[idx].state = 2;
|
|
|
- snooze[idx].snoozeTime = ct;
|
|
|
- snooze[idx].snoozeTime.tm_min += alarm[idx].snooze;
|
|
|
- stopStream();
|
|
|
+ if (alarm[idx].state < 3){
|
|
|
+ alarm[idx].state = 2;
|
|
|
+ snooze[idx].snoozeTime = ct;
|
|
|
+ snooze[idx].snoozeTime.tm_min += alarm[idx].snooze;
|
|
|
+ stopStream();
|
|
|
+ LcdBackLight(LCD_BACKLIGHT_OFF);
|
|
|
+ stopStream();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int daysInMonth(int m, int y) {
|
|
|
@@ -118,22 +123,26 @@ void setState(int idx){
|
|
|
struct _tm ct;
|
|
|
X12RtcGetClock(&ct);
|
|
|
|
|
|
- if (alarm[idx].state == 0){
|
|
|
+ //Set snooze time for snooze alarm
|
|
|
+ if (alarm[idx].state == 0 && alarm[idx].state < 3){
|
|
|
snooze[idx].snoozeTime = alarm[idx].time;
|
|
|
AddSnoozeMinutes(idx,1);
|
|
|
}
|
|
|
|
|
|
- if (compareTime(ct, alarm[idx].time) >= 1 && alarm[idx].time.tm_year != 0 && alarm[idx].state != 2){
|
|
|
+ //Check if alarm has to go off for snooze alarm
|
|
|
+ if (compareTime(ct, alarm[idx].time) >= 1 && alarm[idx].time.tm_year != 0 && alarm[idx].state != 2 && alarm[idx].state < 3){
|
|
|
alarm[idx].state = 1;
|
|
|
- } else if (alarm[idx].state != 2){
|
|
|
+ } else if (alarm[idx].state != 2 && alarm[idx].state < 3){
|
|
|
alarm[idx].state = 0;
|
|
|
}
|
|
|
|
|
|
- if (compareTime(alarm[idx].time,snooze[idx].snoozeTime) >= 1){
|
|
|
+ //Check if alarm has to snooze
|
|
|
+ if (compareTime(alarm[idx].time,snooze[idx].snoozeTime) >= 1 && alarm[idx].state < 3){
|
|
|
alarm[idx].state = 2;
|
|
|
}
|
|
|
|
|
|
- if (alarm[idx].state == 1 && compareTime(ct, snooze[idx].snoozeTime) >= 1){
|
|
|
+ //Check if alarm has to snooze
|
|
|
+ if (alarm[idx].state == 1 && compareTime(ct, snooze[idx].snoozeTime) >= 1 && alarm[idx].state < 3){
|
|
|
alarm[idx].state = 2;
|
|
|
snooze[idx].snoozeTime = ct;
|
|
|
AddSnoozeMinutes(idx, alarm[idx].snooze);
|
|
|
@@ -141,10 +150,12 @@ void setState(int idx){
|
|
|
stopStream();
|
|
|
}
|
|
|
|
|
|
- if (alarm[idx].state == 2 && compareTime(ct, snooze[idx].snoozeTime) >= 1){
|
|
|
+ //Check if snooze is done, and alarm goes off again
|
|
|
+ if (alarm[idx].state == 2 && compareTime(ct, snooze[idx].snoozeTime) >= 1 && alarm[idx].state < 3){
|
|
|
alarm[idx].state = 1;
|
|
|
AddSnoozeMinutes(idx, 1);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/*void getAlarm(struct _alarm *am){
|
|
|
@@ -167,6 +178,39 @@ void setAlarm(struct _tm time, char* name, char* ip, u_short port, char* url, in
|
|
|
alarm[idx].state = 0;
|
|
|
}
|
|
|
|
|
|
+void eenmaligAlarm(struct _tm time, char* name, char* ip, u_short port, char* url, int snooze, int id, int idx){
|
|
|
+ alarm[idx].time = time;
|
|
|
+
|
|
|
+ strncpy(alarm[idx].name, name, sizeof(alarm[idx].name));
|
|
|
+ strncpy(alarm[idx].ip, ip, sizeof(alarm[idx].ip));
|
|
|
+ alarm[idx].port = port;
|
|
|
+ strncpy(alarm[idx].url, url, sizeof(alarm[idx].url));
|
|
|
+
|
|
|
+ alarm[idx].id = id;
|
|
|
+ alarm[idx].state = 3;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//Checks if there is an alarm that has to go off
|
|
|
+void eenmaligAlarmCheck(int idx){
|
|
|
+ struct _tm ct;
|
|
|
+ X12RtcGetClock(&ct);
|
|
|
+
|
|
|
+ //Check if alarm goes off, compares the RTC time to the alarm time
|
|
|
+ if (compareTime(ct, alarm[idx].time) >= 1 && alarm[idx].time.tm_year != 0 && alarm[idx].state == 3){
|
|
|
+ alarm[idx].state = 4;
|
|
|
+ snooze[idx].snoozeTime = ct;
|
|
|
+ AddSnoozeMinutes(idx,2);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Delete alarm after 30 minutes, compares the RTC time to the snooze
|
|
|
+ if (compareTime(ct, snooze[idx].snoozeTime) >= 1 && alarm[idx].state == 4){
|
|
|
+ deleteAlarm(idx);
|
|
|
+ LcdBackLight(LCD_BACKLIGHT_OFF);
|
|
|
+ stopStream();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void deleteAlarm(int idx){
|
|
|
struct _tm tm;
|
|
|
@@ -179,9 +223,12 @@ void deleteAlarm(int idx){
|
|
|
}
|
|
|
|
|
|
void handleAlarm(int idx){
|
|
|
- alarm[idx].state = 0;
|
|
|
- alarm[idx].time.tm_mday += 1;
|
|
|
- printf("state is %d \n",alarm[idx].state);
|
|
|
+ if (alarm[idx].state < 3){
|
|
|
+ alarm[idx].state = 0;
|
|
|
+ alarm[idx].time.tm_mday += 1;
|
|
|
+ } else if (alarm[idx].state == 4){
|
|
|
+ deleteAlarm(idx);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int compareTime(tm t1,tm t2){
|