gotosleep.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <assert.h>
  4. #include <sys/thread.h>
  5. #include <sys/timer.h>
  6. #include <sys/version.h>
  7. #include <dev/irqreg.h>
  8. #include "log.h"
  9. #include "rtc.h"
  10. #include "alarm.h"
  11. #include "display.h"
  12. #include "httpstream.h"
  13. #include "mp3stream.h"
  14. #include "gotosleep.h"
  15. struct _fallSleep
  16. {
  17. struct _tm sleepTime;
  18. };
  19. struct _tm count;
  20. int i = 1;
  21. int x = 0;
  22. void setSleep(void)
  23. {
  24. X12RtcGetClock(&count);
  25. fallSleep.sleepTime = count;
  26. AddMinutes(60);
  27. changeChanel();
  28. x = fallSleep.sleepTime.tm_min;
  29. return 1;
  30. }
  31. void AddMinutes(int minutes){
  32. if (fallSleep.sleepTime.tm_min + minutes >= 60){ //Checks if minutes is >= 60 else minute
  33. fallSleep.sleepTime.tm_hour += 1;
  34. fallSleep.sleepTime.tm_min = ((snooze[idx].snoozeTime.tm_min + minutes) % 60);
  35. if (fallSleep.sleepTime.tm_hour >= 24){ //Checks if hours is >= 24
  36. fallSleep.sleepTime.tm_hour = 0;
  37. if ((fallSleep.sleepTime.tm_mday + 1) <= daysInMonth((fallSleep.sleepTime..tm_mon+1), (fallSleep.sleepTime.tm_year+1900))){ //Checks if day+1 smaller or even is to the amount of days in the month
  38. fallSleep.sleepTime.tm_mday += 1;
  39. } else { //If the days+1 is bigger than the amount of days in the month, day = 1 & month is + 1
  40. fallSleep.sleepTime.tm_mday = 1;
  41. if (fallSleep.sleepTime.tm_mon + 1 > 11){//If month+1 is bigger than 11 (month is 0-11) then month = 0 & year + 1
  42. fallSleep.sleepTime.tm_mon = 0;
  43. fallSleep.sleepTime.tm_year += 1;
  44. } else {
  45. fallSleep.sleepTime.tm_mon += 1;
  46. }
  47. }
  48. }
  49. } else {
  50. fallSleep.sleepTime.tm_min += minutes;
  51. }
  52. }
  53. void checkSleep(void)
  54. {
  55. X12RtcGetClock(&count);
  56. if(compareTime(count, fallSleep.sleepTime) == 0){
  57. killPlayerThread();
  58. }
  59. if(compareTime(count, fallSleep.sleepTime) == 5 && fallSleep.sleepTime.tm_min == x){
  60. volumeDown();
  61. if (x >= 60){
  62. x = 0;
  63. }
  64. x += 2;
  65. }
  66. return 1;
  67. }
  68. void changeChanel(void){
  69. if (i > 2){
  70. i =1;
  71. }
  72. switch(i) {
  73. case 1 :
  74. killPlayerThread();
  75. connectToStream("62.195.226.247",80,"/test.mp3");
  76. play();
  77. i++;
  78. break;
  79. case 2 :
  80. killPlayerThread();
  81. connectToStream("62.195.226.247",80,"/test2.mp3");
  82. play()
  83. i++;
  84. break;
  85. }
  86. return 1;
  87. }