-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathkeymon.c
113 lines (93 loc) · 2.34 KB
/
keymon.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
// v10 (based on trimuismart)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <msettings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define CODE_SELECT 704
#define CODE_START 709
#define CODE_L1 310
#define CODE_R1 311
#define VOLUME_MIN 0
#define VOLUME_MAX 20
#define BRIGHTNESS_MIN 0
#define BRIGHTNESS_MAX 10
#define RELEASED 0
#define PRESSED 1
#define INPUT_COUNT 2
static int input_fd = 0;
static struct input_event ev;
int main (int argc, char *argv[]) {
InitSettings();
input_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
uint32_t input;
uint32_t val;
uint32_t start_pressed = 0;
uint32_t select_pressed = 0;
uint32_t up_pressed = 0;
uint32_t up_just_pressed = 0;
uint32_t up_repeat_at = 0;
uint32_t down_pressed = 0;
uint32_t down_just_pressed = 0;
uint32_t down_repeat_at = 0;
uint32_t now;
struct timeval tod;
while (1) {
gettimeofday(&tod, NULL);
now = tod.tv_sec * 1000 + tod.tv_usec / 1000;
while(read(input_fd, &ev, sizeof(ev))==sizeof(ev)) {
if (ev.type != EV_KEY ) continue;
val = ev.value;
switch (ev.code) {
case CODE_START:
start_pressed = val;
break;
case CODE_SELECT:
select_pressed = val;
break;
case CODE_R1:
up_pressed = up_just_pressed = val;
if (val) up_repeat_at = now + 300;
break;
case CODE_L1:
down_pressed = down_just_pressed = val;
if (val) down_repeat_at = now + 300;
break;
default:
break;
}
}
if (up_just_pressed || (up_pressed && now>=up_repeat_at)) {
if (start_pressed) {
val = GetBrightness();
if (val<BRIGHTNESS_MAX) SetBrightness(++val);
}
else if (select_pressed) {
val = GetVolume();
if (val<VOLUME_MAX) SetVolume(++val);
}
if (up_just_pressed) up_just_pressed = 0;
else up_repeat_at += 100;
}
if (down_just_pressed || (down_pressed && now>=down_repeat_at)) {
if (start_pressed) {
val = GetBrightness();
if (val>BRIGHTNESS_MIN) SetBrightness(--val);
}
else if (select_pressed) {
val = GetVolume();
if (val>VOLUME_MIN) SetVolume(--val);
}
if (down_just_pressed) down_just_pressed = 0;
else down_repeat_at += 100;
}
usleep(16666); // 60fps
}
}