-rw-r--r-- | examples/opiecore/oinputsystemdemo/.cvsignore | 6 | ||||
-rw-r--r-- | examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | 250 | ||||
-rw-r--r-- | examples/opiecore/oinputsystemdemo/oinputsystemdemo.pro | 16 | ||||
-rw-r--r-- | examples/opiecore/onotifydemo/onotifydemo.pro | 1 | ||||
-rw-r--r-- | examples/opiecore/opiecore.pro | 2 |
5 files changed, 273 insertions, 2 deletions
diff --git a/examples/opiecore/oinputsystemdemo/.cvsignore b/examples/opiecore/oinputsystemdemo/.cvsignore new file mode 100644 index 0000000..8f7300c --- a/dev/null +++ b/examples/opiecore/oinputsystemdemo/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
3 | *moc | ||
4 | *.o | ||
5 | ~* | ||
6 | |||
diff --git a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp new file mode 100644 index 0000000..89209a7 --- a/dev/null +++ b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.cpp | |||
@@ -0,0 +1,250 @@ | |||
1 | #include <fcntl.h> | ||
2 | #include <unistd.h> | ||
3 | #include <cstdlib> | ||
4 | #include <cstdio> | ||
5 | #include <string> | ||
6 | |||
7 | #include <sys/types.h> | ||
8 | #include <linux/input.h> | ||
9 | |||
10 | using std::string; | ||
11 | |||
12 | const unsigned char BUT1 = 0x01; | ||
13 | const unsigned char BUT2 = 0x04; | ||
14 | const unsigned char BUT3 = 0x02; | ||
15 | const unsigned char BUT4 = 0x40; | ||
16 | const unsigned char BUT5 = 0x80; | ||
17 | |||
18 | #define BITMASK( name, numbits ) \ | ||
19 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | ||
20 | memset( name, 0, sizeof( name ) ) | ||
21 | |||
22 | #define TEST_BIT( bitmask, bit ) \ | ||
23 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | ||
24 | |||
25 | int Open_cPad() | ||
26 | { | ||
27 | size_t MAX_DEVICES = 1; | ||
28 | int fd = -1; | ||
29 | input_id info; | ||
30 | |||
31 | for( size_t i = 0; i < MAX_DEVICES; ++i ) | ||
32 | { | ||
33 | string devpath( "/dev/input/event0" ); | ||
34 | |||
35 | //devpath << (int)i; | ||
36 | |||
37 | fd = open( devpath.c_str(), O_RDONLY, &info ); | ||
38 | |||
39 | if( fd >= 0 ) | ||
40 | { | ||
41 | int version = -1; | ||
42 | /* ioctl() accesses the underlying driver */ | ||
43 | if (ioctl(fd, EVIOCGVERSION, &version)) { | ||
44 | perror("evdev ioctl"); | ||
45 | } | ||
46 | |||
47 | /* the EVIOCGVERSION ioctl() returns an int */ | ||
48 | /* so we unpack it and display it */ | ||
49 | printf("evdev driver version is %d.%d.%d\n", | ||
50 | version >> 16, (version >> 8) & 0xff, | ||
51 | version & 0xff); | ||
52 | |||
53 | // Get Identifying info | ||
54 | |||
55 | if( ioctl( fd, EVIOCGID, &info) ) | ||
56 | { | ||
57 | perror( "event device ioctl" ); | ||
58 | return -1; | ||
59 | } | ||
60 | printf( "Bus: %#x, Vendor: %#x, Product: %#x, Version: %#x\n", | ||
61 | info.bustype, info.vendor, info.product, info.version ); | ||
62 | |||
63 | switch ( info.bustype) | ||
64 | { | ||
65 | case BUS_PCI : | ||
66 | printf(" is on a PCI bus\n"); | ||
67 | break; | ||
68 | case BUS_USB : | ||
69 | printf(" is on a Universal Serial Bus\n"); | ||
70 | break; | ||
71 | /* ... */ | ||
72 | } | ||
73 | |||
74 | // Get device 'name' | ||
75 | |||
76 | char name[256] = "Unknown"; | ||
77 | if( ioctl( fd, EVIOCGNAME(sizeof name ), name) < 0 ) | ||
78 | { | ||
79 | perror( "event device ioctl" ); | ||
80 | }else | ||
81 | printf( "Device name '%s'\n", name ); | ||
82 | |||
83 | if(ioctl(fd, EVIOCGPHYS(sizeof(name)), name) < 0) { | ||
84 | perror("event ioctl"); | ||
85 | }else | ||
86 | printf("Device path '%s'\n", name ); | ||
87 | |||
88 | if(ioctl(fd, EVIOCGUNIQ(sizeof(name)), name) < 0) { | ||
89 | perror("event ioctl"); | ||
90 | }else | ||
91 | printf("Device identity '%s'\n", name ); | ||
92 | |||
93 | // Get feature types | ||
94 | |||
95 | BITMASK( features, EV_MAX ); | ||
96 | |||
97 | if( ioctl( fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) | ||
98 | { | ||
99 | perror( "event device ioctl" ); | ||
100 | return -1; | ||
101 | } | ||
102 | |||
103 | printf( "Supported features:\n" ); | ||
104 | for( size_t bit = 0; bit < EV_MAX; ++bit ) | ||
105 | { | ||
106 | if( TEST_BIT( features, bit ) ) | ||
107 | { | ||
108 | switch( bit ) | ||
109 | { | ||
110 | case EV_SYN : | ||
111 | printf(" Sync. Events\n"); | ||
112 | break; | ||
113 | //case EV_RST: | ||
114 | // printf( " Reset?\n" ); | ||
115 | // break; | ||
116 | case EV_KEY: | ||
117 | printf( " Keys or buttons\n" ); | ||
118 | break; | ||
119 | case EV_REL: | ||
120 | printf( " Relative axes\n" ); | ||
121 | break; | ||
122 | case EV_ABS: | ||
123 | printf( " Absolute axes\n" ); | ||
124 | break; | ||
125 | case EV_MSC: | ||
126 | printf( " Misc\n" ); | ||
127 | break; | ||
128 | case EV_LED: | ||
129 | printf( " Led's\n" ); | ||
130 | break; | ||
131 | case EV_SND: | ||
132 | printf( " Sounds\n" ); | ||
133 | break; | ||
134 | case EV_REP: | ||
135 | printf( " Repeat\n" ); | ||
136 | break; | ||
137 | case EV_FF : // fallthrough | ||
138 | case EV_FF_STATUS: | ||
139 | printf(" Force Feedback\n"); | ||
140 | break; | ||
141 | case EV_PWR: | ||
142 | printf(" Power Management\n"); | ||
143 | break; | ||
144 | default: | ||
145 | printf( " Unknown (bit %d)\n", bit ); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | // Check keystate | ||
151 | |||
152 | BITMASK( keys, KEY_MAX ); | ||
153 | |||
154 | if( ioctl( fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) | ||
155 | { | ||
156 | perror( "event device ioctl" ); | ||
157 | return -1; | ||
158 | } | ||
159 | |||
160 | printf( "Key global status:\n" ); | ||
161 | for( size_t bit = 0; bit < KEY_MAX; ++bit ) | ||
162 | { | ||
163 | if( TEST_BIT( keys, bit ) ) | ||
164 | { | ||
165 | printf( "Key (bit %d) active\n", bit ); | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | printf( "Failed to open device\n" ); | ||
171 | |||
172 | close( fd ); | ||
173 | } | ||
174 | return fd; | ||
175 | } | ||
176 | |||
177 | |||
178 | int main( int argc, char **argv ) | ||
179 | { | ||
180 | //printf(" Long: %d, int %d, short %d\n", sizeof( long ), sizeof( int ), sizeof( short ) ); | ||
181 | //printf( "num chars %d\n", snprintf( NULL, 0, 0 ) ); | ||
182 | //exit( 0 ); | ||
183 | Open_cPad(); | ||
184 | |||
185 | #if 1 | ||
186 | int fd = open( "/dev/input/event0", O_RDONLY ); | ||
187 | |||
188 | if( fd == -1 ) | ||
189 | { | ||
190 | printf( "Failed to open device\n" ); | ||
191 | goto hell; | ||
192 | } | ||
193 | |||
194 | struct input_event evbuf; | ||
195 | |||
196 | for(;;) | ||
197 | { | ||
198 | if( read( fd, &evbuf, sizeof evbuf ) == -1 ) | ||
199 | { | ||
200 | printf( "Read error\n" ); | ||
201 | goto hell; | ||
202 | } | ||
203 | |||
204 | printf( "Type: %d, Code: %d, Value: %d\n", evbuf.type, evbuf.code, evbuf.value ); | ||
205 | } | ||
206 | |||
207 | #endif | ||
208 | #if 0 | ||
209 | unsigned char buf[ 4 ]; | ||
210 | |||
211 | for(;;) | ||
212 | { | ||
213 | if( read( fd, buf, sizeof buf ) == -1 ) | ||
214 | { | ||
215 | printf( "Read error\n" ); | ||
216 | goto hell; | ||
217 | } | ||
218 | |||
219 | printf( "Raw:\t%#x\t%#x\t%#x\t%#x\n", buf[ 0 ], buf[ 1 ], buf[ 2 ], buf[ 3 ] ); | ||
220 | |||
221 | int dx = buf[ 1 ]; | ||
222 | |||
223 | if( ( buf[ 0 ] & 0x10 ) != 0 ) | ||
224 | dx -= 256; | ||
225 | |||
226 | int dy = - buf[ 2 ]; | ||
227 | |||
228 | if( ( buf[ 0 ] & 0x20 ) != 0 ) | ||
229 | dy += 256; | ||
230 | |||
231 | printf( "( %d, %d )\t", dx, dy ); | ||
232 | |||
233 | if( buf[ 0 ] & BUT1 ) | ||
234 | printf( "Left\t" ); | ||
235 | if( buf[ 0 ] & BUT2 ) | ||
236 | printf( "Middle\t" ); | ||
237 | if( buf[ 0 ] & BUT3 ) | ||
238 | printf( "Right\t" ); | ||
239 | |||
240 | printf( "\n" ); | ||
241 | } | ||
242 | #endif | ||
243 | |||
244 | //close( fd ); | ||
245 | |||
246 | exit( EXIT_SUCCESS ); | ||
247 | hell: | ||
248 | exit( EXIT_FAILURE ); | ||
249 | } | ||
250 | |||
diff --git a/examples/opiecore/oinputsystemdemo/oinputsystemdemo.pro b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.pro new file mode 100644 index 0000000..0a53a5e --- a/dev/null +++ b/examples/opiecore/oinputsystemdemo/oinputsystemdemo.pro | |||
@@ -0,0 +1,16 @@ | |||
1 | TEMPLATE = app | ||
2 | CONFIG = qt warn_on | ||
3 | HEADERS = | ||
4 | SOURCES = oinputsystemdemo.cpp | ||
5 | INCLUDEPATH += $(OPIEDIR)/include | ||
6 | DEPENDPATH += $(OPIEDIR)/include | ||
7 | LIBS += -lopiecore2 -lopieui2 | ||
8 | TARGET = oinputsystemdemo | ||
9 | |||
10 | !contains( platform, x11 ) { | ||
11 | include( $(OPIEDIR)/include.pro ) | ||
12 | } | ||
13 | |||
14 | contains( platform, x11 ) { | ||
15 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | ||
16 | } | ||
diff --git a/examples/opiecore/onotifydemo/onotifydemo.pro b/examples/opiecore/onotifydemo/onotifydemo.pro index d2c9138..1c1040c 100644 --- a/examples/opiecore/onotifydemo/onotifydemo.pro +++ b/examples/opiecore/onotifydemo/onotifydemo.pro | |||
@@ -1,18 +1,17 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG = qt warn_on | 2 | CONFIG = qt warn_on |
3 | HEADERS = | 3 | HEADERS = |
4 | SOURCES = onotifydemo.cpp | 4 | SOURCES = onotifydemo.cpp |
5 | INCLUDEPATH += $(OPIEDIR)/include | 5 | INCLUDEPATH += $(OPIEDIR)/include |
6 | DEPENDPATH += $(OPIEDIR)/include | 6 | DEPENDPATH += $(OPIEDIR)/include |
7 | LIBS += -lopiecore2 -lopieui2 | 7 | LIBS += -lopiecore2 -lopieui2 |
8 | TARGET = onotifydemo | 8 | TARGET = onotifydemo |
9 | 9 | ||
10 | !contains( platform, x11 ) { | 10 | !contains( platform, x11 ) { |
11 | include( $(OPIEDIR)/include.pro ) | 11 | include( $(OPIEDIR)/include.pro ) |
12 | } | 12 | } |
13 | 13 | ||
14 | contains( platform, x11 ) { | 14 | contains( platform, x11 ) { |
15 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 15 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
16 | } | 16 | } |
17 | 17 | ||
18 | MOC_DIR = moc | ||
diff --git a/examples/opiecore/opiecore.pro b/examples/opiecore/opiecore.pro index 39ffd3b..1f86a40 100644 --- a/examples/opiecore/opiecore.pro +++ b/examples/opiecore/opiecore.pro | |||
@@ -1,2 +1,2 @@ | |||
1 | TEMPLATE = subdirs | 1 | TEMPLATE = subdirs |
2 | unix:SUBDIRS = odebugdemo oconfigdemo oglobalsettingsdemo onotifydemo oprocessdemo oplugins | 2 | unix:SUBDIRS = odebugdemo oconfigdemo oglobalsettingsdemo onotifydemo oprocessdemo oplugins oinputsystemdemo |