Переглянути джерело

Merge branch 'Alarm_weergeven' into HttpRadioCommunicatie

Aareschluchtje 9 роки тому
батько
коміт
af8d1dfd44
8 змінених файлів з 249 додано та 23 видалено
  1. 90 0
      alarm.c
  2. 11 0
      alarm.h
  3. 49 13
      display.c
  4. 2 1
      display.h
  5. 34 2
      displayHandler.c
  6. 1 1
      displayHandler.h
  7. 61 5
      main.c
  8. 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);

+ 49 - 13
display.c

@@ -26,7 +26,7 @@
 #include "portio.h"
 #include "display.h"
 #include "log.h"
-
+#include <time.h>
 /*-------------------------------------------------------------------------*/
 /* local defines                                                           */
 /*-------------------------------------------------------------------------*/
@@ -42,6 +42,18 @@ static void LcdWriteByte(u_char, u_char);
 static void LcdWriteNibble(u_char, u_char);
 static void LcdWaitBusy(void);
 
+int timerLCD(u_char Mode){
+    time_t Start;
+    if(Mode == startLCD)
+    {
+            time_t diff = time(0) - Start;
+            return diff;
+    }
+    else if(Mode == stopLCD)
+    {
+        Start = time(0);
+    }
+}
 /*!
  * \addtogroup Display
  */
@@ -52,11 +64,11 @@ static void LcdWaitBusy(void);
 /*                         start of code                                   */
 /*-------------------------------------------------------------------------*/
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief control backlight
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 void LcdBackLight(u_char Mode)
 {
     if (Mode==LCD_BACKLIGHT_ON)
@@ -70,7 +82,31 @@ void LcdBackLight(u_char Mode)
     }
 }
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+
+/* ����������������������������������������������������������������������� */
+
+/*
+ * Lcdbacklight knipperen
+ */
+
+void LcdBacklightKnipperen(u_char Mode)
+{
+    time_t Start;
+    time_t Stop;
+    if (Mode==startLCD)
+    {
+        sbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn on backlight
+        timer(Start);
+    }
+    if (Mode==stopLCD)
+    {
+        cbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn off backlight
+        timer(Stop);
+    }
+}
+/*
+
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief Write a single character on the LCD
  *
@@ -78,14 +114,14 @@ void LcdBackLight(u_char Mode)
  *
  * \param LcdChar character to write
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 void LcdChar(char MyChar)
 {
     LcdWriteByte(WRITE_DATA, MyChar);
 }
 
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief Low-level initialisation function of the LCD-controller
  *
@@ -94,7 +130,7 @@ void LcdChar(char MyChar)
  *           1 line dislay, 10 dots high characters
  *
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
  void LcdLowLevelInit()
 {
     u_char i;
@@ -127,7 +163,7 @@ void LcdChar(char MyChar)
 }
 
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief Low-level routine to write a byte to LCD-controller
  *
@@ -139,7 +175,7 @@ void LcdChar(char MyChar)
  * \param LcdByte byte to write
  *
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 static void LcdWriteByte(u_char CtrlState, u_char LcdByte)
 {
     LcdWaitBusy();                      // see if the controller is ready to receive next byte
@@ -148,7 +184,7 @@ static void LcdWriteByte(u_char CtrlState, u_char LcdByte)
 
 }
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief Low-level routine to write a nibble to LCD-controller
  *
@@ -160,7 +196,7 @@ static void LcdWriteByte(u_char CtrlState, u_char LcdByte)
  * \param LcdNibble nibble to write (upper 4 bits in this byte
  *
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 static void LcdWriteNibble(u_char CtrlState, u_char LcdNibble)
 {
     outp((inp(LCD_DATA_DDR) & 0x0F) | 0xF0, LCD_DATA_DDR);  // set data-port to output again
@@ -186,7 +222,7 @@ static void LcdWriteNibble(u_char CtrlState, u_char LcdNibble)
     outp((inp(LCD_DATA_PORT) & 0x0F) | 0xF0, LCD_DATA_PORT);  // enable pull-ups in data-port
 }
 
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 /*!
  * \brief Low-level routine to see if the controller is ready to receive
  *
@@ -194,7 +230,7 @@ static void LcdWriteNibble(u_char CtrlState, u_char LcdNibble)
  * has become '0'. If a '0' is detected on bit 7 the function returns.
  *
  */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/* ����������������������������������������������������������������������� */
 static void LcdWaitBusy()
 {
     u_char Busy = 1;

+ 2 - 1
display.h

@@ -30,7 +30,8 @@
 
 #define LCD_BACKLIGHT_ON            1
 #define LCD_BACKLIGHT_OFF           0
-
+#define startLCD        1
+#define stopLCD          0
 #define ALL_ZERO          			0x00      // 0000 0000 B
 #define WRITE_COMMAND     			0x02      // 0000 0010 B
 #define WRITE_DATA        			0x03      // 0000 0011 B

+ 34 - 2
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
@@ -37,11 +40,13 @@ void displayDate(int line_number){
     X12RtcGetClock(time);
 
     char str[13];
+
     if (NtpTimeIsValid()){
-        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);
     }else {
-        sprintf(str, "   ??-??-????");
+        sprintf(str, "   ??-??-????   ");
     }
+>>>>>>> origin/developer
 
     if(NtpIsSyncing())
         str[1] = 'S';
@@ -51,5 +56,32 @@ void displayDate(int line_number){
     }
 }
 
