displayHandler.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Created by Jordy Sipkema on 26/02/16.
  3. //
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include "display.h"
  8. #include "displayHandler.h"
  9. #include "ntp.h"
  10. #include "rtc.h"
  11. #define MONTH_OFFSET 1
  12. #define YEAR_OFFSET 1900
  13. void (*write_display_ptr[2])(char*, int) = {LcdArrayLineOne, LcdArrayLineTwo};
  14. void displayTime(int line_number){
  15. tm time;
  16. X12RtcGetClock(&time);
  17. char str[12];
  18. if (NtpTimeIsValid()){
  19. sprintf(str, " %02d:%02d:%02d", time.tm_hour, time.tm_min, time.tm_sec);
  20. }else {
  21. sprintf(str, " ??:??:??");
  22. }
  23. if (line_number > -1 && line_number < 2){
  24. (*write_display_ptr[line_number])(str, 12);
  25. }
  26. }
  27. void displayDate(int line_number){
  28. tm *time;
  29. X12RtcGetClock(time);
  30. char str[13];
  31. if (NtpTimeIsValid()){
  32. sprintf(str, " %02d-%02d-%04d", time->tm_mday, time->tm_mon+MONTH_OFFSET, time->tm_year+YEAR_OFFSET);
  33. }else {
  34. sprintf(str, " ??-??-????");
  35. }
  36. if(NtpIsSyncing())
  37. str[1] = 'S';
  38. if (line_number > -1 && line_number < 2){
  39. (*write_display_ptr[line_number])(str, 13);
  40. }
  41. }