summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp46
-rw-r--r--libopie2/opiecore/oinputsystem.cpp17
-rw-r--r--libopie2/opiecore/oinputsystem.h7
3 files changed, 46 insertions, 24 deletions
diff --git a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp
index 5450966..a9c0fd2 100644
--- a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp
+++ b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp
@@ -39,33 +39,58 @@ using namespace Opie::Core;
39 39
40#if 1 40#if 1
41 41
42int main( int argc, char** argv ) 42int 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 Device '" << 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;
56 features += QString( "\nSynchronous: " );
57 if ( dev->hasFeature( OInputDevice::Synchronous ) ) features += "[ x ]"; else features += "[ ]";
58 features += QString( "\nKeys or Buttons: " );
59 if ( dev->hasFeature( OInputDevice::Keys ) ) features += "[ x ]"; else features += "[ ]";
60 features += QString( "\nRelative Axes: " );
61 if ( dev->hasFeature( OInputDevice::Relative ) ) features += "[ x ]"; else features += "[ ]";
62 features += QString( "\nAbsolute Axes: " );
63 if ( dev->hasFeature( OInputDevice::Absolute ) ) features += "[ x ]"; else features += "[ ]";
64 features += QString( "\nMiscellaneous: " );
65 if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) features += "[ x ]"; else features += "[ ]";
66 features += QString( "\nLeds: " );
67 if ( dev->hasFeature( OInputDevice::Leds ) ) features += "[ x ]"; else features += "[ ]";
68 features += QString( "\nSound: " );
69 if ( dev->hasFeature( OInputDevice::Sound ) ) features += "[ x ]"; else features += "[ ]";
70 features += QString( "\nAutoRepeat " );
71 if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) features += "[ x ]"; else features += "[ ]";
72 features += QString( "\nForceFeedback: " );
73 if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) features += "[ x ]"; else features += "[ ]";
74 features += QString( "\nPowerManagement: " );
75 if ( dev->hasFeature( OInputDevice::PowerManagement ) ) features += "[ x ]"; else features += "[ ]";
76 features += QString( "\nFeedbackStatus: " );
77 if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) features += "[ x ]"; else features += "[ ]";
78
55 odebug << "========================================" 79 odebug << "========================================"
56 << "\nDevice: " << dev->name() 80 << "\nDevice: " << dev->name()
57 << "\nName: " << dev->identity() 81 << "\nName: " << dev->identity()
58 << "\nPath: " << dev->path() 82 << "\nPath: " << dev->path()
59 << "\nUniq: " << dev->uniq() 83 << "\nUniq: " << dev->uniq()
84 << features << "\n"
60 << oendl; 85 << oendl;
61 86
62 ++it; 87 ++it;
63 } 88 }
64} 89}
65 90
66#else 91#else
67 92
68#include <fcntl.h> 93#include <fcntl.h>
69#include <unistd.h> 94#include <unistd.h>
70#include <cstdlib> 95#include <cstdlib>
71#include <cstdio> 96#include <cstdio>
@@ -129,43 +154,24 @@ int Open_cPad()
129 154
130 switch ( info.bustype) 155 switch ( info.bustype)
131 { 156 {
132 case BUS_PCI : 157 case BUS_PCI :
133 printf(" is on a PCI bus\n"); 158 printf(" is on a PCI bus\n");
134 break; 159 break;
135 case BUS_USB : 160 case BUS_USB :
136 printf(" is on a Universal Serial Bus\n"); 161 printf(" is on a Universal Serial Bus\n");
137 break; 162 break;
138 /* ... */ 163 /* ... */
139 } 164 }
140 165
141 // Get device 'name'
142
143 char name[256] = "Unknown";
144 if( ioctl( fd, EVIOCGNAME(sizeof name ), name) < 0 )
145 {
146 perror( "event device ioctl" );
147 }else
148 printf( "Device name '%s'\n", name );
149
150 if(ioctl(fd, EVIOCGPHYS(sizeof(name)), name) < 0) {
151 perror("event ioctl");
152 }else
153 printf("Device path '%s'\n", name );
154
155 if(ioctl(fd, EVIOCGUNIQ(sizeof(name)), name) < 0) {
156 perror("event ioctl");
157 }else
158 printf("Device identity '%s'\n", name );
159
160 // Get feature types 166 // Get feature types
161 167
162 BITMASK( features, EV_MAX ); 168 BITMASK( features, EV_MAX );
163 169
164 if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) 170 if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 )
165 { 171 {
166 perror( "event device ioctl" ); 172 perror( "event device ioctl" );
167 return -1; 173 return -1;
168 } 174 }
169 175
170 printf( "Supported features:\n" ); 176 printf( "Supported features:\n" );
171 for( size_t bit = 0; bit < EV_MAX; ++bit ) 177 for( size_t bit = 0; bit < EV_MAX; ++bit )
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp
index bfdc31f..fde36c3 100644
--- a/libopie2/opiecore/oinputsystem.cpp
+++ b/libopie2/opiecore/oinputsystem.cpp
@@ -30,25 +30,30 @@
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32/* QT */ 32/* QT */
33#include <qfile.h> 33#include <qfile.h>
34 34
35/* STD */ 35/* STD */
36#include <errno.h> 36#include <errno.h>
37#include <string.h> 37#include <string.h>
38#include <linux/input.h> 38#include <linux/input.h>
39#include <sys/fcntl.h> 39#include <sys/fcntl.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41 41
42#define BUFSIZE 256 42#define BUFSIZE 256
43#define BIT_MASK( name, numbits ) \
44 unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \
45 memset( name, 0, sizeof( name ) )
46#define BIT_TEST( bitmask, bit ) \
47 ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) )
43 48
44/*====================================================================================== 49/*======================================================================================
45 * OInputSystem 50 * OInputSystem
46 *======================================================================================*/ 51 *======================================================================================*/
47 52
48OInputSystem* OInputSystem::_instance = 0; 53OInputSystem* OInputSystem::_instance = 0;
49 54
50OInputSystem::OInputSystem() : QObject() 55OInputSystem::OInputSystem() : QObject()
51{ 56{
52 qDebug( "OInputSystem::OInputSystem()" ); 57 qDebug( "OInputSystem::OInputSystem()" );
53 synchronize(); 58 synchronize();
54} 59}
@@ -131,12 +136,22 @@ QString OInputDevice::path() const
131 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); 136 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf );
132 return buf; 137 return buf;
133} 138}
134 139
135 140
136QString OInputDevice::uniq() const 141QString OInputDevice::uniq() const
137{ 142{
138 char buf[BUFSIZE] = "<unknown>"; 143 char buf[BUFSIZE] = "<unknown>";
139 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); 144 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf );
140 return buf; 145 return buf;
141} 146}
142 147
148bool OInputDevice::hasFeature( Feature bit ) const
149{
150 BIT_MASK( features, EV_MAX );
151
152 if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 )
153 return false;
154 else
155 return BIT_TEST( features, bit );
156}
157
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/oinputsystem.h
index 350656b..4d913a1 100644
--- a/libopie2/opiecore/oinputsystem.h
+++ b/libopie2/opiecore/oinputsystem.h
@@ -84,32 +84,32 @@ class OInputSystem : public QObject
84 protected: 84 protected:
85 OInputSystem(); 85 OInputSystem();
86 86
87 static OInputSystem* _instance; 87 static OInputSystem* _instance;
88 DeviceMap _devices; 88 DeviceMap _devices;
89}; 89};
90 90
91 91
92class OInputDevice : public QObject 92class OInputDevice : public QObject
93{ 93{
94 public: 94 public:
95 95
96 enum EventType 96 enum Feature
97 { 97 {
98 Synchronous = EV_SYN, 98 Synchronous = EV_SYN,
99 Keyboard = EV_KEY, 99 Keys = EV_KEY,
100 Relative = EV_REL, 100 Relative = EV_REL,
101 Absolute = EV_ABS, 101 Absolute = EV_ABS,
102 Miscellaneous = EV_MSC, 102 Miscellaneous = EV_MSC,
103 Led = EV_LED, 103 Leds = EV_LED,
104 Sound = EV_SND, 104 Sound = EV_SND,
105 AutoRepeat = EV_REP, 105 AutoRepeat = EV_REP,
106 ForceFeedback = EV_FF, 106 ForceFeedback = EV_FF,
107 PowerManagement = EV_PWR, 107 PowerManagement = EV_PWR,
108 ForceFeedbackStatus = EV_FF_STATUS, 108 ForceFeedbackStatus = EV_FF_STATUS,
109 }; 109 };
110 110
111 enum Bus 111 enum Bus
112 { 112 {
113 PCI = BUS_PCI, 113 PCI = BUS_PCI,
114 ISAPNP = BUS_ISAPNP, 114 ISAPNP = BUS_ISAPNP,
115 HIL = BUS_HIL, 115 HIL = BUS_HIL,
@@ -125,24 +125,25 @@ class OInputDevice : public QObject
125 I2C = BUS_I2C, 125 I2C = BUS_I2C,
126 HOST = BUS_HOST, 126 HOST = BUS_HOST,
127 }; 127 };
128 128
129 public: 129 public:
130 OInputDevice( QObject* parent, const char* name = 0 ); 130 OInputDevice( QObject* parent, const char* name = 0 );
131 ~OInputDevice(); 131 ~OInputDevice();
132 132
133 public: 133 public:
134 QString identity() const; 134 QString identity() const;
135 QString path() const; 135 QString path() const;
136 QString uniq() const; 136 QString uniq() const;
137 bool hasFeature( Feature ) const;
137 138
138 private: 139 private:
139 int _fd; 140 int _fd;
140 input_id _id; 141 input_id _id;
141 142
142}; 143};
143 144
144} 145}
145} 146}
146 147
147#endif // OINPUTSYSTEM_H 148#endif // OINPUTSYSTEM_H
148 149