-
Notifications
You must be signed in to change notification settings - Fork 9
/
program.c
141 lines (121 loc) · 2.78 KB
/
program.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
#include <stdlib.h>
#include "geckonator/common.h"
#include "events.h"
#include "buttons.h"
#include "font.h"
#include "display.h"
#include "menu.h"
#define FG444 0xCB0
#define BG444 0x000
struct event {
const char **lines;
size_t len;
};
#include "program.data"
enum events {
EV_UP = 1,
EV_DOWN,
EV_EXIT,
};
static const struct button_config buttons[BTN_MAX] = {
[BTN_SUP] = { .press = EV_UP, .delay = 500, .rate = 100, .repeat = EV_UP, },
[BTN_SMID] = { .delay = 500, .longpress = EV_EXIT, },
[BTN_SDOWN] = { .press = EV_DOWN, .delay = 500, .rate = 100, .repeat = EV_DOWN, },
[BTN_UP] = { .press = EV_UP, .delay = 500, .rate = 200, .repeat = EV_UP, },
[BTN_DOWN] = { .press = EV_DOWN, .delay = 500, .rate = 200, .repeat = EV_DOWN, },
[BTN_LEFT] = { .press = EV_EXIT, },
};
static void
render(const struct event *e)
{
unsigned int y = 0;
unsigned int i;
dp_puts(2*font.width, y, BG444, FG444, e->lines[0]);
y += font.height;
dp_fill(2*font.width, y, 240-4*font.width, font.height, FG444);
dp_puts(2*font.width, y, BG444, FG444, e->lines[1]);
y += font.height;
for (i = 2; i < 240/font.height; i++) {
dp_fill(0, y, 240, font.height, BG444);
if (i < e->len)
dp_puts(0, y, FG444, BG444, e->lines[i]);
y += font.height;
if (y >= 240)
break;
}
}
static void
browse_day(const char *name, const struct event *day, size_t len)
{
unsigned int i = 0;
dp_fill(0, 0, 240, 2*font.height, FG444);
render(&day[i]);
buttons_config(buttons);
while (1) {
switch ((enum events)event_wait()) {
case EV_UP:
if (i > 0) {
i -= 1;
render(&day[i]);
}
break;
case EV_DOWN:
if (i + 1 < len) {
i += 1;
render(&day[i]);
}
break;
case EV_EXIT:
return;
}
}
}
static void
browse_thursday(void)
{
browse_day("Thursday", day0, ARRAY_SIZE(day0));
}
static void
browse_friday(void)
{
browse_day("Friday", day1, ARRAY_SIZE(day1));
}
static void
browse_saturday(void)
{
browse_day("Saturday", day2, ARRAY_SIZE(day2));
}
static void
browse_sunday(void)
{
browse_day("Sunday", day3, ARRAY_SIZE(day3));
}
static void
browse_monday(void)
{
browse_day("Monday", day4, ARRAY_SIZE(day4));
}
static void
browse_tuesday(void)
{
browse_day("Tuesday", day5, ARRAY_SIZE(day5));
}
static void
browse_wednesday(void)
{
browse_day("Wednesday", day6, ARRAY_SIZE(day6));
}
static const struct menuitem main_menu[] = {
{ .label = "Thursday", .cb = browse_thursday, },
{ .label = "Friday", .cb = browse_friday, },
{ .label = "Saturday", .cb = browse_saturday, },
{ .label = "Sunday", .cb = browse_sunday, },
{ .label = "Monday", .cb = browse_monday, },
{ .label = "Tuesday", .cb = browse_tuesday, },
{ .label = "Wednesday", .cb = browse_wednesday, },
};
void
program(void)
{
menu(main_menu, ARRAY_SIZE(main_menu), FG444, BG444);
}