displayHandler.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #define MONTH_OFFSET 1
  16. #define YEAR_OFFSET 1900
  17. bool displayingCustomMessage = false;
  18. void (*write_display_ptr[2])(char*, int) = {LcdArrayLineOne, LcdArrayLineTwo};
  19. void displayTime(int line_number){
  20. tm time;
  21. X12RtcGetClock(&time);
  22. char str[16];
  23. if (1){
  24. sprintf(str, " %02d:%02d:%02d ", time.tm_hour, time.tm_min, time.tm_sec);
  25. }else {
  26. sprintf(str, " ??:??:?? ");
  27. }
  28. if (line_number > -1 && line_number < 2){
  29. (*write_display_ptr[line_number])(str, 16);
  30. }
  31. }
  32. void displayDate(int line_number) {
  33. tm *time;
  34. X12RtcGetClock(time);
  35. char str[16];
  36. if (1) {
  37. sprintf(str, " %02d-%02d-%04d ", time->tm_mday, time->tm_mon + MONTH_OFFSET, time->tm_year + YEAR_OFFSET);
  38. } else {
  39. sprintf(str, " ??-??-???? ");
  40. }
  41. if (NtpIsSyncing()) {
  42. str[1] = 'S';
  43. }else if(NetworkIsReceiving()){
  44. str[1] = 'N';
  45. }
  46. if (line_number > -1 && line_number < 2){
  47. (*write_display_ptr[line_number])(str, 16);
  48. }
  49. }
  50. void displayAlarm(int line_number, int line_numberTwo, int idx)
  51. {
  52. int i;
  53. int j;
  54. int startidx;
  55. char str[16];
  56. struct _alarm am = getAlarm(idx);
  57. sprintf(str, " %02d:%02d:%02d ", am.time.tm_hour, am.time.tm_min, am.time.tm_sec);
  58. if (line_number > -1 && line_number < 2){
  59. (*write_display_ptr[line_number])(str, 16);
  60. }
  61. j = 0;
  62. char str2[16];
  63. for (i = 0; i < 16;i++){
  64. if (am.name[i] != 0){
  65. j = j + 1;
  66. }
  67. }
  68. if (j != 16){
  69. startidx = (8-(j/2));
  70. }
  71. j = 0;
  72. for(i = 0; i < 16; i++){
  73. if (i >= startidx){
  74. if (am.name[j] != 0){
  75. str2[i] = am.name[j];
  76. } else {
  77. str2[i] = ' ';
  78. }
  79. j++;
  80. } else {
  81. str2[i] = ' ';
  82. }
  83. }
  84. if (line_numberTwo > -1 && line_numberTwo < 2){
  85. (*write_display_ptr[line_numberTwo])(str2, 16);
  86. LcdBackLight(LCD_BACKLIGHT_ON);
  87. }
  88. }
  89. void displayVolume(int pos)
  90. {
  91. ClearLcd();
  92. int i;
  93. LcdArrayLineOne(" Volume ", 16);
  94. char characters[17];
  95. for(i = 0; i < 17; i++)
  96. {
  97. characters[i] = 0xFF;
  98. }
  99. LcdArrayLineTwo(characters,pos);
  100. }
  101. void displayTwitter(char* text)
  102. {
  103. //int lineNumber,char text[]
  104. ClearLcd();
  105. displayingCustomMessage = true;
  106. LcdArrayLineOne(" Twitter ", 16);
  107. int j = 0;
  108. int i;
  109. char text1[16];
  110. //char text2[140] = text;
  111. int shift = 0;
  112. //char *text = "Twitter";
  113. for(i = 0; i<200;i++){
  114. if (text[i] != 0){
  115. j++;
  116. }
  117. }
  118. while(1) {
  119. /*for (i = 0; i < 16; ++i) {
  120. LcdArrayLineOne(getLoop(text, shift + i), 7);
  121. shift++;
  122. }*/
  123. for(i = 0; i < 16; i++){
  124. if (text[shift+i]!= 0) {
  125. text1[i] = text[shift + i];
  126. } else {
  127. text1[i] = ' ';
  128. }
  129. }
  130. printf("%s\n", text1);
  131. LcdArrayLineTwo(text1,16);
  132. shift++;
  133. if (shift > j){
  134. shift = 0;
  135. }
  136. NutDelay(500);
  137. }
  138. }
  139. void displayTwitch(char name[], char title[], char game[])
  140. {
  141. displayingCustomMessage = true;
  142. ClearLcd();
  143. LcdArrayLineOne(name, strlen(name));
  144. LcdArrayLineTwo("Streaming", 9);
  145. LcdBackLight(LCD_BACKLIGHT_ON);
  146. }
  147. bool isDisplayingCustomMessage(){
  148. return displayingCustomMessage;
  149. }
  150. void setDisplayingCustomMessage(bool value){
  151. displayingCustomMessage = value;
  152. }