displayHandler.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 (NtpTimeIsValid()){
  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 (NtpTimeIsValid()) {
  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. char str[12];
  53. struct _alarm am = getAlarm(idx);
  54. sprintf(str, " %02d:%02d:%02d ", am.time.tm_hour, am.time.tm_min, am.time.tm_sec);
  55. if (line_number > -1 && line_number < 2){
  56. (*write_display_ptr[line_number])(str, 12);
  57. }
  58. char str2[16];
  59. for(i = 0; i < 17; i++){
  60. str2[i] = am.name[i];
  61. }
  62. if (line_numberTwo > -1 && line_numberTwo < 2){
  63. (*write_display_ptr[line_numberTwo])(str2, 16);
  64. LcdBackLight(LCD_BACKLIGHT_ON);
  65. }
  66. }
  67. void displayVolume(int pos)
  68. {
  69. ClearLcd();
  70. int i;
  71. LcdArrayLineOne(" Volume ", 16);
  72. char characters[17];
  73. for(i = 0; i < 17; i++)
  74. {
  75. characters[i] = 0xFF;
  76. }
  77. LcdArrayLineTwo(characters,pos);
  78. }