gotosleep.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. fallSleep.sleepTime.tm_hour += 1;
  27. changeChanel();
  28. x = fallSleep.sleepTime.tm_min;
  29. return 1;
  30. }
  31. void checkSleep(void)
  32. {
  33. X12RtcGetClock(&count);
  34. if(compareTime(count, fallSleep.sleepTime) == 0){
  35. killPlayerThread();
  36. }
  37. if(compareTime(count, fallSleep.sleepTime) == 5 && fallSleep.sleepTime.tm_min == x){
  38. volumeDown();
  39. x += 2;
  40. }
  41. return 1;
  42. }
  43. void changeChanel(void){
  44. if (i > 2){
  45. i =1;
  46. }
  47. switch(i) {
  48. case 1 :
  49. killPlayerThread();
  50. connectToStream("62.195.226.247",80,"/test.mp3");
  51. play();
  52. i++;
  53. break;
  54. case 2 :
  55. killPlayerThread();
  56. connectToStream("62.195.226.247",80,"/test2.mp3");
  57. play()
  58. i++;
  59. break;
  60. }
  61. return 1;
  62. }