-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_functions.c
186 lines (164 loc) · 3.18 KB
/
print_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "rtc_common.h"
#include "print_functions.h"
#include <avr/pgmspace.h>
#include "lcd.h"
#include <stdlib.h>
const char monthStrings[12][4] PROGMEM = {
{ "Jan" },
{ "Feb" },
{ "Mar" },
{ "Apr" },
{ "May" },
{ "Jun" },
{ "Jul" },
{ "Aug" },
{ "Sep" },
{ "Oct" },
{ "Nov" },
{ "Dec" }
};
const char dayStrings[7][4] PROGMEM = {
{ "Sun" },
{ "Mon" },
{ "Tue" },
{ "Wed" },
{ "Thr" },
{ "Fri" },
{ "Sat" },
};
const char menuStrings[3][15] PROGMEM = {
{ " Set Time" },
{ " Set Alarm" },
//{ " Set Alarm2" },
{ " Return" },
};
char buffer[7];
char *digit_string(uint16_t digits)
{
if (digits == 0)
return "00";
else if (digits < 10) {
utoa(digits, buffer, 10);
// Prepend "0"
// TODO why is strcat() b0rked?
buffer[1] = buffer[0];
buffer[0] = '0';
buffer[2] = '\0';
return buffer;
}
else
return utoa(digits, buffer, 10);
}
void print_date(time t)
{
print_date_xy(t, dateOrigin.x, dateOrigin.y);
}
void print_date_xy(time t, uint8_t x, uint8_t y)
{
lcd_gotoxy(x, y);
lcd_puts_p(dayStrings[get_day_of_week(t)]);
lcd_putc(' ');
lcd_puts_p(monthStrings[t.month - 1]);
lcd_putc(' ');
lcd_puts(digit_string(t.date));
lcd_puts(", ");
lcd_puts(digit_string(t.year));
}
void print_time(time t)
{
print_time_xy(t, timeOrigin.x, timeOrigin.y);
}
void print_time_xy(time t, uint8_t x, uint8_t y)
{
lcd_gotoxy(x, y);
lcd_puts(digit_string(t.hour));
lcd_putc(':');
lcd_puts(digit_string(t.minute));
lcd_putc(':');
lcd_puts(digit_string(t.second));
}
void print_blank(uint8_t x, uint8_t y, uint8_t len)
{
lcd_gotoxy(x, y);
for (; len>0; len--)
lcd_putc(' ');
}
void print_hour(time t)
{
lcd_gotoxy(timeOrigin.x, timeOrigin.y);
lcd_puts(digit_string(t.hour));
}
void print_minute(time t)
{
lcd_gotoxy(timeOrigin.x + MINUTE_X_OFFSET, timeOrigin.y);
lcd_puts(digit_string(t.minute));
}
void print_second(time t)
{
lcd_gotoxy(timeOrigin.x + SECOND_X_OFFSET, timeOrigin.y);
lcd_puts(digit_string(t.second));
}
void print_month(time t)
{
lcd_gotoxy(dateOrigin.x + MONTH_X_OFFSET, dateOrigin.y + 1);
lcd_puts_p(monthStrings[t.month - 1]);
}
void print_day(time t)
{
lcd_gotoxy(dateOrigin.x + DAY_X_OFFSET, dateOrigin.y + 1);
lcd_puts(digit_string(t.date));
}
void print_year(time t)
{
lcd_gotoxy(dateOrigin.x + YEAR_X_OFFSET, dateOrigin.y + 1);
lcd_puts(digit_string(t.year));
}
void print_menu(uint8_t menu)
{
lcd_clrscr();
print_arrows(0);
lcd_gotoxy(1, 0);
lcd_puts_p(menuStrings[menu - 1]);
switch (menu)
{
case SET_TIME:
print_time(t);
break;
case SET_ALARM1:
print_time(alarmTime);
break;
//case SET_ALARM2:
// print_time(alarmTime);
// break;
case SET_RETURN:
break;
}
}
void print_set_time(time tempTime)
{
lcd_clrscr();
lcd_gotoxy(1, 0);
lcd_puts_p(menuStrings[SET_TIME - 1]);
print_time(tempTime);
}
void print_set_date(time tempTime)
{
lcd_clrscr();
lcd_gotoxy(1, 0);
lcd_puts_p(menuStrings[SET_TIME - 1]);
print_date_xy(tempTime, 0, 1);
}
void print_set_alarm1(time tempTime)
{
lcd_clrscr();
lcd_gotoxy(1, 0);
lcd_puts_p(menuStrings[SET_ALARM1 - 1]);
print_time(tempTime);
}
void print_arrows(uint8_t row)
{
lcd_gotoxy(0, row);
lcd_data(0x7F); // <--
lcd_gotoxy(15, row);
lcd_data(0x7E); // -->
}