author | mickeyl <mickeyl> | 2005-02-02 15:23:01 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-02-02 15:23:01 (UTC) |
commit | 227d06128b74ef78b8268e18dabe454469b65cc8 (patch) (unidiff) | |
tree | 64632ebff3bb6df1ba81ce1e70638cbce15de33c /examples | |
parent | 1a5dc271114432e0e598af499c076bfbf69ff972 (diff) | |
download | opie-227d06128b74ef78b8268e18dabe454469b65cc8.zip opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.gz opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.bz2 |
first work on input system abstractions
-rw-r--r-- | examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp index 89209a7..5450966 100644 --- a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp +++ b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | |||
@@ -1,48 +1,115 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | ||
4 | .=l. | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This program is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This program is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
18 | ..}^=.= = ; Library General Public License for more | ||
19 | ++= -. .` .: details. | ||
20 | : = ...= . :.=- | ||
21 | -. .:....=;==+<; You should have received a copy of the GNU | ||
22 | -_. . . )=. = Library General Public License along with | ||
23 | -- :-=` this library; see the file COPYING.LIB. | ||
24 | If not, write to the Free Software Foundation, | ||
25 | Inc., 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | */ | ||
28 | |||
29 | #include <opie2/odebug.h> | ||
30 | #include <opie2/oinputsystem.h> | ||
31 | |||
32 | using namespace Opie::Core; | ||
33 | |||
34 | #include <stdlib.h> | ||
35 | #include <stdio.h> | ||
36 | #include <unistd.h> | ||
37 | #include <sys/ioctl.h> | ||
38 | #include <sys/fcntl.h> | ||
39 | |||
40 | #if 1 | ||
41 | |||
42 | int main( int argc, char** argv ) | ||
43 | { | ||
44 | OInputSystem* sys = OInputSystem::instance(); | ||
45 | OInputSystem::DeviceIterator it = sys->iterator(); | ||
46 | |||
47 | OInputDevice* dev = 0; | ||
48 | |||
49 | while ( it.current() ) | ||
50 | { | ||
51 | odebug << "DEMO: OInputSystem contains Device '" << it.current()->name() << "'" << oendl; | ||
52 | |||
53 | dev = it.current(); | ||
54 | |||
55 | odebug << "========================================" | ||
56 | << "\nDevice: " << dev->name() | ||
57 | << "\nName: " << dev->identity() | ||
58 | << "\nPath: " << dev->path() | ||
59 | << "\nUniq: " << dev->uniq() | ||
60 | << oendl; | ||
61 | |||
62 | ++it; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | #else | ||
67 | |||
1 | #include <fcntl.h> | 68 | #include <fcntl.h> |
2 | #include <unistd.h> | 69 | #include <unistd.h> |
3 | #include <cstdlib> | 70 | #include <cstdlib> |
4 | #include <cstdio> | 71 | #include <cstdio> |
5 | #include <string> | 72 | #include <string> |
6 | 73 | ||
7 | #include <sys/types.h> | 74 | #include <sys/types.h> |
8 | #include <linux/input.h> | 75 | #include <linux/input.h> |
9 | 76 | ||
10 | using std::string; | 77 | using std::string; |
11 | 78 | ||
12 | const unsigned char BUT1 = 0x01; | 79 | const unsigned char BUT1 = 0x01; |
13 | const unsigned char BUT2 = 0x04; | 80 | const unsigned char BUT2 = 0x04; |
14 | const unsigned char BUT3 = 0x02; | 81 | const unsigned char BUT3 = 0x02; |
15 | const unsigned char BUT4 = 0x40; | 82 | const unsigned char BUT4 = 0x40; |
16 | const unsigned char BUT5 = 0x80; | 83 | const unsigned char BUT5 = 0x80; |
17 | 84 | ||
18 | #define BITMASK( name, numbits ) \ | 85 | #define BITMASK( name, numbits ) \ |
19 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | 86 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ |
20 | memset( name, 0, sizeof( name ) ) | 87 | memset( name, 0, sizeof( name ) ) |
21 | 88 | ||
22 | #define TEST_BIT( bitmask, bit ) \ | 89 | #define TEST_BIT( bitmask, bit ) \ |
23 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | 90 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) |
24 | 91 | ||
25 | int Open_cPad() | 92 | int Open_cPad() |
26 | { | 93 | { |
27 | size_t MAX_DEVICES = 1; | 94 | size_t MAX_DEVICES = 1; |
28 | int fd = -1; | 95 | int fd = -1; |
29 | input_id info; | 96 | input_id info; |
30 | 97 | ||
31 | for( size_t i = 0; i < MAX_DEVICES; ++i ) | 98 | for( size_t i = 0; i < MAX_DEVICES; ++i ) |
32 | { | 99 | { |
33 | string devpath( "/dev/input/event0" ); | 100 | string devpath( "/dev/input/event0" ); |
34 | 101 | ||
35 | //devpath << (int)i; | 102 | //devpath << (int)i; |
36 | 103 | ||
37 | fd = open( devpath.c_str(), O_RDONLY, &info ); | 104 | fd = open( devpath.c_str(), O_RDONLY, &info ); |
38 | 105 | ||
39 | if( fd >= 0 ) | 106 | if( fd >= 0 ) |
40 | { | 107 | { |
41 | int version = -1; | 108 | int version = -1; |
42 | /* ioctl() accesses the underlying driver */ | 109 | /* ioctl() accesses the underlying driver */ |
43 | if (ioctl(fd, EVIOCGVERSION, &version)) { | 110 | if (ioctl(fd, EVIOCGVERSION, &version)) { |
44 | perror("evdev ioctl"); | 111 | perror("evdev ioctl"); |
45 | } | 112 | } |
46 | 113 | ||
47 | /* the EVIOCGVERSION ioctl() returns an int */ | 114 | /* the EVIOCGVERSION ioctl() returns an int */ |
48 | /* so we unpack it and display it */ | 115 | /* so we unpack it and display it */ |
@@ -203,48 +270,49 @@ int main( int argc, char **argv ) | |||
203 | 270 | ||
204 | printf( "Type: %d, Code: %d, Value: %d\n", evbuf.type, evbuf.code, evbuf.value ); | 271 | printf( "Type: %d, Code: %d, Value: %d\n", evbuf.type, evbuf.code, evbuf.value ); |
205 | } | 272 | } |
206 | 273 | ||
207 | #endif | 274 | #endif |
208 | #if 0 | 275 | #if 0 |
209 | unsigned char buf[ 4 ]; | 276 | unsigned char buf[ 4 ]; |
210 | 277 | ||
211 | for(;;) | 278 | for(;;) |
212 | { | 279 | { |
213 | if( read( fd, buf, sizeof buf ) == -1 ) | 280 | if( read( fd, buf, sizeof buf ) == -1 ) |
214 | { | 281 | { |
215 | printf( "Read error\n" ); | 282 | printf( "Read error\n" ); |
216 | goto hell; | 283 | goto hell; |
217 | } | 284 | } |
218 | 285 | ||
219 | printf( "Raw:\t%#x\t%#x\t%#x\t%#x\n", buf[ 0 ], buf[ 1 ], buf[ 2 ], buf[ 3 ] ); | 286 | printf( "Raw:\t%#x\t%#x\t%#x\t%#x\n", buf[ 0 ], buf[ 1 ], buf[ 2 ], buf[ 3 ] ); |
220 | 287 | ||
221 | int dx = buf[ 1 ]; | 288 | int dx = buf[ 1 ]; |
222 | 289 | ||
223 | if( ( buf[ 0 ] & 0x10 ) != 0 ) | 290 | if( ( buf[ 0 ] & 0x10 ) != 0 ) |
224 | dx -= 256; | 291 | dx -= 256; |
225 | 292 | ||
226 | int dy = - buf[ 2 ]; | 293 | int dy = - buf[ 2 ]; |
227 | 294 | ||
228 | if( ( buf[ 0 ] & 0x20 ) != 0 ) | 295 | if( ( buf[ 0 ] & 0x20 ) != 0 ) |
229 | dy += 256; | 296 | dy += 256; |
230 | 297 | ||
231 | printf( "( %d, %d )\t", dx, dy ); | 298 | printf( "( %d, %d )\t", dx, dy ); |
232 | 299 | ||
233 | if( buf[ 0 ] & BUT1 ) | 300 | if( buf[ 0 ] & BUT1 ) |
234 | printf( "Left\t" ); | 301 | printf( "Left\t" ); |
235 | if( buf[ 0 ] & BUT2 ) | 302 | if( buf[ 0 ] & BUT2 ) |
236 | printf( "Middle\t" ); | 303 | printf( "Middle\t" ); |
237 | if( buf[ 0 ] & BUT3 ) | 304 | if( buf[ 0 ] & BUT3 ) |
238 | printf( "Right\t" ); | 305 | printf( "Right\t" ); |
239 | 306 | ||
240 | printf( "\n" ); | 307 | printf( "\n" ); |
241 | } | 308 | } |
242 | #endif | 309 | #endif |
243 | 310 | ||
244 | //close( fd ); | 311 | //close( fd ); |
245 | 312 | ||
246 | exit( EXIT_SUCCESS ); | 313 | exit( EXIT_SUCCESS ); |
247 | hell: | 314 | hell: |
248 | exit( EXIT_FAILURE ); | 315 | exit( EXIT_FAILURE ); |
249 | } | 316 | } |
250 | 317 | ||
318 | #endif \ No newline at end of file | ||