Browse Source

Alarm zetten, met message (Wordt nog niet in eeprom opgeslagen & werkt nog niet met duration)

guusvdongen 9 years ago
parent
commit
e21cc04c21
5 changed files with 125 additions and 17 deletions
  1. 90 0
      alarm.c
  2. 11 0
      alarm.h
  3. 15 5
      displayHandler.c
  4. 8 11
      main.c
  5. 1 1
      rtc.c

+ 90 - 0
alarm.c

@@ -0,0 +1,90 @@
+#define LOG_MODULE  LOG_MAIN_MODULE
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "log.h"
+#include "rtc.h"
+#include "alarm.h"
+
+struct _alarm{
+	int seconds;
+	char name[16];
+};
+
+void setAlarm(struct _tm time, char *name, int sec){
+	struct _alarm al;
+	
+	X12RtcSetAlarm(0, &time, AFLGS);
+	NutDelay(100);
+	
+	al.seconds = sec;
+	strncpy(al.name, name, sizeof(al.name));
+	
+	//Schrijf struct naar eeprom
+}
+
+int getDuration(){
+	//Haal duration op uit eeprom
+	return 10;
+}
+
+char* getName(){
+	//haal naam op uit eeprom en geef de pointer mee
+	char str[17];
+	//int x = 561;
+	//sprintf(str,"test123456789%d", x);
+	sprintf(str, "     Wekker     ");
+	return str;
+}
+
+void handleAlarm(){
+	struct _tm alarmtime;
+	
+    alarmtime = GetRTCTime();
+	
+    X12RtcGetAlarm(0,&alarmtime,AFLGS);
+	alarmtime.tm_min = (alarmtime.tm_min-79);
+	alarmtime.tm_mday = (alarmtime.tm_mday - 80);
+	alarmtime.tm_mon = (alarmtime.tm_mon - 80);
+	
+		
+	X12RtcSetAlarm(0,&alarmtime, AFLGS);
+	NutDelay(100);
+	X12RtcClearStatus(ALARM_1);
+}
+
+int checkTime(){
+	/*struct _tm ctime;
+	struct _tm atime;
+	time_t at;
+	time_t ct;
+	time_t diff;
+	
+	atime = GetRTCTime();
+	ctime = GetRTCTime();
+	
+	X12RtcGetAlarm(0,&atime,0b11111111);
+	atime.tm_min = atime.tm_min - 80;
+	atime.tm_mday = (atime.tm_mday - 80);
+	atime.tm_mon = (atime.tm_mon - 80);
+	atime.tm_year = 116;
+	
+	LogMsg_P(LOG_INFO, PSTR("at %02d-%02d-%04d || %02d-%02d-%02d"), atime.tm_mday, atime.tm_mon+1, atime.tm_year+1900, atime.tm_hour, atime.tm_min, atime.tm_sec);
+	
+	ct = mktime(&ctime);
+	at = mktime(&atime);
+	
+	at += getDuration();
+	
+	LogMsg_P(LOG_INFO, PSTR("at = %d, ct = %d"), at, ct);
+	
+	diff = ct - at;
+	
+	if (diff > 0){
+		return 1;
+	}*/
+	return 0;
+}
+

+ 11 - 0
alarm.h

@@ -0,0 +1,11 @@
+/* Alarm get/set status values */
+#define ALARM_1 	5
+#define ALARM_2		6
+
+#define AFLGS		0b11111111
+
+void handleAlaram(void);
+void setAlarm(struct _tm time, char *name, int sec);
+int getDuration(void);
+char* getName(void);
+int checkTime(void);

+ 15 - 5
displayHandler.c

@@ -1,6 +1,7 @@
 //
 // Created by Jordy Sipkema on 26/02/16.
 //
+#define LOG_MODULE  LOG_MAIN_MODULE
 
 #include <stdlib.h>
 #include <string.h>
@@ -9,7 +10,9 @@
 #include "display.h"
 #include "displayHandler.h"
 #include "ntp.h"
+#include "log.h"
 #include "rtc.h"
+#include "alarm.h"
 
 #define MONTH_OFFSET 1
 #define YEAR_OFFSET 1900
@@ -33,7 +36,7 @@ void displayDate(int line_number){
     X12RtcGetClock(time);
 
     char str[13];
-    sprintf(str, "   %02d-%02d-%04d", time->tm_mday, time->tm_mon+MONTH_OFFSET, time->tm_year+YEAR_OFFSET);
+    sprintf(str, "   %02d-%02d-%04d   ", time->tm_mday, time->tm_mon+MONTH_OFFSET, time->tm_year+YEAR_OFFSET);
 
     if(NtpIsSyncing())
         str[1] = 'S';
@@ -45,17 +48,24 @@ void displayDate(int line_number){
 void displayAlarm(int line_number, int line_numberTwo)
 {
     struct _tm alarmtime;
+	int i;
     alarmtime = GetRTCTime();
-    long flags;
+	
     X12RtcGetAlarm(0,&alarmtime,0b11111111);
     char str[12];
-    sprintf(str, "    %02d:%02d:%02d", alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec);
+    sprintf(str, "    %02d:%02d:%02d    ", alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec);
     if (line_number > -1 && line_number < 2){
         (*write_display_ptr[line_number])(str, 12);
     }
 
-    char str2[16];
-    sprintf(str2,"     Wekker     ");
+    char str2[17];
+	char *data = getName();
+	for(i = 0; i < 17; i++){
+		str2[i] = data[i];
+	}
+	//LogMsg_P(LOG_INFO, PSTR("%d"), str2);
+    //sprintf(str2,"     Wekker     ");
+	//LogMsg_P(LOG_INFO, PSTR("%d"), str2);
     if (line_numberTwo > -1 && line_numberTwo < 2){
         (*write_display_ptr[line_numberTwo])(str2, 16);
         LcdBacklightKnipperen(startLCD);

+ 8 - 11
main.c

@@ -44,6 +44,7 @@
 
 #include <time.h>
 #include "rtc.h"
+#include "alarm.h"
 #include "ntp.h"
 
 
@@ -190,20 +191,19 @@ static void SysControlMainBeat(u_char OnOff)
     }
 }
 
-void handleAlarm(){
+/*void handleAlarm(){
 	struct _tm alarmtime;
     alarmtime = GetRTCTime();
     long flags;
 	
     X12RtcGetAlarm(0,&alarmtime,0b11111111);
-	alarmtime.tm_min = (alarmtime.tm_min-80);
-	alarmtime.tm_mday = (alarmtime.tm_mday - 79);
+	alarmtime.tm_min = (alarmtime.tm_min-79);
 	
 	LogMsg_P(LOG_INFO, PSTR("Alarm : day = %02d,[%02d:%02d:%02d]"),alarmtime.tm_mday, alarmtime.tm_hour, alarmtime.tm_min, alarmtime.tm_sec);
 	
 	X12RtcSetAlarm(0,&alarmtime, 0b11111111);
 	NutDelay(100);
-}
+}*/
 
 int timer(time_t start){
 	time_t diff = time(0) - start;
@@ -320,7 +320,8 @@ int main(void)
 	
     alarmtime = GetRTCTime();
     alarmtime.tm_sec = alarmtime.tm_sec+10;
-    
+    LogMsg_P(LOG_INFO, PSTR("alarmtime %02d-%02d-%04d || %02d-%02d-%02d"), alarmtime.tm_mday, alarmtime.tm_mon+1, alarmtime.tm_year+1900, alarmtime.tm_hour, alarmtime.tm_min, alarmtime.tm_sec);
+	
     X12RtcSetAlarm(0,&alarmtime,0b11111111);
     NutDelay(100);
 	
@@ -342,16 +343,12 @@ int main(void)
 		}
         
 		
-		LogMsg_P(LOG_INFO, PSTR("voor if: %d"), X12RtcGetStatus(5));
         if(X12RtcGetStatus(5) > 0)
         {
 			displayAlarm(0,1);
-			if (KbScan() < -1){
-				LogMsg_P(LOG_INFO, PSTR("voor: %d"), X12RtcGetStatus(5));
-				X12RtcClearStatus(5);
-				NutDelay(100);
-				LogMsg_P(LOG_INFO, PSTR("na: %d"), X12RtcGetStatus(5));
+			if (KbScan() < -1 || checkTime() == 1){
 				handleAlarm();
+				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
         }
         else {

+ 1 - 1
rtc.c

@@ -352,7 +352,7 @@ int X12RtcGetStatus(u_long *sflgs)
  */
 int X12RtcClearStatus(u_long sflgs)
 {
-    rtc_status &= ~sflgs;
+    rtc_status &= sflgs;
 
     return(0);
 }