summaryrefslogtreecommitdiff
path: root/examples
Unidiff
Diffstat (limited to 'examples') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp46
1 files changed, 26 insertions, 20 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
@@ -27,57 +27,82 @@
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
32using namespace Opie::Core; 32using 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
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>
72#include <string> 97#include <string>
73 98
74#include <sys/types.h> 99#include <sys/types.h>
75#include <linux/input.h> 100#include <linux/input.h>
76 101
77using std::string; 102using std::string;
78 103
79const unsigned char BUT1 = 0x01; 104const unsigned char BUT1 = 0x01;
80const unsigned char BUT2 = 0x04; 105const unsigned char BUT2 = 0x04;
81const unsigned char BUT3 = 0x02; 106const unsigned char BUT3 = 0x02;
82const unsigned char BUT4 = 0x40; 107const unsigned char BUT4 = 0x40;
83const unsigned char BUT5 = 0x80; 108const unsigned char BUT5 = 0x80;
@@ -117,67 +142,48 @@ int Open_cPad()
117 version >> 16, (version >> 8) & 0xff, 142 version >> 16, (version >> 8) & 0xff,
118 version & 0xff); 143 version & 0xff);
119 144
120 // Get Identifying info 145 // Get Identifying info
121 146
122 if( ioctl( fd, EVIOCGID, &info) ) 147 if( ioctl( fd, EVIOCGID, &info) )
123 { 148 {
124 perror( "event device ioctl" ); 149 perror( "event device ioctl" );
125 return -1; 150 return -1;
126 } 151 }
127 printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n", 152 printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n",
128 info.bustype, info.vendor, info.product, info.version ); 153 info.bustype, info.vendor, info.product, info.version );
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 )
172 { 178 {
173 if( TEST_BIT( features, bit ) ) 179 if( TEST_BIT( features, bit ) )
174 { 180 {
175 switch( bit ) 181 switch( bit )
176 { 182 {
177 case EV_SYN : 183 case EV_SYN :
178 printf(" Sync. Events\n"); 184 printf(" Sync. Events\n");
179 break; 185 break;
180 //case EV_RST: 186 //case EV_RST:
181 // printf( " Reset?\n" ); 187 // printf( " Reset?\n" );
182 // break; 188 // break;
183 case EV_KEY: 189 case EV_KEY: