-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwrmate.c
40 lines (36 loc) · 808 Bytes
/
pwrmate.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
#include "hoa.h"
int pwrmate_open(pwrmate_state *pwm) {
pwm->fd = open(PWRMATE_DEV, O_RDONLY);
memset(&pwm->new, 0, 6);
memset(&pwm->old, 0, 6);
pwm->timeout.tv_sec = 0;
pwm->timeout.tv_usec = 100000;
return pwm->fd;
}
void pwrmate_event(int fd, short event, void *arg) {
pwrmate_state *pwm = arg;
int r;
switch (event) {
case EV_READ:
r = read(fd, pwm->new, 6);
if ((pwm->new[0] == 0x01) &&
(pwm->old[0] == 0x00)) {
denon_toggle_mute(pwm->avr);
} else {
if (!denon_is_muted(pwm->avr)) {
if (pwm->new[1] < 0x7f) {
denon_vol_up(pwm->avr);
}
if (pwm->new[1] > 0x7f) {
denon_vol_dn(pwm->avr);
}
}
}
memcpy(&pwm->old, &pwm->new, 6);
break;
case EV_TIMEOUT:
printf("%s timeout fired!\n", __FUNCTION__);
break;
}
return;
}