displayHandler.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Created by Jordy Sipkema on 26/02/16.
  3. //
  4. #define LOG_MODULE LOG_MAIN_MODULE
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8. #include "display.h"
  9. #include "displayHandler.h"
  10. #include "ntp.h"
  11. #include "log.h"
  12. #include "rtc.h"
  13. #include "alarm.h"
  14. #include "network.h"
  15. #include "httpstream.h"
  16. #define MONTH_OFFSET 1
  17. #define YEAR_OFFSET 1900
  18. bool displayingCustomMessage = false;
  19. void (*write_display_ptr[2])(char*, int) = {LcdArrayLineOne, LcdArrayLineTwo};
  20. void displayTime(int line_number){
  21. tm time;
  22. X12RtcGetClock(&time);
  23. char str[16];
  24. if (1){
  25. sprintf(str, " %02d:%02d:%02d ", time.tm_hour, time.tm_min, time.tm_sec);
  26. }else {
  27. sprintf(str, " ??:??:?? ");
  28. }
  29. if (line_number > -1 && line_number < 2){
  30. (*write_display_ptr[line_number])(str, 16);
  31. }
  32. }
  33. void displayDate(int line_number) {
  34. tm *time;
  35. X12RtcGetClock(time);
  36. char str[16];
  37. if (1) {
  38. sprintf(str, " %02d-%02d-%04d ", time->tm_mday, time->tm_mon + MONTH_OFFSET, time->tm_year + YEAR_OFFSET);
  39. } else {
  40. sprintf(str, " ??-??-???? ");
  41. }
  42. if (NtpIsSyncing()) {
  43. str[1] = 'S';
  44. }else if(NetworkIsReceiving()){
  45. str[1] = 'N';
  46. }
  47. if (line_number > -1 && line_number < 2){
  48. (*write_display_ptr[line_number])(str, 16);
  49. }
  50. }
  51. void displayAlarm(int line_number, int line_numberTwo, int idx)
  52. {
  53. int i;
  54. int j;
  55. int startidx;
  56. char str[16];
  57. struct _alarm am = getAlarm(idx);
  58. sprintf(str, " %02d:%02d:%02d ", am.time.tm_hour, am.time.tm_min, am.time.tm_sec);
  59. if (line_number > -1 && line_number < 2){
  60. (*write_display_ptr[line_number])(str, 16);
  61. }
  62. playStream(am.ip, am.port, am.url);
  63. j = 0;
  64. char str2[16];
  65. for (i = 0; i < 16;i++){
  66. if (am.name[i] != 0){
  67. j = j + 1;
  68. }
  69. }
  70. if (j != 16){
  71. startidx = (8-(j/2));
  72. }
  73. j = 0;
  74. for(i = 0; i < 16; i++){
  75. if (i >= startidx){
  76. if (am.name[j] != 0){
  77. str2[i] = am.name[j];
  78. } else {
  79. str2[i] = ' ';
  80. }
  81. j++;
  82. } else {
  83. str2[i] = ' ';
  84. }
  85. }
  86. if (line_numberTwo > -1 && line_numberTwo < 2){
  87. (*write_display_ptr[line_numberTwo])(str2, 16);
  88. LcdBackLight(LCD_BACKLIGHT_ON);
  89. }
  90. }
  91. void displayVolume(int pos)
  92. {
  93. ClearLcd();
  94. int i;
  95. LcdArrayLineOne(" Volume ", 16);
  96. char characters[17];
  97. for(i = 0; i < 17; i++)
  98. {
  99. characters[i] = 0xFF;
  100. }
  101. LcdArrayLineTwo(characters,pos);
  102. }
  103. void displayTwitter(int lineNumber,char text[])
  104. {
  105. ClearLcd();
  106. int i;
  107. if (lineNumber > -1 && lineNumber < 2){
  108. (*write_display_ptr[lineNumber])(text,strlen(text));
  109. }
  110. }
  111. void displayTwitch(char name[], char title[], char game[])
  112. {
  113. displayingCustomMessage = true;
  114. ClearLcd();
  115. LcdArrayLineOne(name, strlen(name));
  116. LcdArrayLineTwo("Streaming", 9);
  117. LcdBackLight(LCD_BACKLIGHT_ON);
  118. }
  119. bool isDisplayingCustomMessage(){
  120. return displayingCustomMessage;
  121. }
  122. void setDisplayingCustomMessage(bool value){
  123. displayingCustomMessage = value;
  124. }