alarm.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #define LOG_MODULE LOG_MAIN_MODULE
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "log.h"
  6. #include "rtc.h"
  7. #include "alarm.h"
  8. struct _alarm{
  9. int seconds;
  10. char name[16];
  11. };
  12. void setAlarm(struct _tm time, char *name, int sec){
  13. struct _alarm al;
  14. X12RtcSetAlarm(0, &time, AFLGS);
  15. NutDelay(100);
  16. al.seconds = sec;
  17. strncpy(al.name, name, sizeof(al.name));
  18. //Schrijf struct naar eeprom
  19. }
  20. int getDuration(){
  21. //Haal duration op uit eeprom
  22. return 10;
  23. }
  24. char* getName(){
  25. //haal naam op uit eeprom en geef de pointer mee
  26. char str[17];
  27. //int x = 561;
  28. //sprintf(str,"test123456789%d", x);
  29. sprintf(str, " Wekker ");
  30. return str;
  31. }
  32. void handleAlarm(){
  33. struct _tm alarmtime;
  34. alarmtime = GetRTCTime();
  35. X12RtcGetAlarm(0,&alarmtime,AFLGS);
  36. alarmtime.tm_min = (alarmtime.tm_min-79);
  37. alarmtime.tm_mday = (alarmtime.tm_mday - 80);
  38. alarmtime.tm_mon = (alarmtime.tm_mon - 80);
  39. X12RtcSetAlarm(0,&alarmtime, AFLGS);
  40. NutDelay(100);
  41. X12RtcClearStatus(ALARM_1);
  42. }
  43. int checkTime(){
  44. /*struct _tm ctime;
  45. struct _tm atime;
  46. time_t at;
  47. time_t ct;
  48. time_t diff;
  49. atime = GetRTCTime();
  50. ctime = GetRTCTime();
  51. X12RtcGetAlarm(0,&atime,0b11111111);
  52. atime.tm_min = atime.tm_min - 80;
  53. atime.tm_mday = (atime.tm_mday - 80);
  54. atime.tm_mon = (atime.tm_mon - 80);
  55. atime.tm_year = 116;
  56. 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);
  57. ct = mktime(&ctime);
  58. at = mktime(&atime);
  59. at += getDuration();
  60. LogMsg_P(LOG_INFO, PSTR("at = %d, ct = %d"), at, ct);
  61. diff = ct - at;
  62. if (diff > 0){
  63. return 1;
  64. }*/
  65. return 0;
  66. }