summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-02-04 16:51:11 (UTC)
committer mickeyl <mickeyl>2005-02-04 16:51:11 (UTC)
commit276022cd2a84f531bbf727c34d76420d8195512d (patch) (unidiff)
tree31c15ddb1cbed5e5a0db43e32af9066b424bab8c
parent5398d63dbd79eb166ab1c36517f60c6e850a2ca7 (diff)
downloadopie-276022cd2a84f531bbf727c34d76420d8195512d.zip
opie-276022cd2a84f531bbf727c34d76420d8195512d.tar.gz
opie-276022cd2a84f531bbf727c34d76420d8195512d.tar.bz2
show global key state
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp10
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,181 +1,191 @@
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
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 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
102using std::string; 112using std::string;
103 113
104const unsigned char BUT1 = 0x01; 114const unsigned char BUT1 = 0x01;
105const unsigned char BUT2 = 0x04; 115const unsigned char BUT2 = 0x04;
106const unsigned char BUT3 = 0x02; 116const unsigned char BUT3 = 0x02;
107const unsigned char BUT4 = 0x40; 117const unsigned char BUT4 = 0x40;
108const unsigned char BUT5 = 0x80; 118const 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
117int Open_cPad() 127int 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 )