displayHandler.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. void (*write_display_ptr[2])(char*, int) = {LcdArrayLineOne, LcdArrayLineTwo};
  18. void displayTime(int line_number){
  19. tm time;
  20. X12RtcGetClock(&time);
  21. char str[16];
  22. if (1){
  23. sprintf(str, " %02d:%02d:%02d ", time.tm_hour, time.tm_min, time.tm_sec);
  24. }else {
  25. sprintf(str, " ??:??:?? ");
  26. }
  27. if (line_number > -1 && line_number < 2){
  28. (*write_display_ptr[line_number])(str, 16);
  29. }
  30. }
  31. void displayDate(int line_number) {
  32. tm *time;
  33. X12RtcGetClock(time);
  34. char str[16];
  35. if (1) {
  36. sprintf(str, " %02d-%02d-%04d ", time->tm_mday, time->tm_mon + MONTH_OFFSET, time->tm_year + YEAR_OFFSET);
  37. } else {
  38. sprintf(str, " ??-??-???? ");
  39. }
  40. if (NtpIsSyncing()) {
  41. str[1] = 'S';
  42. }else if(NetworkIsReceiving()){
  43. str[1] = 'N';
  44. }
  45. if (line_number > -1 && line_number < 2){
  46. (*write_display_ptr[line_number])(str, 16);
  47. }
  48. }
  49. void displayAlarm(int line_number, int line_numberTwo, int idx)
  50. {
  51. int i;
  52. int j;
  53. int startidx;
  54. char str[16];
  55. struct _alarm am = getAlarm(idx);
  56. sprintf(str, " %02d:%02d:%02d ", am.time.tm_hour, am.time.tm_min, am.time.tm_sec);
  57. if (line_number > -1 && line_number < 2){
  58. (*write_display_ptr[line_number])(str, 16);
  59. }
  60. j = 0;
  61. char str2[16];
  62. for (i = 0; i < 16;i++){
  63. if (am.name[i] != 0){
  64. j = j + 1;
  65. }
  66. }
  67. if (j != 16){
  68. startidx = (8-(j/2));
  69. }
  70. j = 0;
  71. for(i = 0; i < 16; i++){
  72. if (i >= startidx){
  73. if (am.name[j] != 0){
  74. str2[i] = am.name[j];
  75. } else {
  76. str2[i] = ' ';
  77. }
  78. j++;
  79. } else {
  80. str2[i] = ' ';
  81. }
  82. }
  83. if (line_numberTwo > -1 && line_numberTwo < 2){
  84. (*write_display_ptr[line_numberTwo])(str2, 16);
  85. LcdBackLight(LCD_BACKLIGHT_ON);
  86. }
  87. }
  88. void displayVolume(int pos)
  89. {
  90. ClearLcd();
  91. int i;
  92. LcdArrayLineOne(" Volume ", 16);
  93. char characters[17];
  94. for(i = 0; i < 17; i++)
  95. {
  96. characters[i] = 0xFF;
  97. }
  98. LcdArrayLineTwo(characters,pos);
  99. }