gotosleep.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if (x >= 60){
  40. x = 0;
  41. }
  42. x += 2;
  43. }
  44. return 1;
  45. }
  46. void changeChanel(void){
  47. if (i > 2){
  48. i =1;
  49. }
  50. switch(i) {
  51. case 1 :
  52. killPlayerThread();
  53. connectToStream("62.195.226.247",80,"/test.mp3");
  54. play();
  55. i++;
  56. break;
  57. case 2 :
  58. killPlayerThread();
  59. connectToStream("62.195.226.247",80,"/test2.mp3");
  60. play()
  61. i++;
  62. break;
  63. }
  64. return 1;
  65. }