+void displayAlarm(int line_number, int line_numberTwo)
+{
+    struct _tm alarmtime;
+	int i;
+    alarmtime = GetRTCTime();
+	
+    X12RtcGetAlarm(0,&alarmtime,0b11111111);
+    char str[12];
+    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[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);
+    }
+}
+
 
 

+ 1 - 1
displayHandler.h

@@ -7,5 +7,5 @@
 
 void displayTime(int);
 void displayDate(int);
-
+void displayAlarm(int line_number, int line_numberTwo);
 #endif //MUTLI_OS_BUILD_DISPLAYHANDLER_H

+ 61 - 5
main.c

@@ -44,6 +44,7 @@
 
 #include <time.h>
 #include "rtc.h"
+#include "alarm.h"
 #include "ntp.h"
 
 
@@ -165,7 +166,6 @@ void SysInitIO(void)
      */
     outp(0x18, DDRG);
 }
-
 /* ����������������������������������������������������������������������� */
 /*!
  * \brief Starts or stops the 4.44 msec mainbeat of the system
@@ -191,6 +191,20 @@ static void SysControlMainBeat(u_char OnOff)
     }
 }
 
+/*void handleAlarm(){
+	struct _tm alarmtime;
+    alarmtime = GetRTCTime();
+    long flags;
+	
+    X12RtcGetAlarm(0,&alarmtime,0b11111111);
+	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;
 	return diff;
@@ -205,6 +219,23 @@ int checkOffPressed(){
 	}
 }
 
+/*void displayAlarm()
+{
+    struct _tm alarmtime;
+    alarmtime = GetRTCTime();
+    long flags;
+    X12RtcGetAlarm(0,&alarmtime,0b11111111);
+    NutDelay(100);
+    char str[12];
+    sprintf(str, "    %02d:%02d:%02d", alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec);
+    LogMsg_P(LOG_INFO, PSTR("Alarm : [%02d:%02d:%02d]"), alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec );
+    LcdArrayLineOne(str,12);
+
+    char str2[6];
+    sprintf(str2,"Wekker");
+    LcdArrayLineTwo(str2,6);
+    LcdBacklightKnipperen(startLCD);
+}*/
 /* ����������������������������������������������������������������������� */
 /*!
  * \brief Main entry of the SIR firmware
@@ -232,7 +263,14 @@ int main(void)
 {
 	time_t start;
 	int running = 0;
-
+	/* 
+	 * Kroeske: time struct uit nut/os time.h (http://www.ethernut.de/api/time_8h-source.html)
+	 *
+	 */
+	struct _tm alarmtime;
+	/*
+	 * Kroeske: Ook kan 'struct _tm gmt' Zie bovenstaande link
+	 */
     /*
      *  First disable the watchdog
      */
@@ -290,12 +328,20 @@ int main(void)
 	/* Enable global interrupts */
 	sei();
 	
+    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);
+	
     for (;;)
     {		
 		//Check if a button is pressed
 		if (checkOffPressed() == 1){
 			start = time(0);
 			running = 1;
+            LcdBacklightKnipperen(startLCD);
 		}
 		
 		//Check if background LED is on, and compare to timer
@@ -305,10 +351,20 @@ int main(void)
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
 		}
-
-        displayDate(0);
-		displayTime(1);
+        
 		
+        if(X12RtcGetStatus(5) > 0)
+        {
+			displayAlarm(0,1);
+			if (KbScan() < -1 || checkTime() == 1){
+				handleAlarm();
+				LcdBackLight(LCD_BACKLIGHT_OFF);
+			}
+        }
+        else {
+            displayTime(0);
+            displayDate(1);
+        }
         WatchDogRestart();
     }
 

+ 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);
 }