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
|
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include "gpio.h"
#define FBSIZE (1186848 * 2)
#define SDPATH "/run/media/mmcblk0p1"
void enable_displays(void)
{
printf("enabling displays\n");
gpio_set(ENABLE_LEFT_DISPLAY);
gpio_set(ENABLE_RIGHT_DISPLAY);
}
void halt(void)
{
char *halt[] = { "shutdown", "-h", "now", NULL };
execvp(halt[0], halt);
}
void poweroff(int reason)
{
static int halting = 0;
if (halting) {
return;
}
halting = 1;
printf("shutting down (%d)\n", reason);
if (reason == GPIO_LOWBATTERY) {
printf("low battery\n");
}
exit(0);
}
void buttonpress(int button)
{
switch (button) {
case BUTTON_SPECIAL:
printf("special\n");
break;
case BUTTON_NEXTCHAPTER:
printf("next chapter\n");
break;
case BUTTON_PREVBOOK:
printf("previous book\n");
break;
case BUTTON_NEXTBOOK:
printf("next book\n");
break;
case BUTTON_PREVPAGE:
printf("previous page\n");
break;
case BUTTON_NEXTPAGE:
printf("next page\n");
break;
default:
printf("button %d pressed\n", button);
}
}
int main(int argc, char *argv[])
{
(void)argc; (void)argv;
atexit(halt);
gpio_init();
gpio_watch(GPIO_LOWBATTERY, poweroff);
gpio_watch(GPIO_SHUTDOWN, poweroff);
gpio_watch(BUTTON_SPECIAL, buttonpress);
gpio_watch(BUTTON_PREVBOOK, buttonpress);
gpio_watch(BUTTON_PREVPAGE, buttonpress);
gpio_watch(BUTTON_NEXTPAGE, buttonpress);
gpio_watch(BUTTON_NEXTCHAPTER, buttonpress);
gpio_watch(BUTTON_NEXTBOOK, buttonpress);
enable_displays();
for (;;) {
sleep(INT_MAX);
}
return 0;
}
|