/
io.c
141 lines (131 loc) · 3.36 KB
/
io.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
/*
* sysinfo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include "current.h"
#include "io.h"
#include "sysinfo.h"
#include "rc_device.h"
struct input_event ev;
unsigned short rccode=-1;
int rc;
int InitRC(void)
{
char rc_device[32];
get_rc_device(rc_device);
printf("rc_device: using %s\n", rc_device);
rc = open(rc_device, O_RDONLY | O_CLOEXEC);
if(rc == -1)
{
perror(__plugin__ " <open remote control failed>");
exit(1);
}
fcntl(rc, F_SETFL, O_NONBLOCK | O_SYNC);
while(RCKeyPressed());
return 1;
}
int CloseRC(void)
{
while(RCKeyPressed());
close(rc);
return 1;
}
int RCKeyPressed(void)
{
if(read(rc, &ev, sizeof(ev)) == sizeof(ev))
{
if(ev.value)
{
rccode=ev.code;
return 1;
}
}
rccode = -1;
return 0;
}
int GetRCCode()
{
#define REPEAT_TIMER 3
static int count = 0;
static __u16 rc_last_key = KEY_RESERVED;
//get code
if (read(rc, &ev, sizeof(ev)) == sizeof(ev))
{
if(ev.value > 0 && ev.code != rc_last_key)
{
if (ev.value == 2)
{
while (count < REPEAT_TIMER)
{
count++;
rccode = -1;
usleep(15000L);
return rccode;
}
}
else
count = 0;
rc_last_key = ev.code;
switch (ev.code)
{
case KEY_UP: rccode = RC_UP; break;
case KEY_DOWN: rccode = RC_DOWN; break;
case KEY_LEFT: rccode = RC_LEFT; break;
case KEY_RIGHT: rccode = RC_RIGHT; break;
case KEY_OK: rccode = RC_OK; break;
case KEY_0: rccode = RC_0; break;
case KEY_1: rccode = RC_1; break;
case KEY_2: rccode = RC_2; break;
case KEY_3: rccode = RC_3; break;
case KEY_4: rccode = RC_4; break;
case KEY_5: rccode = RC_5; break;
case KEY_6: rccode = RC_6; break;
case KEY_7: rccode = RC_7; break;
case KEY_8: rccode = RC_8; break;
case KEY_9: rccode = RC_9; break;
case KEY_RED: rccode = RC_RED; break;
case KEY_GREEN: rccode = RC_GREEN; break;
case KEY_YELLOW: rccode = RC_YELLOW; break;
case KEY_BLUE: rccode = RC_BLUE; break;
case KEY_VOLUMEUP: rccode = RC_PLUS; break;
case KEY_VOLUMEDOWN: rccode = RC_MINUS; break;
case KEY_MUTE: rccode = RC_MUTE; break;
case KEY_HELP: rccode = RC_HELP; break;
case KEY_INFO: rccode = RC_HELP; break;
case KEY_SETUP: rccode = RC_DBOX; break;
case KEY_MENU: rccode = RC_DBOX; break;
case KEY_EXIT: rccode = RC_EXIT; break;
case KEY_HOME: rccode = RC_HOME; break;
case KEY_POWER: rccode = RC_STANDBY;break;
default: rccode = -1;
}
return rccode;
}
else
{
rccode = -1;
rc_last_key = KEY_RESERVED;
}
}
return -1;
}