summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-02-02 15:23:01 (UTC)
committer mickeyl <mickeyl>2005-02-02 15:23:01 (UTC)
commit227d06128b74ef78b8268e18dabe454469b65cc8 (patch) (unidiff)
tree64632ebff3bb6df1ba81ce1e70638cbce15de33c
parent1a5dc271114432e0e598af499c076bfbf69ff972 (diff)
downloadopie-227d06128b74ef78b8268e18dabe454469b65cc8.zip
opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.gz
opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.bz2
first work on input system abstractions
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp68
-rw-r--r--libopie2/opiecore/oinputsystem.cpp113
-rw-r--r--libopie2/opiecore/oinputsystem.h108
-rw-r--r--libopie2/opiemm/osoundsystem.h4
4 files changed, 286 insertions, 7 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,250 +1,318 @@
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
32using 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
42int 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
10using std::string; 77using std::string;
11 78
12const unsigned char BUT1 = 0x01; 79const unsigned char BUT1 = 0x01;
13const unsigned char BUT2 = 0x04; 80const unsigned char BUT2 = 0x04;
14const unsigned char BUT3 = 0x02; 81const unsigned char BUT3 = 0x02;
15const unsigned char BUT4 = 0x40; 82const unsigned char BUT4 = 0x40;
16const unsigned char BUT5 = 0x80; 83const 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
25int Open_cPad() 92int 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 */
49 printf("evdev driver version is %d.%d.%d\n", 116 printf("evdev driver version is %d.%d.%d\n",
50 version >> 16, (version >> 8) & 0xff, 117 version >> 16, (version >> 8) & 0xff,
51 version & 0xff); 118 version & 0xff);
52 119
53 // Get Identifying info 120 // Get Identifying info
54 121
55 if( ioctl( fd, EVIOCGID, &info) ) 122 if( ioctl( fd, EVIOCGID, &info) )
56 { 123 {
57 perror( "event device ioctl" ); 124 perror( "event device ioctl" );
58 return -1; 125 return -1;
59 } 126 }
60 printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n", 127 printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n",
61 info.bustype, info.vendor, info.product, info.version ); 128 info.bustype, info.vendor, info.product, info.version );
62 129
63 switch ( info.bustype) 130 switch ( info.bustype)
64 { 131 {
65 case BUS_PCI : 132 case BUS_PCI :
66 printf(" is on a PCI bus\n"); 133 printf(" is on a PCI bus\n");
67 break; 134 break;
68 case BUS_USB : 135 case BUS_USB :
69 printf(" is on a Universal Serial Bus\n"); 136 printf(" is on a Universal Serial Bus\n");
70 break; 137 break;
71 /* ... */ 138 /* ... */
72 } 139 }
73 140
74 // Get device 'name' 141 // Get device 'name'
75 142
76 char name[256] = "Unknown"; 143 char name[256] = "Unknown";
77 if( ioctl( fd, EVIOCGNAME(sizeof name ), name) < 0 ) 144 if( ioctl( fd, EVIOCGNAME(sizeof name ), name) < 0 )
78 { 145 {
79 perror( "event device ioctl" ); 146 perror( "event device ioctl" );
80 }else 147 }else
81 printf( "Device name '%s'\n", name ); 148 printf( "Device name '%s'\n", name );
82 149
83 if(ioctl(fd, EVIOCGPHYS(sizeof(name)), name) < 0) { 150 if(ioctl(fd, EVIOCGPHYS(sizeof(name)), name) < 0) {
84 perror("event ioctl"); 151 perror("event ioctl");
85 }else 152 }else
86 printf("Device path '%s'\n", name ); 153 printf("Device path '%s'\n", name );
87 154
88 if(ioctl(fd, EVIOCGUNIQ(sizeof(name)), name) < 0) { 155 if(ioctl(fd, EVIOCGUNIQ(sizeof(name)), name) < 0) {
89 perror("event ioctl"); 156 perror("event ioctl");
90 }else 157 }else
91 printf("Device identity '%s'\n", name ); 158 printf("Device identity '%s'\n", name );
92 159
93 // Get feature types 160 // Get feature types
94 161
95 BITMASK( features, EV_MAX ); 162 BITMASK( features, EV_MAX );
96 163
97 if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) 164 if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 )
98 { 165 {
99 perror( "event device ioctl" ); 166 perror( "event device ioctl" );
100 return -1; 167 return -1;
101 } 168 }
102 169
103 printf( "Supported features:\n" ); 170 printf( "Supported features:\n" );
104 for( size_t bit = 0; bit < EV_MAX; ++bit ) 171 for( size_t bit = 0; bit < EV_MAX; ++bit )
105 { 172 {
106 if( TEST_BIT( features, bit ) ) 173 if( TEST_BIT( features, bit ) )
107 { 174 {
108 switch( bit ) 175 switch( bit )
109 { 176 {
110 case EV_SYN : 177 case EV_SYN :
111 printf(" Sync. Events\n"); 178 printf(" Sync. Events\n");
112 break; 179 break;
113 //case EV_RST: 180 //case EV_RST:
114 // printf( " Reset?\n" ); 181 // printf( " Reset?\n" );
115 // break; 182 // break;
116 case EV_KEY: 183 case EV_KEY:
117 printf( " Keys or buttons\n" ); 184 printf( " Keys or buttons\n" );
118 break; 185 break;
119 case EV_REL: 186 case EV_REL:
120 printf( " Relative axes\n" ); 187 printf( " Relative axes\n" );
121 break; 188 break;
122 case EV_ABS: 189 case EV_ABS:
123 printf( " Absolute axes\n" ); 190 printf( " Absolute axes\n" );
124 break; 191 break;
125 case EV_MSC: 192 case EV_MSC:
126 printf( " Misc\n" ); 193 printf( " Misc\n" );
127 break; 194 break;
128 case EV_LED: 195 case EV_LED:
129 printf( " Led's\n" ); 196 printf( " Led's\n" );
130 break; 197 break;
131 case EV_SND: 198 case EV_SND:
132 printf( " Sounds\n" ); 199 printf( " Sounds\n" );
133 break; 200 break;
134 case EV_REP: 201 case EV_REP:
135 printf( " Repeat\n" ); 202 printf( " Repeat\n" );
136 break; 203 break;
137 case EV_FF : // fallthrough 204 case EV_FF : // fallthrough
138 case EV_FF_STATUS: 205 case EV_FF_STATUS:
139 printf(" Force Feedback\n"); 206 printf(" Force Feedback\n");
140 break; 207 break;
141 case EV_PWR: 208 case EV_PWR:
142 printf(" Power Management\n"); 209 printf(" Power Management\n");
143 break; 210 break;
144 default: 211 default:
145 printf( " Unknown (bit %d)\n", bit ); 212 printf( " Unknown (bit %d)\n", bit );
146 } 213 }
147 } 214 }
148 } 215 }
149 216
150 // Check keystate 217 // Check keystate
151 218
152 BITMASK( keys, KEY_MAX ); 219 BITMASK( keys, KEY_MAX );
153 220
154 if( ioctl( fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) 221 if( ioctl( fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 )
155 { 222 {
156 perror( "event device ioctl" ); 223 perror( "event device ioctl" );
157 return -1; 224 return -1;
158 } 225 }
159 226
160 printf( "Key global status:\n" ); 227 printf( "Key global status:\n" );
161 for( size_t bit = 0; bit < KEY_MAX; ++bit ) 228 for( size_t bit = 0; bit < KEY_MAX; ++bit )
162 { 229 {
163 if( TEST_BIT( keys, bit ) ) 230 if( TEST_BIT( keys, bit ) )
164 { 231 {
165 printf( "Key (bit %d) active\n", bit ); 232 printf( "Key (bit %d) active\n", bit );
166 } 233 }
167 } 234 }
168 } 235 }
169 else 236 else
170 printf( "Failed to open device\n" ); 237 printf( "Failed to open device\n" );
171 238
172 close( fd ); 239 close( fd );
173 } 240 }
174 return fd; 241 return fd;
175} 242}
176 243
177 244
178int main( int argc, char **argv ) 245int main( int argc, char **argv )
179{ 246{
180 //printf(" Long: %d, int %d, short %d\n", sizeof( long ), sizeof( int ), sizeof( short ) ); 247 //printf(" Long: %d, int %d, short %d\n", sizeof( long ), sizeof( int ), sizeof( short ) );
181 //printf( "num chars %d\n", snprintf( NULL, 0, 0 ) ); 248 //printf( "num chars %d\n", snprintf( NULL, 0, 0 ) );
182 //exit( 0 ); 249 //exit( 0 );
183 Open_cPad(); 250 Open_cPad();
184 251
185#if 1 252#if 1
186 int fd = open( "/dev/input/event0", O_RDONLY ); 253 int fd = open( "/dev/input/event0", O_RDONLY );
187 254
188 if( fd == -1 ) 255 if( fd == -1 )
189 { 256 {
190 printf( "Failed to open device\n" ); 257 printf( "Failed to open device\n" );
191 goto hell; 258 goto hell;
192 } 259 }
193 260
194 struct input_event evbuf; 261 struct input_event evbuf;
195 262
196 for(;;) 263 for(;;)
197 { 264 {
198 if( read( fd, &evbuf, sizeof evbuf ) == -1 ) 265 if( read( fd, &evbuf, sizeof evbuf ) == -1 )
199 { 266 {
200 printf( "Read error\n" ); 267 printf( "Read error\n" );
201 goto hell; 268 goto hell;
202 } 269 }
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 );
247hell: 314hell:
248 exit( EXIT_FAILURE ); 315 exit( EXIT_FAILURE );
249} 316}
250 317
318#endif \ No newline at end of file
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp
index c33d5c8..bfdc31f 100644
--- a/libopie2/opiecore/oinputsystem.cpp
+++ b/libopie2/opiecore/oinputsystem.cpp
@@ -1,31 +1,142 @@
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 "oinputsystem.h" 29#include "oinputsystem.h"
30
31using namespace Opie::Core; 30using namespace Opie::Core;
31
32/* QT */
33#include <qfile.h>
34
35/* STD */
36#include <errno.h>
37#include <string.h>
38#include <linux/input.h>
39#include <sys/fcntl.h>
40#include <sys/ioctl.h>
41
42#define BUFSIZE 256
43
44/*======================================================================================
45 * OInputSystem
46 *======================================================================================*/
47
48OInputSystem* OInputSystem::_instance = 0;
49
50OInputSystem::OInputSystem() : QObject()
51{
52 qDebug( "OInputSystem::OInputSystem()" );
53 synchronize();
54}
55
56
57void OInputSystem::synchronize()
58{
59 qDebug( "OInputSystem::synchronize()" );
60 if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) );
61 if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) );
62 if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) );
63 if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) );
64 qDebug( "OInputSystem::synchronize() done" );
65}
66
67
68OInputSystem::~OInputSystem()
69{
70 qDebug( "OInputSystem::~OInputSystem()" );
71}
72
73
74int OInputSystem::count() const
75{
76 return _devices.count();
77}
78
79
80OInputDevice* OInputSystem::device( const QString& device ) const
81{
82 return _devices[device];
83}
84
85
86OInputSystem* OInputSystem::instance()
87{
88 if ( !_instance ) _instance = new OInputSystem();
89 return _instance;
90}
91
92
93OInputSystem::DeviceIterator OInputSystem::iterator() const
94{
95 return OInputSystem::DeviceIterator( _devices );
96}
97
98/*======================================================================================
99 * OInputDevice
100 *======================================================================================*/
101
102OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name )
103{
104 qDebug( "OInputDevice::OInputDevice( '%s' )", name );
105
106 _fd = ::open( name, O_RDONLY );
107 if ( _fd == -1 )
108 {
109 qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) );
110 }
111}
112
113
114OInputDevice::~OInputDevice()
115{
116 qDebug( "OInputDevice::~OInputDevice()" );
117}
118
119
120QString OInputDevice::identity() const
121{
122 char buf[BUFSIZE] = "<unknown>";
123 ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf );
124 return buf;
125}
126
127
128QString OInputDevice::path() const
129{
130 char buf[BUFSIZE] = "<unknown>";
131 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf );
132 return buf;
133}
134
135
136QString OInputDevice::uniq() const
137{
138 char buf[BUFSIZE] = "<unknown>";
139 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf );
140 return buf;
141}
142
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/oinputsystem.h
index 2bcdc3a..350656b 100644
--- a/libopie2/opiecore/oinputsystem.h
+++ b/libopie2/opiecore/oinputsystem.h
@@ -1,48 +1,148 @@
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#ifndef OINPUTSYSTEM_H 29#ifndef OINPUTSYSTEM_H
30#define OINPUTSYSTEM_H 30#define OINPUTSYSTEM_H
31 31
32/* QT */
32#include <qobject.h> 33#include <qobject.h>
34#include <qdict.h>
35
36/* STD */
37#include <linux/input.h>
33 38
34namespace Opie { 39namespace Opie {
35namespace Core { 40namespace Core {
36 41
37/** 42class OInputDevice;
38 * ...
39 *
40 */
41 43
44/**
45 * @brief A container class for all input devices
46 *
47 * This class provides access to all available input system devices of your computer.
48 *
49 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
50 */
42class OInputSystem : public QObject 51class OInputSystem : public QObject
43{ 52{
53 public:
54 typedef QDict<OInputDevice> DeviceMap;
55 typedef QDictIterator<OInputDevice> DeviceIterator;
56
57 /**
58 * @returns the number of available input devices
59 */
60 int count() const;
61 /**
62 * @returns a pointer to the (one and only) @ref OInputSystem instance.
63 */
64 static OInputSystem* instance();
65 /**
66 * @returns an iterator usable for iterating through all network interfaces.
67 */
68 DeviceIterator iterator() const;
69 /**
70 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
71 * @see OAudioInterface
72 */
73 OInputDevice* device( const QString& interface ) const;
74 /**
75 * @internal Rebuild the internal interface database
76 * @note Sometimes it might be useful to call this from client code,
77 */
78 void synchronize();
79 /**
80 * @internal desctructor
81 */
82 ~OInputSystem();
83
84 protected:
85 OInputSystem();
86
87 static OInputSystem* _instance;
88 DeviceMap _devices;
89};
90
91
92class OInputDevice : public QObject
93{
94 public:
95
96 enum EventType
97 {
98 Synchronous = EV_SYN,
99 Keyboard = EV_KEY,
100 Relative = EV_REL,
101 Absolute = EV_ABS,
102 Miscellaneous = EV_MSC,
103 Led = EV_LED,
104 Sound = EV_SND,
105 AutoRepeat = EV_REP,
106 ForceFeedback = EV_FF,
107 PowerManagement = EV_PWR,
108 ForceFeedbackStatus = EV_FF_STATUS,
109 };
110
111 enum Bus
112 {
113 PCI = BUS_PCI,
114 ISAPNP = BUS_ISAPNP,
115 HIL = BUS_HIL,
116 BLUETOOTH = BUS_BLUETOOTH,
117 ISA = BUS_ISA,
118 I8042 = BUS_I8042,
119 XTKBD = BUS_XTKBD,
120 RS232 = BUS_RS232,
121 GAMEPORT = BUS_GAMEPORT,
122 PARPORT = BUS_PARPORT,
123 AMIGA = BUS_AMIGA,
124 ADB = BUS_ADB,
125 I2C = BUS_I2C,
126 HOST = BUS_HOST,
127 };
128
129 public:
130 OInputDevice( QObject* parent, const char* name = 0 );
131 ~OInputDevice();
132
133 public:
134 QString identity() const;
135 QString path() const;
136 QString uniq() const;
137
138 private:
139 int _fd;
140 input_id _id;
141
44}; 142};
143
45} 144}
46} 145}
47 146
48#endif // OINPUTSYSTEM_H 147#endif // OINPUTSYSTEM_H
148
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h
index cce90c0..5f6fb7a 100644
--- a/libopie2/opiemm/osoundsystem.h
+++ b/libopie2/opiemm/osoundsystem.h
@@ -1,202 +1,202 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#ifndef OSOUNDSYSTEM_H 31#ifndef OSOUNDSYSTEM_H
32#define OSOUNDSYSTEM_H 32#define OSOUNDSYSTEM_H
33 33
34#include <qobject.h> 34#include <qobject.h>
35#include <qdict.h> 35#include <qdict.h>
36#include <qmap.h> 36#include <qmap.h>
37 37
38namespace Opie { 38namespace Opie {
39namespace MM { 39namespace MM {
40 40
41class OAudioInterface; 41class OAudioInterface;
42class OMixerInterface; 42class OMixerInterface;
43class OSoundCard; 43class OSoundCard;
44 44
45/*====================================================================================== 45/*======================================================================================
46 * OSoundSystem 46 * OSoundSystem
47 *======================================================================================*/ 47 *======================================================================================*/
48 48
49/** 49/**
50 * @brief A container class for all audio interfaces 50 * @brief A container class for all audio interfaces
51 * 51 *
52 * This class provides access to all available audio/midi/sequencer interfaces of your computer. 52 * This class provides access to all available audio/midi/sequencer interfaces of your computer.
53 * 53 *
54 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 54 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
55 */ 55 */
56class OSoundSystem : public QObject 56class OSoundSystem : public QObject
57{ 57{
58 Q_OBJECT 58 Q_OBJECT
59 59
60 public: 60 public:
61 typedef QDict<OSoundCard> CardMap; 61 typedef QDict<OSoundCard> CardMap;
62 typedef QDictIterator<OSoundCard> CardIterator; 62 typedef QDictIterator<OSoundCard> CardIterator;
63 63
64 public: 64 public:
65 /** 65 /**
66 * @returns the number of available interfaces 66 * @returns the number of available interfaces
67 */ 67 */
68 int count() const; 68 int count() const;
69 /** 69 /**
70 * @returns a pointer to the (one and only) @ref ONetwork instance. 70 * @returns a pointer to the (one and only) @ref OSystem instance.
71 */ 71 */
72 static OSoundSystem* instance(); 72 static OSoundSystem* instance();
73 /** 73 /**
74 * @returns an iterator usable for iterating through all network interfaces. 74 * @returns an iterator usable for iterating through all sound cards.
75 */ 75 */
76 CardIterator iterator() const; 76 CardIterator iterator() const;
77 /** 77 /**
78 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found 78 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
79 * @see OAudioInterface 79 * @see OAudioInterface
80 */ 80 */
81 OSoundCard* card( const QString& interface ) const; 81 OSoundCard* card( const QString& interface ) const;
82 /** 82 /**
83 * @internal Rebuild the internal interface database 83 * @internal Rebuild the internal interface database
84 * @note Sometimes it might be useful to call this from client code, 84 * @note Sometimes it might be useful to call this from client code,
85 * e.g. after issuing a cardctl insert 85 * e.g. after issuing a cardctl insert
86 */ 86 */
87 void synchronize(); 87 void synchronize();
88 88
89 protected: 89 protected:
90 OSoundSystem(); 90 OSoundSystem();
91 91
92 private: 92 private:
93 static OSoundSystem* _instance; 93 static OSoundSystem* _instance;
94 CardMap _interfaces; 94 CardMap _interfaces;
95 class Private; 95 class Private;
96 Private *d; 96 Private *d;
97}; 97};
98 98
99 99
100/*====================================================================================== 100/*======================================================================================
101 * OSoundCard 101 * OSoundCard
102 *======================================================================================*/ 102 *======================================================================================*/
103 103
104class OSoundCard : public QObject 104class OSoundCard : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 /** 109 /**
110 * Constructor. Normally you don't create @ref OSoundCard objects yourself, 110 * Constructor. Normally you don't create @ref OSoundCard objects yourself,
111 * but access them via @ref OSoundSystem::card(). 111 * but access them via @ref OSoundSystem::card().
112 */ 112 */
113 OSoundCard( QObject* parent, const char* name ); 113 OSoundCard( QObject* parent, const char* name );
114 /** 114 /**
115 * Destructor. 115 * Destructor.
116 */ 116 */
117 virtual ~OSoundCard(); 117 virtual ~OSoundCard();
118 118
119 bool hasMixer() const { return _audio; }; 119 bool hasMixer() const { return _audio; };
120 bool hasAudio() const { return _mixer; }; 120 bool hasAudio() const { return _mixer; };
121 121
122 OAudioInterface* audio() const { return _audio; }; 122 OAudioInterface* audio() const { return _audio; };
123 OMixerInterface* mixer() const { return _mixer; }; 123 OMixerInterface* mixer() const { return _mixer; };
124 124
125 protected: 125 protected:
126 OAudioInterface* _audio; 126 OAudioInterface* _audio;
127 OMixerInterface* _mixer; 127 OMixerInterface* _mixer;
128 128
129 private: 129 private:
130 void init(); 130 void init();
131 private: 131 private:
132 class Private; 132 class Private;
133 Private *d; 133 Private *d;
134}; 134};
135 135
136/*====================================================================================== 136/*======================================================================================
137 * OAudioInterface 137 * OAudioInterface
138 *======================================================================================*/ 138 *======================================================================================*/
139 139
140class OAudioInterface : public QObject 140class OAudioInterface : public QObject
141{ 141{
142 Q_OBJECT 142 Q_OBJECT
143 143
144 public: 144 public:
145 /** 145 /**
146 * Constructor. Normally you don't create @ref OAudioInterface objects yourself, 146 * Constructor. Normally you don't create @ref OAudioInterface objects yourself,
147 * but access them via the @ref OSoundCard interface. 147 * but access them via the @ref OSoundCard interface.
148 */ 148 */
149 OAudioInterface( QObject* parent, const char* name ); 149 OAudioInterface( QObject* parent, const char* name );
150 /** 150 /**
151 * Destructor. 151 * Destructor.
152 */ 152 */
153 virtual ~OAudioInterface(); 153 virtual ~OAudioInterface();
154 154
155 protected: 155 protected:
156 const int _sfd; 156 const int _sfd;
157 157
158 private: 158 private:
159 void init(); 159 void init();
160 private: 160 private:
161 class Private; 161 class Private;
162 Private *d; 162 Private *d;
163}; 163};
164 164
165 165
166/*====================================================================================== 166/*======================================================================================
167 * OMixerInterface 167 * OMixerInterface
168 *======================================================================================*/ 168 *======================================================================================*/
169 169
170class OMixerInterface : public QObject 170class OMixerInterface : public QObject
171{ 171{
172 Q_OBJECT 172 Q_OBJECT
173 173
174 public: 174 public:
175 175
176 typedef QMap<QString,int>::ConstIterator ChannelIterator; 176 typedef QMap<QString,int>::ConstIterator ChannelIterator;
177 177
178 /** 178 /**
179 * Constructor. Normally you don't create @ref OMixerInterface objects yourself, 179 * Constructor. Normally you don't create @ref OMixerInterface objects yourself,
180 * but access them via the @ref OSoundCard interface. 180 * but access them via the @ref OSoundCard interface.
181 */ 181 */
182 OMixerInterface( QObject* parent, const char* name ); 182 OMixerInterface( QObject* parent, const char* name );
183 /** 183 /**
184 * Destructor. 184 * Destructor.
185 */ 185 */
186 virtual ~OMixerInterface(); 186 virtual ~OMixerInterface();
187 187
188 /** 188 /**
189 * @returns all available channels. 189 * @returns all available channels.
190 */ 190 */
191 QStringList allChannels() const; 191 QStringList allChannels() const;
192 /** 192 /**
193 * @returns recordable channels. 193 * @returns recordable channels.
194 */ 194 */
195 QStringList recChannels() const; 195 QStringList recChannels() const;
196 /** 196 /**
197 * @returns playable channels. 197 * @returns playable channels.
198 */ 198 */
199 QStringList playChannels() const; 199 QStringList playChannels() const;
200 /** 200 /**
201 * @returns true, if the device features multiple recording sources. 201 * @returns true, if the device features multiple recording sources.
202 */ 202 */