author | sandman <sandman> | 2002-09-06 21:40:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-06 21:40:14 (UTC) |
commit | c22872aadda2ba93ddc53e5d5607ad795f147883 (patch) (unidiff) | |
tree | 247c442995fec2e5e2ed9b5826f46a427333a410 | |
parent | e95e14f056ce6be658a4fd0d4737168431e92d88 (diff) | |
download | opie-c22872aadda2ba93ddc53e5d5607ad795f147883.zip opie-c22872aadda2ba93ddc53e5d5607ad795f147883.tar.gz opie-c22872aadda2ba93ddc53e5d5607ad795f147883.tar.bz2 |
Fix for the new OD_IO macros
-rw-r--r-- | libopie/odevice.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 6e3f114..9871e80 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -1,329 +1,331 @@ | |||
1 | /* This file is part of the OPIE libraries | 1 | /* This file is part of the OPIE libraries |
2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) | 2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <sys/ioctl.h> | 23 | #include <sys/ioctl.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <linux/soundcard.h> | 26 | #include <linux/soundcard.h> |
27 | #include <math.h> | 27 | #include <math.h> |
28 | 28 | ||
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | 30 | ||
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qpe/sound.h> | 33 | #include <qpe/sound.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | 36 | ||
37 | #include "odevice.h" | 37 | #include "odevice.h" |
38 | 38 | ||
39 | // _IO and friends are only defined in kernel headers ... | 39 | // _IO and friends are only defined in kernel headers ... |
40 | 40 | ||
41 | #define OD_IO(type,area,number,args) (( type << 30 ) | ( area << 8 ) | ( number ) | ( sizeof( args ) << 16 )) | 41 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
42 | #define OD_IOW(area,number,args) OD_IO(1,area,number,args) | 42 | |
43 | #define OD_IOR(area,number,args) OD_IO(2,area,number,args) | 43 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
44 | #define OD_IORW(area,number,args) OD_IO(3,area,number,args) | 44 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
45 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | ||
46 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | ||
45 | 47 | ||
46 | 48 | ||
47 | class ODeviceData { | 49 | class ODeviceData { |
48 | public: | 50 | public: |
49 | QString m_vendorstr; | 51 | QString m_vendorstr; |
50 | OVendor m_vendor; | 52 | OVendor m_vendor; |
51 | 53 | ||
52 | QString m_modelstr; | 54 | QString m_modelstr; |
53 | OModel m_model; | 55 | OModel m_model; |
54 | 56 | ||
55 | QString m_systemstr; | 57 | QString m_systemstr; |
56 | OSystem m_system; | 58 | OSystem m_system; |
57 | 59 | ||
58 | QString m_sysverstr; | 60 | QString m_sysverstr; |
59 | 61 | ||
60 | OLedState m_leds [4]; // just for convenience ... | 62 | OLedState m_leds [4]; // just for convenience ... |
61 | }; | 63 | }; |
62 | 64 | ||
63 | class ODeviceIPAQ : public ODevice { | 65 | class ODeviceIPAQ : public ODevice { |
64 | protected: | 66 | protected: |
65 | virtual void init ( ); | 67 | virtual void init ( ); |
66 | 68 | ||
67 | public: | 69 | public: |
68 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); | 70 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); |
69 | 71 | ||
70 | virtual bool setDisplayBrightness ( int b ); | 72 | virtual bool setDisplayBrightness ( int b ); |
71 | virtual int displayBrightnessResolution ( ) const; | 73 | virtual int displayBrightnessResolution ( ) const; |
72 | 74 | ||
73 | virtual void alarmSound ( ); | 75 | virtual void alarmSound ( ); |
74 | 76 | ||
75 | virtual uint hasLeds ( ) const; | 77 | virtual uint hasLeds ( ) const; |
76 | virtual OLedState led ( uint which ) const; | 78 | virtual OLedState led ( uint which ) const; |
77 | virtual bool setLed ( uint which, OLedState st ); | 79 | virtual bool setLed ( uint which, OLedState st ); |
78 | }; | 80 | }; |
79 | 81 | ||
80 | class ODeviceZaurus : public ODevice { | 82 | class ODeviceZaurus : public ODevice { |
81 | protected: | 83 | protected: |
82 | virtual void init ( ); | 84 | virtual void init ( ); |
83 | 85 | ||
84 | public: | 86 | public: |
85 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); | 87 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); |
86 | 88 | ||
87 | virtual bool setDisplayBrightness ( int b ); | 89 | virtual bool setDisplayBrightness ( int b ); |
88 | virtual int displayBrightnessResolution ( ) const; | 90 | virtual int displayBrightnessResolution ( ) const; |
89 | 91 | ||
90 | virtual void alarmSound ( ); | 92 | virtual void alarmSound ( ); |
91 | virtual void keySound ( ); | 93 | virtual void keySound ( ); |
92 | virtual void touchSound ( ); | 94 | virtual void touchSound ( ); |
93 | 95 | ||
94 | virtual uint hasLeds ( ) const; | 96 | virtual uint hasLeds ( ) const; |
95 | virtual OLedState led ( uint which ) const; | 97 | virtual OLedState led ( uint which ) const; |
96 | virtual bool setLed ( uint which, OLedState st ); | 98 | virtual bool setLed ( uint which, OLedState st ); |
97 | 99 | ||
98 | protected: | 100 | protected: |
99 | virtual void buzzer ( int snd ); | 101 | virtual void buzzer ( int snd ); |
100 | }; | 102 | }; |
101 | 103 | ||
102 | 104 | ||
103 | 105 | ||
104 | 106 | ||
105 | ODevice *ODevice::inst ( ) | 107 | ODevice *ODevice::inst ( ) |
106 | { | 108 | { |
107 | static ODevice *dev = 0; | 109 | static ODevice *dev = 0; |
108 | 110 | ||
109 | if ( !dev ) { | 111 | if ( !dev ) { |
110 | if ( QFile::exists ( "/proc/hal/model" )) | 112 | if ( QFile::exists ( "/proc/hal/model" )) |
111 | dev = new ODeviceIPAQ ( ); | 113 | dev = new ODeviceIPAQ ( ); |
112 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 114 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
113 | dev = new ODeviceZaurus ( ); | 115 | dev = new ODeviceZaurus ( ); |
114 | else | 116 | else |
115 | dev = new ODevice ( ); | 117 | dev = new ODevice ( ); |
116 | 118 | ||
117 | dev-> init ( ); | 119 | dev-> init ( ); |
118 | } | 120 | } |
119 | return dev; | 121 | return dev; |
120 | } | 122 | } |
121 | 123 | ||
122 | 124 | ||
123 | /************************************************** | 125 | /************************************************** |
124 | * | 126 | * |
125 | * common | 127 | * common |
126 | * | 128 | * |
127 | **************************************************/ | 129 | **************************************************/ |
128 | 130 | ||
129 | 131 | ||
130 | ODevice::ODevice ( ) | 132 | ODevice::ODevice ( ) |
131 | { | 133 | { |
132 | d = new ODeviceData; | 134 | d = new ODeviceData; |
133 | 135 | ||
134 | d-> m_modelstr = "Unknown"; | 136 | d-> m_modelstr = "Unknown"; |
135 | d-> m_model = OMODEL_Unknown; | 137 | d-> m_model = OMODEL_Unknown; |
136 | d-> m_vendorstr = "Unkown"; | 138 | d-> m_vendorstr = "Unkown"; |
137 | d-> m_vendor = OVENDOR_Unknown; | 139 | d-> m_vendor = OVENDOR_Unknown; |
138 | d-> m_systemstr = "Unkown"; | 140 | d-> m_systemstr = "Unkown"; |
139 | d-> m_system = OSYSTEM_Unknown; | 141 | d-> m_system = OSYSTEM_Unknown; |
140 | d-> m_sysverstr = "0.0"; | 142 | d-> m_sysverstr = "0.0"; |
141 | } | 143 | } |
142 | 144 | ||
143 | void ODevice::init ( ) | 145 | void ODevice::init ( ) |
144 | { | 146 | { |
145 | } | 147 | } |
146 | 148 | ||
147 | ODevice::~ODevice ( ) | 149 | ODevice::~ODevice ( ) |
148 | { | 150 | { |
149 | delete d; | 151 | delete d; |
150 | } | 152 | } |
151 | 153 | ||
152 | bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | 154 | bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) |
153 | { | 155 | { |
154 | return false; | 156 | return false; |
155 | } | 157 | } |
156 | 158 | ||
157 | //#include <linux/apm_bios.h> | 159 | //#include <linux/apm_bios.h> |
158 | 160 | ||
159 | #define APM_IOC_SUSPEND OD_IO( 0, 'A', 2, 0 ) | 161 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
160 | 162 | ||
161 | 163 | ||
162 | bool ODevice::suspend ( ) | 164 | bool ODevice::suspend ( ) |
163 | { | 165 | { |
164 | if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices | 166 | if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices |
165 | return false; | 167 | return false; |
166 | 168 | ||
167 | int fd; | 169 | int fd; |
168 | bool res = false; | 170 | bool res = false; |
169 | 171 | ||
170 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || | 172 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || |
171 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { | 173 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { |
172 | struct timeval tvs, tvn; | 174 | struct timeval tvs, tvn; |
173 | 175 | ||
174 | ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped | 176 | ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped |
175 | ::gettimeofday ( &tvs, 0 ); | 177 | ::gettimeofday ( &tvs, 0 ); |
176 | 178 | ||
177 | ::sync ( ); // flush fs caches | 179 | ::sync ( ); // flush fs caches |
178 | 180 | ||
179 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending | 181 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending |
180 | 182 | ||
181 | if ( res ) { | 183 | if ( res ) { |
182 | ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group | 184 | ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group |
183 | 185 | ||
184 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 186 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
185 | ::usleep ( 200 * 1000 ); | 187 | ::usleep ( 200 * 1000 ); |
186 | ::gettimeofday ( &tvn, 0 ); | 188 | ::gettimeofday ( &tvn, 0 ); |
187 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 189 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
188 | 190 | ||
189 | ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group | 191 | ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group |
190 | } | 192 | } |
191 | 193 | ||
192 | ::close ( fd ); | 194 | ::close ( fd ); |
193 | ::signal ( SIGTSTP, SIG_DFL ); | 195 | ::signal ( SIGTSTP, SIG_DFL ); |
194 | } | 196 | } |
195 | 197 | ||
196 | return res; | 198 | return res; |
197 | } | 199 | } |
198 | 200 | ||
199 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | 201 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... |
200 | 202 | ||
201 | #define FBIOBLANK OD_IO( 0, 'F', 0x11, 0 ) // 0x4611 | 203 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 |
202 | 204 | ||
203 | /* VESA Blanking Levels */ | 205 | /* VESA Blanking Levels */ |
204 | #define VESA_NO_BLANKING 0 | 206 | #define VESA_NO_BLANKING 0 |
205 | #define VESA_VSYNC_SUSPEND 1 | 207 | #define VESA_VSYNC_SUSPEND 1 |
206 | #define VESA_HSYNC_SUSPEND 2 | 208 | #define VESA_HSYNC_SUSPEND 2 |
207 | #define VESA_POWERDOWN 3 | 209 | #define VESA_POWERDOWN 3 |
208 | 210 | ||
209 | 211 | ||
210 | bool ODevice::setDisplayStatus ( bool on ) | 212 | bool ODevice::setDisplayStatus ( bool on ) |
211 | { | 213 | { |
212 | if ( d-> m_model == OMODEL_Unknown ) | 214 | if ( d-> m_model == OMODEL_Unknown ) |
213 | return false; | 215 | return false; |
214 | 216 | ||
215 | bool res = false; | 217 | bool res = false; |
216 | int fd; | 218 | int fd; |
217 | 219 | ||
218 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | 220 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { |
219 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | 221 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); |
220 | ::close ( fd ); | 222 | ::close ( fd ); |
221 | } | 223 | } |
222 | return res; | 224 | return res; |
223 | } | 225 | } |
224 | 226 | ||
225 | bool ODevice::setDisplayBrightness ( int ) | 227 | bool ODevice::setDisplayBrightness ( int ) |
226 | { | 228 | { |
227 | return false; | 229 | return false; |
228 | } | 230 | } |
229 | 231 | ||
230 | int ODevice::displayBrightnessResolution ( ) const | 232 | int ODevice::displayBrightnessResolution ( ) const |
231 | { | 233 | { |
232 | return 16; | 234 | return 16; |
233 | } | 235 | } |
234 | 236 | ||
235 | QString ODevice::vendorString ( ) | 237 | QString ODevice::vendorString ( ) |
236 | { | 238 | { |
237 | return d-> m_vendorstr; | 239 | return d-> m_vendorstr; |
238 | } | 240 | } |
239 | 241 | ||
240 | OVendor ODevice::vendor ( ) | 242 | OVendor ODevice::vendor ( ) |
241 | { | 243 | { |
242 | return d-> m_vendor; | 244 | return d-> m_vendor; |
243 | } | 245 | } |
244 | 246 | ||
245 | QString ODevice::modelString ( ) | 247 | QString ODevice::modelString ( ) |
246 | { | 248 | { |
247 | return d-> m_modelstr; | 249 | return d-> m_modelstr; |
248 | } | 250 | } |
249 | 251 | ||
250 | OModel ODevice::model ( ) | 252 | OModel ODevice::model ( ) |
251 | { | 253 | { |
252 | return d-> m_model; | 254 | return d-> m_model; |
253 | } | 255 | } |
254 | 256 | ||
255 | QString ODevice::systemString ( ) | 257 | QString ODevice::systemString ( ) |
256 | { | 258 | { |
257 | return d-> m_systemstr; | 259 | return d-> m_systemstr; |
258 | } | 260 | } |
259 | 261 | ||
260 | OSystem ODevice::system ( ) | 262 | OSystem ODevice::system ( ) |
261 | { | 263 | { |
262 | return d-> m_system; | 264 | return d-> m_system; |
263 | } | 265 | } |
264 | 266 | ||
265 | QString ODevice::systemVersionString ( ) | 267 | QString ODevice::systemVersionString ( ) |
266 | { | 268 | { |
267 | return d-> m_sysverstr; | 269 | return d-> m_sysverstr; |
268 | } | 270 | } |
269 | 271 | ||
270 | void ODevice::alarmSound ( ) | 272 | void ODevice::alarmSound ( ) |
271 | { | 273 | { |
272 | #ifndef QT_QWS_EBX | 274 | #ifndef QT_QWS_EBX |
273 | #ifndef QT_NO_SOUND | 275 | #ifndef QT_NO_SOUND |
274 | static Sound snd ( "alarm" ); | 276 | static Sound snd ( "alarm" ); |
275 | 277 | ||
276 | if ( snd. isFinished ( )) | 278 | if ( snd. isFinished ( )) |
277 | snd. play ( ); | 279 | snd. play ( ); |
278 | #endif | 280 | #endif |
279 | #endif | 281 | #endif |
280 | } | 282 | } |
281 | 283 | ||
282 | void ODevice::keySound ( ) | 284 | void ODevice::keySound ( ) |
283 | { | 285 | { |
284 | #ifndef QT_QWS_EBX | 286 | #ifndef QT_QWS_EBX |
285 | #ifndef QT_NO_SOUND | 287 | #ifndef QT_NO_SOUND |
286 | static Sound snd ( "keysound" ); | 288 | static Sound snd ( "keysound" ); |
287 | 289 | ||
288 | if ( snd. isFinished ( )) | 290 | if ( snd. isFinished ( )) |
289 | snd. play ( ); | 291 | snd. play ( ); |
290 | #endif | 292 | #endif |
291 | #endif | 293 | #endif |
292 | } | 294 | } |
293 | 295 | ||
294 | void ODevice::touchSound ( ) | 296 | void ODevice::touchSound ( ) |
295 | { | 297 | { |
296 | 298 | ||
297 | #ifndef QT_QWS_EBX | 299 | #ifndef QT_QWS_EBX |
298 | #ifndef QT_NO_SOUND | 300 | #ifndef QT_NO_SOUND |
299 | static Sound snd ( "touchsound" ); | 301 | static Sound snd ( "touchsound" ); |
300 | 302 | ||
301 | if ( snd. isFinished ( )) | 303 | if ( snd. isFinished ( )) |
302 | snd. play ( ); | 304 | snd. play ( ); |
303 | #endif | 305 | #endif |
304 | #endif | 306 | #endif |
305 | } | 307 | } |
306 | 308 | ||
307 | uint ODevice::hasLeds ( ) const | 309 | uint ODevice::hasLeds ( ) const |
308 | { | 310 | { |
309 | return 0; | 311 | return 0; |
310 | } | 312 | } |
311 | 313 | ||
312 | OLedState ODevice::led ( uint /*which*/ ) const | 314 | OLedState ODevice::led ( uint /*which*/ ) const |
313 | { | 315 | { |
314 | return OLED_Off; | 316 | return OLED_Off; |
315 | } | 317 | } |
316 | 318 | ||
317 | bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) | 319 | bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) |
318 | { | 320 | { |
319 | return false; | 321 | return false; |
320 | } | 322 | } |
321 | 323 | ||
322 | 324 | ||
323 | 325 | ||
324 | 326 | ||
325 | /************************************************** | 327 | /************************************************** |
326 | * | 328 | * |
327 | * iPAQ | 329 | * iPAQ |
328 | * | 330 | * |
329 | **************************************************/ | 331 | **************************************************/ |