author | mickeyl <mickeyl> | 2005-02-04 16:51:11 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-02-04 16:51:11 (UTC) |
commit | 276022cd2a84f531bbf727c34d76420d8195512d (patch) (unidiff) | |
tree | 31c15ddb1cbed5e5a0db43e32af9066b424bab8c | |
parent | 5398d63dbd79eb166ab1c36517f60c6e850a2ca7 (diff) | |
download | opie-276022cd2a84f531bbf727c34d76420d8195512d.zip opie-276022cd2a84f531bbf727c34d76420d8195512d.tar.gz opie-276022cd2a84f531bbf727c34d76420d8195512d.tar.bz2 |
show global key state
-rw-r--r-- | examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp index a9c0fd2..6c95048 100644 --- a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp +++ b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | |||
@@ -1,277 +1,287 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <opie2/odebug.h> | 29 | #include <opie2/odebug.h> |
30 | #include <opie2/oinputsystem.h> | 30 | #include <opie2/oinputsystem.h> |
31 | 31 | ||
32 | using namespace Opie::Core; | 32 | using namespace Opie::Core; |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <sys/ioctl.h> | 37 | #include <sys/ioctl.h> |
38 | #include <sys/fcntl.h> | 38 | #include <sys/fcntl.h> |
39 | 39 | ||
40 | #if 1 | 40 | #if 1 |
41 | 41 | ||
42 | int main( int argc, char** argv ) | 42 | int main( int argc, char** argv ) |
43 | { | 43 | { |
44 | OInputSystem* sys = OInputSystem::instance(); | 44 | OInputSystem* sys = OInputSystem::instance(); |
45 | OInputSystem::DeviceIterator it = sys->iterator(); | 45 | OInputSystem::DeviceIterator it = sys->iterator(); |
46 | 46 | ||
47 | OInputDevice* dev = 0; | 47 | OInputDevice* dev = 0; |
48 | 48 | ||
49 | while ( it.current() ) | 49 | while ( it.current() ) |
50 | { | 50 | { |
51 | odebug << "DEMO: OInputSystem contains OInputDevice '" << it.current()->name() << "'" << oendl; | 51 | odebug << "DEMO: OInputSystem contains OInputDevice '" << it.current()->name() << "'" << oendl; |
52 | 52 | ||
53 | dev = it.current(); | 53 | dev = it.current(); |
54 | 54 | ||
55 | QString features; | 55 | QString features; |
56 | features += QString( "\nSynchronous: " ); | 56 | features += QString( "\nSynchronous: " ); |
57 | if ( dev->hasFeature( OInputDevice::Synchronous ) ) features += "[ x ]"; else features += "[ ]"; | 57 | if ( dev->hasFeature( OInputDevice::Synchronous ) ) features += "[ x ]"; else features += "[ ]"; |
58 | features += QString( "\nKeys or Buttons: " ); | 58 | features += QString( "\nKeys or Buttons: " ); |
59 | if ( dev->hasFeature( OInputDevice::Keys ) ) features += "[ x ]"; else features += "[ ]"; | 59 | if ( dev->hasFeature( OInputDevice::Keys ) ) features += "[ x ]"; else features += "[ ]"; |
60 | features += QString( "\nRelative Axes: " ); | 60 | features += QString( "\nRelative Axes: " ); |
61 | if ( dev->hasFeature( OInputDevice::Relative ) ) features += "[ x ]"; else features += "[ ]"; | 61 | if ( dev->hasFeature( OInputDevice::Relative ) ) features += "[ x ]"; else features += "[ ]"; |
62 | features += QString( "\nAbsolute Axes: " ); | 62 | features += QString( "\nAbsolute Axes: " ); |
63 | if ( dev->hasFeature( OInputDevice::Absolute ) ) features += "[ x ]"; else features += "[ ]"; | 63 | if ( dev->hasFeature( OInputDevice::Absolute ) ) features += "[ x ]"; else features += "[ ]"; |
64 | features += QString( "\nMiscellaneous: " ); | 64 | features += QString( "\nMiscellaneous: " ); |
65 | if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) features += "[ x ]"; else features += "[ ]"; | 65 | if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) features += "[ x ]"; else features += "[ ]"; |
66 | features += QString( "\nLeds: " ); | 66 | features += QString( "\nLeds: " ); |
67 | if ( dev->hasFeature( OInputDevice::Leds ) ) features += "[ x ]"; else features += "[ ]"; | 67 | if ( dev->hasFeature( OInputDevice::Leds ) ) features += "[ x ]"; else features += "[ ]"; |
68 | features += QString( "\nSound: " ); | 68 | features += QString( "\nSound: " ); |
69 | if ( dev->hasFeature( OInputDevice::Sound ) ) features += "[ x ]"; else features += "[ ]"; | 69 | if ( dev->hasFeature( OInputDevice::Sound ) ) features += "[ x ]"; else features += "[ ]"; |
70 | features += QString( "\nAutoRepeat " ); | 70 | features += QString( "\nAutoRepeat " ); |
71 | if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) features += "[ x ]"; else features += "[ ]"; | 71 | if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) features += "[ x ]"; else features += "[ ]"; |
72 | features += QString( "\nForceFeedback: " ); | 72 | features += QString( "\nForceFeedback: " ); |
73 | if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) features += "[ x ]"; else features += "[ ]"; | 73 | if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) features += "[ x ]"; else features += "[ ]"; |
74 | features += QString( "\nPowerManagement: " ); | 74 | features += QString( "\nPowerManagement: " ); |
75 | if ( dev->hasFeature( OInputDevice::PowerManagement ) ) features += "[ x ]"; else features += "[ ]"; | 75 | if ( dev->hasFeature( OInputDevice::PowerManagement ) ) features += "[ x ]"; else features += "[ ]"; |
76 | features += QString( "\nFeedbackStatus: " ); | 76 | features += QString( "\nFeedbackStatus: " ); |
77 | if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) features += "[ x ]"; else features += "[ ]"; | 77 | if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) features += "[ x ]"; else features += "[ ]"; |
78 | 78 | ||
79 | odebug << "========================================" | 79 | odebug << "========================================" |
80 | << "\nDevice: " << dev->name() | 80 | << "\nDevice: " << dev->name() |
81 | << "\nName: " << dev->identity() | 81 | << "\nName: " << dev->identity() |
82 | << "\nPath: " << dev->path() | 82 | << "\nPath: " << dev->path() |
83 | << "\nUniq: " << dev->uniq() | 83 | << "\nUniq: " << dev->uniq() |
84 | << features << "\n" | 84 | << features << "\n" |
85 | << oendl; | 85 | << oendl; |
86 | |||
87 | if ( dev->isHeld( OInputDevice::Key_LEFTSHIFT ) ) | ||
88 | odebug << "Left Shift is being held." << oendl; | ||
89 | else odebug << "Left Shift is _not_ being held." << oendl; | ||
90 | |||
91 | if ( dev->isHeld( OInputDevice::Button_LEFT ) ) | ||
92 | odebug << "Left Mouse Button is being held." << oendl; | ||
93 | else odebug << "Left Mouse Button is _not_ being held." << oendl; | ||
94 | |||
95 | odebug << "Global key mask: " << dev->globalKeyMask() << oendl; | ||
86 | 96 | ||
87 | ++it; | 97 | ++it; |
88 | } | 98 | } |
89 | } | 99 | } |
90 | 100 | ||
91 | #else | 101 | #else |
92 | 102 | ||
93 | #include <fcntl.h> | 103 | #include <fcntl.h> |
94 | #include <unistd.h> | 104 | #include <unistd.h> |
95 | #include <cstdlib> | 105 | #include <cstdlib> |
96 | #include <cstdio> | 106 | #include <cstdio> |
97 | #include <string> | 107 | #include <string> |
98 | 108 | ||
99 | #include <sys/types.h> | 109 | #include <sys/types.h> |
100 | #include <linux/input.h> | 110 | #include <linux/input.h> |
101 | 111 | ||
102 | using std::string; | 112 | using std::string; |
103 | 113 | ||
104 | const unsigned char BUT1 = 0x01; | 114 | const unsigned char BUT1 = 0x01; |
105 | const unsigned char BUT2 = 0x04; | 115 | const unsigned char BUT2 = 0x04; |
106 | const unsigned char BUT3 = 0x02; | 116 | const unsigned char BUT3 = 0x02; |
107 | const unsigned char BUT4 = 0x40; | 117 | const unsigned char BUT4 = 0x40; |
108 | const unsigned char BUT5 = 0x80; | 118 | const unsigned char BUT5 = 0x80; |
109 | 119 | ||
110 | #define BITMASK( name, numbits ) \ | 120 | #define BITMASK( name, numbits ) \ |
111 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | 121 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ |
112 | memset( name, 0, sizeof( name ) ) | 122 | memset( name, 0, sizeof( name ) ) |
113 | 123 | ||
114 | #define TEST_BIT( bitmask, bit ) \ | 124 | #define TEST_BIT( bitmask, bit ) \ |
115 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | 125 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) |
116 | 126 | ||
117 | int Open_cPad() | 127 | int Open_cPad() |
118 | { | 128 | { |
119 | size_t MAX_DEVICES = 1; | 129 | size_t MAX_DEVICES = 1; |
120 | int fd = -1; | 130 | int fd = -1; |
121 | input_id info; | 131 | input_id info; |
122 | 132 | ||
123 | for( size_t i = 0; i < MAX_DEVICES; ++i ) | 133 | for( size_t i = 0; i < MAX_DEVICES; ++i ) |
124 | { | 134 | { |
125 | string devpath( "/dev/input/event0" ); | 135 | string devpath( "/dev/input/event0" ); |
126 | 136 | ||
127 | //devpath << (int)i; | 137 | //devpath << (int)i; |
128 | 138 | ||
129 | fd = open( devpath.c_str(), O_RDONLY, &info ); | 139 | fd = open( devpath.c_str(), O_RDONLY, &info ); |
130 | 140 | ||
131 | if( fd >= 0 ) | 141 | if( fd >= 0 ) |
132 | { | 142 | { |
133 | int version = -1; | 143 | int version = -1; |
134 | /* ioctl() accesses the underlying driver */ | 144 | /* ioctl() accesses the underlying driver */ |
135 | if (ioctl(fd, EVIOCGVERSION, &version)) { | 145 | if (ioctl(fd, EVIOCGVERSION, &version)) { |
136 | perror("evdev ioctl"); | 146 | perror("evdev ioctl"); |
137 | } | 147 | } |
138 | 148 | ||
139 | /* the EVIOCGVERSION ioctl() returns an int */ | 149 | /* the EVIOCGVERSION ioctl() returns an int */ |
140 | /* so we unpack it and display it */ | 150 | /* so we unpack it and display it */ |
141 | printf("evdev driver version is %d.%d.%d\n", | 151 | printf("evdev driver version is %d.%d.%d\n", |
142 | version >> 16, (version >> 8) & 0xff, | 152 | version >> 16, (version >> 8) & 0xff, |
143 | version & 0xff); | 153 | version & 0xff); |
144 | 154 | ||
145 | // Get Identifying info | 155 | // Get Identifying info |
146 | 156 | ||
147 | if( ioctl( fd, EVIOCGID, &info) ) | 157 | if( ioctl( fd, EVIOCGID, &info) ) |
148 | { | 158 | { |
149 | perror( "event device ioctl" ); | 159 | perror( "event device ioctl" ); |
150 | return -1; | 160 | return -1; |
151 | } | 161 | } |
152 | printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n", | 162 | printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n", |
153 | info.bustype, info.vendor, info.product, info.version ); | 163 | info.bustype, info.vendor, info.product, info.version ); |
154 | 164 | ||
155 | switch ( info.bustype) | 165 | switch ( info.bustype) |
156 | { | 166 | { |
157 | case BUS_PCI : | 167 | case BUS_PCI : |
158 | printf(" is on a PCI bus\n"); | 168 | printf(" is on a PCI bus\n"); |
159 | break; | 169 | break; |
160 | case BUS_USB : | 170 | case BUS_USB : |
161 | printf(" is on a Universal Serial Bus\n"); | 171 | printf(" is on a Universal Serial Bus\n"); |
162 | break; | 172 | break; |
163 | /* ... */ | 173 | /* ... */ |
164 | } | 174 | } |
165 | 175 | ||
166 | // Get feature types | 176 | // Get feature types |
167 | 177 | ||
168 | BITMASK( features, EV_MAX ); | 178 | BITMASK( features, EV_MAX ); |
169 | 179 | ||
170 | if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) | 180 | if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) |
171 | { | 181 | { |
172 | perror( "event device ioctl" ); | 182 | perror( "event device ioctl" ); |
173 | return -1; | 183 | return -1; |
174 | } | 184 | } |
175 | 185 | ||
176 | printf( "Supported features:\n" ); | 186 | printf( "Supported features:\n" ); |
177 | for( size_t bit = 0; bit < EV_MAX; ++bit ) | 187 | for( size_t bit = 0; bit < EV_MAX; ++bit ) |
178 | { | 188 | { |
179 | if( TEST_BIT( features, bit ) ) | 189 | if( TEST_BIT( features, bit ) ) |
180 | { | 190 | { |
181 | switch( bit ) | 191 | switch( bit ) |
182 | { | 192 | { |
183 | case EV_SYN : | 193 | case EV_SYN : |
184 | printf(" Sync. Events\n"); | 194 | printf(" Sync. Events\n"); |
185 | break; | 195 | break; |
186 | //case EV_RST: | 196 | //case EV_RST: |
187 | // printf( " Reset?\n" ); | 197 | // printf( " Reset?\n" ); |
188 | // break; | 198 | // break; |
189 | case EV_KEY: | 199 | case EV_KEY: |
190 | printf( " Keys or buttons\n" ); | 200 | printf( " Keys or buttons\n" ); |
191 | break; | 201 | break; |
192 | case EV_REL: | 202 | case EV_REL: |
193 | printf( " Relative axes\n" ); | 203 | printf( " Relative axes\n" ); |
194 | break; | 204 | break; |
195 | case EV_ABS: | 205 | case EV_ABS: |
196 | printf( " Absolute axes\n" ); | 206 | printf( " Absolute axes\n" ); |
197 | break; | 207 | break; |
198 | case EV_MSC: | 208 | case EV_MSC: |
199 | printf( " Misc\n" ); | 209 | printf( " Misc\n" ); |
200 | break; | 210 | break; |
201 | case EV_LED: | 211 | case EV_LED: |
202 | printf( " Led's\n" ); | 212 | printf( " Led's\n" ); |
203 | break; | 213 | break; |
204 | case EV_SND: | 214 | case EV_SND: |
205 | printf( " Sounds\n" ); | 215 | printf( " Sounds\n" ); |
206 | break; | 216 | break; |
207 | case EV_REP: | 217 | case EV_REP: |
208 | printf( " Repeat\n" ); | 218 | printf( " Repeat\n" ); |
209 | break; | 219 | break; |
210 | case EV_FF : // fallthrough | 220 | case EV_FF : // fallthrough |
211 | case EV_FF_STATUS: | 221 | case EV_FF_STATUS: |
212 | printf(" Force Feedback\n"); | 222 | printf(" Force Feedback\n"); |
213 | break; | 223 | break; |
214 | case EV_PWR: | 224 | case EV_PWR: |
215 | printf(" Power Management\n"); | 225 | printf(" Power Management\n"); |
216 | break; | 226 | break; |
217 | default: | 227 | default: |
218 | printf( " Unknown (bit %d)\n", bit ); | 228 | printf( " Unknown (bit %d)\n", bit ); |
219 | } | 229 | } |
220 | } | 230 | } |
221 | } | 231 | } |
222 | 232 | ||
223 | // Check keystate | 233 | // Check keystate |
224 | 234 | ||
225 | BITMASK( keys, KEY_MAX ); | 235 | BITMASK( keys, KEY_MAX ); |
226 | 236 | ||
227 | if( ioctl( fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) | 237 | if( ioctl( fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) |
228 | { | 238 | { |
229 | perror( "event device ioctl" ); | 239 | perror( "event device ioctl" ); |
230 | return -1; | 240 | return -1; |
231 | } | 241 | } |
232 | 242 | ||
233 | printf( "Key global status:\n" ); | 243 | printf( "Key global status:\n" ); |
234 | for( size_t bit = 0; bit < KEY_MAX; ++bit ) | 244 | for( size_t bit = 0; bit < KEY_MAX; ++bit ) |
235 | { | 245 | { |
236 | if( TEST_BIT( keys, bit ) ) | 246 | if( TEST_BIT( keys, bit ) ) |
237 | { | 247 | { |
238 | printf( "Key (bit %d) active\n", bit ); | 248 | printf( "Key (bit %d) active\n", bit ); |
239 | } | 249 | } |
240 | } | 250 | } |
241 | } | 251 | } |
242 | else | 252 | else |
243 | printf( "Failed to open device\n" ); | 253 | printf( "Failed to open device\n" ); |
244 | 254 | ||
245 | close( fd ); | 255 | close( fd ); |
246 | } | 256 | } |
247 | return fd; | 257 | return fd; |
248 | } | 258 | } |
249 | 259 | ||
250 | 260 | ||
251 | int main( int argc, char **argv ) | 261 | int main( int argc, char **argv ) |
252 | { | 262 | { |
253 | //printf(" Long: %d, int %d, short %d\n", sizeof( long ), sizeof( int ), sizeof( short ) ); | 263 | //printf(" Long: %d, int %d, short %d\n", sizeof( long ), sizeof( int ), sizeof( short ) ); |
254 | //printf( "num chars %d\n", snprintf( NULL, 0, 0 ) ); | 264 | //printf( "num chars %d\n", snprintf( NULL, 0, 0 ) ); |
255 | //exit( 0 ); | 265 | //exit( 0 ); |
256 | Open_cPad(); | 266 | Open_cPad(); |
257 | 267 | ||
258 | #if 1 | 268 | #if 1 |
259 | int fd = open( "/dev/input/event0", O_RDONLY ); | 269 | int fd = open( "/dev/input/event0", O_RDONLY ); |
260 | 270 | ||
261 | if( fd == -1 ) | 271 | if( fd == -1 ) |
262 | { | 272 | { |
263 | printf( "Failed to open device\n" ); | 273 | printf( "Failed to open device\n" ); |
264 | goto hell; | 274 | goto hell; |
265 | } | 275 | } |
266 | 276 | ||
267 | struct input_event evbuf; | 277 | struct input_event evbuf; |
268 | 278 | ||
269 | for(;;) | 279 | for(;;) |
270 | { | 280 | { |
271 | if( read( fd, &evbuf, sizeof evbuf ) == -1 ) | 281 | if( read( fd, &evbuf, sizeof evbuf ) == -1 ) |
272 | { | 282 | { |
273 | printf( "Read error\n" ); | 283 | printf( "Read error\n" ); |
274 | goto hell; | 284 | goto hell; |
275 | } | 285 | } |
276 | 286 | ||
277 | printf( "Type: %d, Code: %d, Value: %d\n", evbuf.type, evbuf.code, evbuf.value ); | 287 | printf( "Type: %d, Code: %d, Value: %d\n", evbuf.type, evbuf.code, evbuf.value ); |