소스 검색

LcdBackLight undefined reference

guusvdongen 9 년 전
부모
커밋
a7da0e46d2
2개의 변경된 파일120개의 추가작업 그리고 32개의 파일을 삭제
  1. 81 17
      alarm.c
  2. 39 15
      main.c

+ 81 - 17
alarm.c

@@ -8,14 +8,14 @@
 #include "log.h"
 #include "rtc.h"
 #include "alarm.h"
+#include "display.h"
 
 #define n 2
 
 
 struct _snooze
 {
-	struct _tm snoozeStart;
-	struct _tm snoozeEnd;
+	struct _tm snoozeTime;
 };
 
 struct _alarm alarm[n];
@@ -60,26 +60,85 @@ int maxAlarms(){
 	return n;
 }
 
+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;
+}
+
+int daysInMonth(int m, int y) {
+    if(m == 2 && isLeapYear(y))
+        return 29 + (int)(m + floor(m/8)) % 2 + 2 % m + 2 * floor(1/m);
+    return 28 + (int)(m + floor(m/8)) % 2 + 2 % m + 2 * floor(1/m);
+}
+
+int daysInYear(int y){
+    if(isLeapYear(y))
+        return 366;
+    return 365;
+}
+
+int isLeapYear(int y){
+    return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
+}
+
+
+void AddSnoozeMinutes(int idx, int minutes){
+	if (snooze[idx].snoozeTime.tm_min + minutes >= 60){ //Checks if minutes is >= 60 else minute
+		snooze[idx].snoozeTime.tm_hour += 1;
+		snooze[idx].snoozeTime.tm_min = ((snooze[idx].snoozeTime.tm_min + minutes) % 60);
+		if (snooze[idx].snoozeTime.tm_hour >= 24){ //Checks if hours is >= 24
+			snooze[idx].snoozeTime.tm_hour = 0;
+			if ((snooze[idx].snoozeTime.tm_mday + 1) <= daysInMonth((snooze[idx].snoozeTime.tm_mon+1), (snooze[idx].snoozeTime.tm_year+1900))){ //Checks if day+1 smaller or even is to the amount of days in the month
+				snooze[idx].snoozeTime.tm_mday += 1;
+			} else { //If the days+1 is bigger than the amount of days in the month, day = 1 & month is + 1
+				snooze[idx].snoozeTime.tm_mday = 1;
+				if (snooze[idx].snoozeTime.tm_mon + 1 > 11){//If month+1 is bigger than 11 (month is 0-11) then month = 0 & year + 1
+					snooze[idx].snoozeTime.tm_mon = 0;
+					snooze[idx].snoozeTime.tm_year += 1;
+				} else {
+					snooze[idx].snoozeTime.tm_mon += 1;
+				}
+			}
+		}
+	} else {
+		snooze[idx].snoozeTime.tm_min += minutes;
+	}
+}
+
 void setState(int idx){
 	struct _tm ct;
 	X12RtcGetClock(&ct);
 	
-	if (compareTime(ct, alarm[idx].time) == 1 && alarm[idx].time.tm_year != 0){
+	if (alarm[idx].state == 0){
+		snooze[idx].snoozeTime = alarm[idx].time;
+		AddSnoozeMinutes(idx,1);
+	}
+	
+	if (NtpCompareTime(ct, alarm[idx].time) == 1 && alarm[idx].time.tm_year != 0 && alarm[idx].state != 2){
 		alarm[idx].state = 1;
-	} else {
+	} else if (alarm[idx].state != 2){
 		alarm[idx].state = 0;
 	}
 	
-	/*if (compareTime(alarm[idx].time,snooze[idx].snoozeStart)){
+	if (NtpCompareTime(alarm[idx].time,snooze[idx].snoozeTime)){
 		alarm[idx].state = 2;
 	}
 	
-	if (alarm[idx].state == 2){
-		if (compareTime(alarm[idx].time, snooze[idx].snoozeEnd)){
-			snooze[idx].snoozeStart.tm_min += alarm[idx].snooze + 1;
-			snooze[idx].snoozeEnd.tm_min += alarm[idx].snooze + 1;
-		}
-	}*/
+	if (alarm[idx].state == 1 && compareTime(ct, snooze[idx].snoozeTime) == 1){
+		alarm[idx].state = 2;
+		snooze[idx].snoozeTime = ct;
+		AddSnoozeMinutes(idx, alarm[idx].snooze);
+		LcdBackLight(LCD_BACKLIGHT_OFF);
+	}
+	
+	if (alarm[idx].state == 2 && compareTime(ct, snooze[idx].snoozeTime) == 1){
+		alarm[idx].state = 1;
+		AddSnoozeMinutes(idx, 1);
+	}
 }
 
 /*void getAlarm(struct _alarm *am){
@@ -100,11 +159,6 @@ void setAlarm(struct _tm time, char* name, char* ip, u_short port, char* url, in
 	alarm[idx].snooze = snooze;
 	alarm[idx].id = id;
 	alarm[idx].state = 0;
-
-	//snooze[idx].snoozeStart = time;
-	//snooze[idx].snoozeEnd = time;
-	//snooze[idx].snoozeStart += 1;
-	//snooze[idx].snoozeEnd += (snooze +1);
 }
 
 
@@ -119,7 +173,17 @@ void deleteAlarm(int idx){
 }
 
 void handleAlarm(int idx){
-	alarm[idx].time.tm_mday = alarm[idx].time.tm_mday + 1;
+		if ((alarm[idx].time.tm_mday + 1) <= daysInMonth((alarm[idx].time.tm_mon+1), (alarm[idx].time.tm_year+1900))){ 
+		alarm[idx].time.tm_mday += 1;
+	} else {
+		alarm[idx].time.tm_mday = 1;
+		if ((alarm[idx].time.tm_mon + 1) > 11){					
+			alarm[idx].time.tm_mon = 0;
+			alarm[idx].time.tm_year += 1;
+		} else {
+			alarm[idx].time.tm_mon += 1;
+		}
+	}
 	alarm[idx].state = 0;
 }
 

+ 39 - 15
main.c

@@ -183,6 +183,7 @@ static void SysControlMainBeat(u_char OnOff)
 /*-------------------------------------------------------------------------*/
 int isAlarmSyncing;
 int initialized;
+int running = 0;
 
 
 /*-------------------------------------------------------------------------*/
@@ -244,8 +245,18 @@ int timer(time_t start){
     return diff;
 }
 
+long timerStruct(struct _tm s){
+	struct _tm ct;
+	X12RtcGetClock(&ct);
+	
+	long stime = (s.tm_hour * 3600) + (s.tm_min * 60) + s.tm_sec;
+	long ctime = (ct.tm_hour * 3600) + (ct.tm_min * 60) + ct.tm_sec;
+	
+	return ctime - stime;
+}
+
 int checkOffPressed(){
-    if (KbGetKey() == KEY_POWER){
+    if (KbGetKey() == KEY_UNDEFINED){
         LcdBackLight(LCD_BACKLIGHT_ON);
         return 1;
     } else {
@@ -259,11 +270,10 @@ int main(void)
 {
 	initialized = 0;
     int VOL2;
-    time_t start;
+    struct _tm timeCheck;
+	struct _tm start;
 	int idx = 0;
 
-	int running;
-
     WatchDogDisable();
 
     NutDelay(100);
@@ -286,7 +296,7 @@ int main(void)
 
     VsPlayerInit();
 
-    LcdBackLight(LCD_BACKLIGHT_ON);
+ 
     NtpInit();
 
     NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
@@ -318,23 +328,33 @@ int main(void)
 /*    if(hasNetworkConnection() == true){
         playStream("145.58.53.152", 80, "/3fm-bb-mp3");
     }*/
-    start = time(0) - 10;
     unsigned char VOL = 64;
-
-    running = 1;
+	
+	X12RtcGetClock(&timeCheck);
+	X12RtcGetClock(&start);
+	LcdBackLight(LCD_BACKLIGHT_OFF);
 
     for (;;)
     {
+		
+		if (timerStruct(start) < 0){
+			X12RtcGetClock(&start);
+		}
+		
+		if (timerStruct(timeCheck) < 0){
+			X12RtcGetClock(&timeCheck);
+		}
+		
 		//Check if a button is pressed
 		if (checkOffPressed() == 1){
-			start = time(0);
+			X12RtcGetClock(&start);
 			running = 1;
-            LcdBacklightKnipperen(startLCD);
+            LcdBacklight(LCD_BACKLIGHT_ON);
 		}
 
 		//Check if background LED is on, and compare to timer
 		if (running == 1){
-			if (timer(start) >= 10){
+			if (timerStruct(start) >= 10 || running > 1){
 				running = 0;
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
@@ -344,7 +364,7 @@ int main(void)
         if(KbGetKey() == KEY_DOWN)
         {
             NutSleep(150);
-            start = time(0);
+             X12RtcGetClock(&timeCheck);
             if(VOL > 8){
                 VOL -= 8;
                 VsSetVolume (128-VOL, 128-VOL);
@@ -354,14 +374,14 @@ int main(void)
         else if(KbGetKey() == KEY_UP)
         {
             NutSleep(150);
-            start = time(0);
+             X12RtcGetClock(&timeCheck);
             if(VOL < 128) {
                 VOL += 8;
                 VsSetVolume(128-VOL, 128-VOL);
                 displayVolume(VOL/8);
             }
         }
-        else if(timer(start) >= 5 && checkAlarms() == 1)
+        else if(timerStruct(timeCheck) >= 5 && checkAlarms() == 1)
         {
 			for (idx = 0; idx < 2; idx++){
 				if (getState(idx) == 1){
@@ -371,12 +391,16 @@ int main(void)
 						handleAlarm(idx);
 						NutDelay(50);
 						LcdBackLight(LCD_BACKLIGHT_OFF);
+                        stopStream();
+					} else if (KbGetKey() == KEY_01 || KbGetKey() == KEY_02 || KbGetKey() == KEY_03 || KbGetKey() == KEY_04 || KbGetKey() == KEY_05 || KbGetKey() == KEY_ALT){
+						setSnooze(idx);
+						LcdBackLight(LCD_BACKLIGHT_OFF);
                         stopStream();
 					}
 				}
 			}
 		}
-		else if (timer(start) >= 5){
+		else if (timerStruct(timeCheck) >= 5){
             displayTime(0);
             displayDate(1);
 		}