module_date.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "module_date.h"
  2. #define RIGHT_DOW 44
  3. #define LEFT_YEAR 46
  4. #define WIDTH_YEAR 26
  5. #define MID_CENTURY 53
  6. #define MID_YEAR_10s 62
  7. #define MID_YEAR_1s 69
  8. #define MID_DATE_S1 74
  9. #define LEFT_MONTH 76
  10. #define WIDTH_INYEAR 30
  11. #define MID_MONTH_10s 79
  12. #define MID_MONTH_1s 86
  13. #define MID_DATE_S2 91
  14. #define MID_DAY_10s 96
  15. #define MID_DAY_1s 103
  16. #define DIGIT_HALFW 3
  17. #define DIGIT_HEIGHT 9
  18. #define WIDTH_DOW 25
  19. #define WIDTH_DATE 88
  20. char* day_name[] = {"- ", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
  21. static void draw_dow_right(Canvas* canvas, uint16_t top, uint16_t right, int8_t day_in_week) {
  22. if(day_in_week == -1) {
  23. day_in_week = 0;
  24. }
  25. char buf[5];
  26. snprintf(buf, sizeof(buf), "%s,", day_name[day_in_week]);
  27. canvas_draw_str_aligned(canvas, right, top, AlignRight, AlignTop, buf);
  28. }
  29. static void draw_digit_centered(Canvas* canvas, uint16_t top, uint16_t mid_left, int8_t digit) {
  30. if(digit < 0) {
  31. canvas_draw_str_aligned(canvas, mid_left, top, AlignCenter, AlignTop, "-");
  32. } else {
  33. char buf[4];
  34. snprintf(buf, sizeof(buf), "%d", digit);
  35. canvas_draw_str_aligned(canvas, mid_left, top, AlignCenter, AlignTop, buf);
  36. }
  37. }
  38. static void draw_selection_digit(Canvas* canvas, uint16_t top, uint16_t mid_left) {
  39. canvas_draw_frame(canvas, mid_left - DIGIT_HALFW, top + DIGIT_HEIGHT, DIGIT_HALFW * 2 + 1, 2);
  40. }
  41. void draw_decoded_date(
  42. Canvas* canvas,
  43. uint16_t top,
  44. DecodingDatePhase selection,
  45. int8_t century,
  46. int8_t year_10s,
  47. int8_t year_1s,
  48. int8_t month_10s,
  49. int8_t month_1s,
  50. int8_t day_in_month_10s,
  51. int8_t day_in_month_1s,
  52. int8_t day_in_week) {
  53. canvas_set_font(canvas, FontPrimary);
  54. canvas_draw_str_aligned(canvas, MID_DATE_S1, top, AlignCenter, AlignTop, ".");
  55. canvas_draw_str_aligned(canvas, MID_DATE_S2, top, AlignCenter, AlignTop, ".");
  56. draw_dow_right(canvas, top, RIGHT_DOW, day_in_week);
  57. draw_digit_centered(canvas, top, MID_CENTURY, century);
  58. draw_digit_centered(canvas, top, MID_YEAR_10s, year_10s);
  59. draw_digit_centered(canvas, top, MID_YEAR_1s, year_1s);
  60. draw_digit_centered(canvas, top, MID_MONTH_10s, month_10s);
  61. draw_digit_centered(canvas, top, MID_MONTH_1s, month_1s);
  62. draw_digit_centered(canvas, top, MID_DAY_10s, day_in_month_10s);
  63. draw_digit_centered(canvas, top, MID_DAY_1s, day_in_month_1s);
  64. switch(selection) {
  65. case DecodingDateYear10s:
  66. draw_selection_digit(canvas, top, MID_YEAR_10s);
  67. break;
  68. case DecodingDateYear1s:
  69. draw_selection_digit(canvas, top, MID_YEAR_1s);
  70. break;
  71. case DecodingDateMonth10s:
  72. draw_selection_digit(canvas, top, MID_MONTH_10s);
  73. break;
  74. case DecodingDateMonth1s:
  75. draw_selection_digit(canvas, top, MID_MONTH_1s);
  76. break;
  77. case DecodingDateDayOfMonth10s:
  78. draw_selection_digit(canvas, top, MID_DAY_10s);
  79. break;
  80. case DecodingDateDayOfMonth1s:
  81. draw_selection_digit(canvas, top, MID_DAY_1s);
  82. break;
  83. case DecodingDateDayOfWeek:
  84. canvas_draw_frame(canvas, RIGHT_DOW - WIDTH_DOW, top + DIGIT_HEIGHT, WIDTH_DOW, 2);
  85. break;
  86. case DecodingDateDayOfWeekChecksum:
  87. canvas_draw_frame(canvas, RIGHT_DOW - WIDTH_DOW, top + DIGIT_HEIGHT, WIDTH_DOW, 2);
  88. break;
  89. case DecodingDateDate:
  90. canvas_draw_frame(canvas, RIGHT_DOW - WIDTH_DOW, top + DIGIT_HEIGHT, WIDTH_DATE, 2);
  91. break;
  92. case DecodingDateYearChecksum:
  93. canvas_draw_frame(canvas, LEFT_YEAR, top + DIGIT_HEIGHT, WIDTH_YEAR, 2);
  94. break;
  95. case DecodingDateInYearChecksum:
  96. canvas_draw_frame(canvas, LEFT_MONTH, top + DIGIT_HEIGHT, WIDTH_INYEAR, 2);
  97. break;
  98. default:
  99. break;
  100. }
  101. }