gotosleep.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "mp3stream.h"
  13. #include "gotosleep.h"
  14. struct _tm sleepTime;
  15. struct _tm count;
  16. int i = 1;
  17. int x = 0;
  18. int mins;
  19. int hours;
  20. int days;
  21. bool sleepOn = false;
  22. void setSleep(void)
  23. {
  24. if (sleepOn == true)
  25. {
  26. printf("closed1");
  27. killPlayerThread();
  28. sleepOn = false;
  29. }
  30. else{
  31. X12RtcGetClock(&count);
  32. sleepTime = count;
  33. AddMinutes(60);
  34. printf("%d", sleepTime.tm_hour);
  35. playChanel();
  36. x = sleepTime.tm_min;
  37. mins = sleepTime.tm_min;
  38. hours = sleepTime.tm_hour;
  39. days = sleepTime.tm_mday;
  40. sleepOn = true;
  41. }
  42. }
  43. void AddMinutes(int minutes){
  44. if (sleepTime.tm_min + minutes >= 60){ //Checks if minutes is >= 60 else minute
  45. sleepTime.tm_hour += 1;
  46. sleepTime.tm_min = ((sleepTime.tm_min + minutes) % 60);
  47. if (sleepTime.tm_hour >= 24){ //Checks if hours is >= 24
  48. sleepTime.tm_hour = 0;
  49. if ((sleepTime.tm_mday + 1) <= daysInMonth((sleepTime.tm_mon+1), (sleepTime.tm_year+1900))){ //Checks if day+1 smaller or even is to the amount of days in the month
  50. sleepTime.tm_mday += 1;
  51. } else { //If the days+1 is bigger than the amount of days in the month, day = 1 & month is + 1
  52. sleepTime.tm_mday = 1;
  53. if (sleepTime.tm_mon + 1 > 11){//If month+1 is bigger than 11 (month is 0-11) then month = 0 & year + 1
  54. sleepTime.tm_mon = 0;
  55. sleepTime.tm_year += 1;
  56. } else {
  57. sleepTime.tm_mon += 1;
  58. }
  59. }
  60. }
  61. } else {
  62. sleepTime.tm_min += minutes;
  63. }
  64. }
  65. void checkSleep(void)
  66. {
  67. X12RtcGetClock(&count);
  68. if(count.tm_min == mins && count.tm_hour == hours && count.tm_mday == days){
  69. printf("closed");
  70. killPlayerThread();
  71. volumeUp();
  72. volumeUp();
  73. volumeUp();
  74. volumeUp();
  75. volumeUp();
  76. volumeUp();
  77. sleepOn = false;
  78. }
  79. if(count.tm_min == x){
  80. volumeDown();
  81. if (x >= 60){
  82. x = 0;
  83. }
  84. x += 10;
  85. }
  86. }
  87. void changeChanel(void){
  88. i++;
  89. if (i > 5){
  90. i = 1;
  91. }
  92. }
  93. void playChanel(void){
  94. switch(i) {
  95. case 1 :
  96. connectToStream("62.195.226.247",80,"/test7.mp3");
  97. play();
  98. break;
  99. case 2 :
  100. connectToStream("62.195.226.247",80,"/test5.mp3");
  101. play();
  102. break;
  103. case 3 :
  104. connectToStream("62.195.226.247",80,"/test4.mp3");
  105. play();
  106. break;
  107. case 4 :
  108. connectToStream("62.195.226.247",80,"/test10.mp3");
  109. play();
  110. break;
  111. case 5 :
  112. connectToStream("62.195.226.247",80,"/test11.mp3");
  113. play();
  114. break;
  115. }
  116. }