author | sandman <sandman> | 2002-09-30 21:09:13 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-30 21:09:13 (UTC) |
commit | 3ff016b281a3c059e6ecb728c60fd6847756f291 (patch) (unidiff) | |
tree | 6d7b341ef586552b1a2154af047b41fb567b59d9 /libopie/odevice.cpp | |
parent | 5158385997be6b64cab623674f9e9e1835f94fc6 (diff) | |
download | opie-3ff016b281a3c059e6ecb728c60fd6847756f291.zip opie-3ff016b281a3c059e6ecb728c60fd6847756f291.tar.gz opie-3ff016b281a3c059e6ecb728c60fd6847756f291.tar.bz2 |
- partly rearranged for better bc in the future
- led handling rewritten
- cleanups
- another try at fixing the OZ suspend "glitches"
-rw-r--r-- | libopie/odevice.cpp | 409 |
1 files changed, 285 insertions, 124 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 3bc1e0c..c84312e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -35,8 +35,11 @@ | |||
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | 36 | ||
37 | #include "odevice.h" | 37 | #include "odevice.h" |
38 | 38 | ||
39 | #include <qwindowsystem_qws.h> | ||
40 | |||
41 | |||
39 | // _IO and friends are only defined in kernel headers ... | 42 | // _IO and friends are only defined in kernel headers ... |
40 | 43 | ||
41 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 44 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
42 | 45 | ||
@@ -44,11 +47,14 @@ | |||
44 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 47 | #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)) | 48 | #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)) | 49 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
47 | 50 | ||
51 | using namespace Opie; | ||
48 | 52 | ||
49 | class ODeviceData { | 53 | class ODeviceData { |
50 | public: | 54 | public: |
55 | bool m_qwsserver; | ||
56 | |||
51 | QString m_vendorstr; | 57 | QString m_vendorstr; |
52 | OVendor m_vendor; | 58 | OVendor m_vendor; |
53 | 59 | ||
54 | QString m_modelstr; | 60 | QString m_modelstr; |
@@ -57,63 +63,81 @@ public: | |||
57 | QString m_systemstr; | 63 | QString m_systemstr; |
58 | OSystem m_system; | 64 | OSystem m_system; |
59 | 65 | ||
60 | QString m_sysverstr; | 66 | QString m_sysverstr; |
61 | |||
62 | OLedState m_leds [4]; // just for convenience ... | ||
63 | }; | 67 | }; |
64 | 68 | ||
65 | class ODeviceIPAQ : public ODevice { | 69 | |
70 | class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { | ||
66 | protected: | 71 | protected: |
67 | virtual void init ( ); | 72 | virtual void init ( ); |
68 | 73 | ||
69 | public: | 74 | public: |
70 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); | 75 | virtual bool setSoftSuspend ( bool soft ); |
71 | 76 | ||
72 | virtual bool setDisplayBrightness ( int b ); | 77 | virtual bool setDisplayBrightness ( int b ); |
73 | virtual int displayBrightnessResolution ( ) const; | 78 | virtual int displayBrightnessResolution ( ) const; |
74 | 79 | ||
75 | virtual void alarmSound ( ); | 80 | virtual void alarmSound ( ); |
76 | 81 | ||
77 | virtual uint hasLeds ( ) const; | 82 | virtual QValueList <OLed> ledList ( ) const; |
78 | virtual OLedState led ( uint which ) const; | 83 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
79 | virtual bool setLed ( uint which, OLedState st ); | 84 | virtual OLedState ledState ( OLed led ) const; |
85 | virtual bool setLedState ( OLed led, OLedState st ); | ||
86 | |||
87 | //virtual QValueList <int> keyList ( ) const; | ||
88 | |||
89 | protected: | ||
90 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | ||
91 | virtual void timerEvent ( QTimerEvent *te ); | ||
92 | |||
93 | int m_power_timer; | ||
94 | |||
95 | OLedState m_leds [2]; | ||
80 | }; | 96 | }; |
81 | 97 | ||
82 | class ODeviceZaurus : public ODevice { | 98 | class Zaurus : public ODevice { |
83 | protected: | 99 | protected: |
84 | virtual void init ( ); | 100 | virtual void init ( ); |
85 | 101 | ||
86 | public: | 102 | public: |
87 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); | 103 | virtual bool setSoftSuspend ( bool soft ); |
88 | 104 | ||
89 | virtual bool setDisplayBrightness ( int b ); | 105 | virtual bool setDisplayBrightness ( int b ); |
90 | virtual int displayBrightnessResolution ( ) const; | 106 | virtual int displayBrightnessResolution ( ) const; |
91 | 107 | ||
92 | virtual void alarmSound ( ); | 108 | virtual void alarmSound ( ); |
93 | virtual void keySound ( ); | 109 | virtual void keySound ( ); |
94 | virtual void touchSound ( ); | 110 | virtual void touchSound ( ); |
95 | 111 | ||
96 | virtual uint hasLeds ( ) const; | 112 | virtual QValueList <OLed> ledList ( ) const; |
97 | virtual OLedState led ( uint which ) const; | 113 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
98 | virtual bool setLed ( uint which, OLedState st ); | 114 | virtual OLedState ledState ( OLed led ) const; |
115 | virtual bool setLedState ( OLed led, OLedState st ); | ||
116 | |||
117 | //virtual QValueList <int> keyList ( ) const; | ||
99 | 118 | ||
100 | protected: | 119 | protected: |
101 | virtual void buzzer ( int snd ); | 120 | virtual void buzzer ( int snd ); |
121 | |||
122 | OLedState m_leds [1]; | ||
102 | }; | 123 | }; |
103 | 124 | ||
104 | 125 | ||
105 | 126 | ||
106 | 127 | ||
128 | |||
129 | |||
130 | |||
107 | ODevice *ODevice::inst ( ) | 131 | ODevice *ODevice::inst ( ) |
108 | { | 132 | { |
109 | static ODevice *dev = 0; | 133 | static ODevice *dev = 0; |
110 | 134 | ||
111 | if ( !dev ) { | 135 | if ( !dev ) { |
112 | if ( QFile::exists ( "/proc/hal/model" )) | 136 | if ( QFile::exists ( "/proc/hal/model" )) |
113 | dev = new ODeviceIPAQ ( ); | 137 | dev = new iPAQ ( ); |
114 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 138 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
115 | dev = new ODeviceZaurus ( ); | 139 | dev = new Zaurus ( ); |
116 | else | 140 | else |
117 | dev = new ODevice ( ); | 141 | dev = new ODevice ( ); |
118 | 142 | ||
119 | dev-> init ( ); | 143 | dev-> init ( ); |
@@ -132,14 +156,16 @@ ODevice *ODevice::inst ( ) | |||
132 | ODevice::ODevice ( ) | 156 | ODevice::ODevice ( ) |
133 | { | 157 | { |
134 | d = new ODeviceData; | 158 | d = new ODeviceData; |
135 | 159 | ||
160 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | ||
161 | |||
136 | d-> m_modelstr = "Unknown"; | 162 | d-> m_modelstr = "Unknown"; |
137 | d-> m_model = OMODEL_Unknown; | 163 | d-> m_model = Model_Unknown; |
138 | d-> m_vendorstr = "Unkown"; | 164 | d-> m_vendorstr = "Unkown"; |
139 | d-> m_vendor = OVENDOR_Unknown; | 165 | d-> m_vendor = Vendor_Unknown; |
140 | d-> m_systemstr = "Unkown"; | 166 | d-> m_systemstr = "Unkown"; |
141 | d-> m_system = OSYSTEM_Unknown; | 167 | d-> m_system = System_Unknown; |
142 | d-> m_sysverstr = "0.0"; | 168 | d-> m_sysverstr = "0.0"; |
143 | } | 169 | } |
144 | 170 | ||
145 | void ODevice::init ( ) | 171 | void ODevice::init ( ) |
@@ -150,9 +176,9 @@ ODevice::~ODevice ( ) | |||
150 | { | 176 | { |
151 | delete d; | 177 | delete d; |
152 | } | 178 | } |
153 | 179 | ||
154 | bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | 180 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
155 | { | 181 | { |
156 | return false; | 182 | return false; |
157 | } | 183 | } |
158 | 184 | ||
@@ -162,9 +188,12 @@ bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | |||
162 | 188 | ||
163 | 189 | ||
164 | bool ODevice::suspend ( ) | 190 | bool ODevice::suspend ( ) |
165 | { | 191 | { |
166 | if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices | 192 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend |
193 | return false; | ||
194 | |||
195 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | ||
167 | return false; | 196 | return false; |
168 | 197 | ||
169 | int fd; | 198 | int fd; |
170 | bool res = false; | 199 | bool res = false; |
@@ -172,28 +201,28 @@ bool ODevice::suspend ( ) | |||
172 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || | 201 | if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || |
173 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { | 202 | (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { |
174 | struct timeval tvs, tvn; | 203 | struct timeval tvs, tvn; |
175 | 204 | ||
176 | ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped | 205 | // ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped |
177 | ::gettimeofday ( &tvs, 0 ); | 206 | ::gettimeofday ( &tvs, 0 ); |
178 | 207 | ||
179 | ::sync ( ); // flush fs caches | 208 | ::sync ( ); // flush fs caches |
180 | 209 | ||
181 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending | 210 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending |
211 | ::close ( fd ); | ||
182 | 212 | ||
183 | if ( res ) { | 213 | if ( res ) { |
184 | ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group | 214 | // ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group |
185 | 215 | ||
186 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 216 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
187 | ::usleep ( 200 * 1000 ); | 217 | ::usleep ( 200 * 1000 ); |
188 | ::gettimeofday ( &tvn, 0 ); | 218 | ::gettimeofday ( &tvn, 0 ); |
189 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 219 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
190 | 220 | ||
191 | ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group | 221 | // ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group |
192 | } | 222 | } |
193 | 223 | ||
194 | ::close ( fd ); | 224 | // ::signal ( SIGTSTP, SIG_DFL ); |
195 | ::signal ( SIGTSTP, SIG_DFL ); | ||
196 | } | 225 | } |
197 | 226 | ||
198 | return res; | 227 | return res; |
199 | } | 228 | } |
@@ -210,9 +239,9 @@ bool ODevice::suspend ( ) | |||
210 | 239 | ||
211 | 240 | ||
212 | bool ODevice::setDisplayStatus ( bool on ) | 241 | bool ODevice::setDisplayStatus ( bool on ) |
213 | { | 242 | { |
214 | if ( d-> m_model == OMODEL_Unknown ) | 243 | if ( d-> m_model == Model_Unknown ) |
215 | return false; | 244 | return false; |
216 | 245 | ||
217 | bool res = false; | 246 | bool res = false; |
218 | int fd; | 247 | int fd; |
@@ -233,39 +262,39 @@ int ODevice::displayBrightnessResolution ( ) const | |||
233 | { | 262 | { |
234 | return 16; | 263 | return 16; |
235 | } | 264 | } |
236 | 265 | ||
237 | QString ODevice::vendorString ( ) | 266 | QString ODevice::vendorString ( ) const |
238 | { | 267 | { |
239 | return d-> m_vendorstr; | 268 | return d-> m_vendorstr; |
240 | } | 269 | } |
241 | 270 | ||
242 | OVendor ODevice::vendor ( ) | 271 | OVendor ODevice::vendor ( ) const |
243 | { | 272 | { |
244 | return d-> m_vendor; | 273 | return d-> m_vendor; |
245 | } | 274 | } |
246 | 275 | ||
247 | QString ODevice::modelString ( ) | 276 | QString ODevice::modelString ( ) const |
248 | { | 277 | { |
249 | return d-> m_modelstr; | 278 | return d-> m_modelstr; |
250 | } | 279 | } |
251 | 280 | ||
252 | OModel ODevice::model ( ) | 281 | OModel ODevice::model ( ) const |
253 | { | 282 | { |
254 | return d-> m_model; | 283 | return d-> m_model; |
255 | } | 284 | } |
256 | 285 | ||
257 | QString ODevice::systemString ( ) | 286 | QString ODevice::systemString ( ) const |
258 | { | 287 | { |
259 | return d-> m_systemstr; | 288 | return d-> m_systemstr; |
260 | } | 289 | } |
261 | 290 | ||
262 | OSystem ODevice::system ( ) | 291 | OSystem ODevice::system ( ) const |
263 | { | 292 | { |
264 | return d-> m_system; | 293 | return d-> m_system; |
265 | } | 294 | } |
266 | 295 | ||
267 | QString ODevice::systemVersionString ( ) | 296 | QString ODevice::systemVersionString ( ) const |
268 | { | 297 | { |
269 | return d-> m_sysverstr; | 298 | return d-> m_sysverstr; |
270 | } | 299 | } |
271 | 300 | ||
@@ -305,36 +334,48 @@ void ODevice::touchSound ( ) | |||
305 | #endif | 334 | #endif |
306 | #endif | 335 | #endif |
307 | } | 336 | } |
308 | 337 | ||
309 | uint ODevice::hasLeds ( ) const | 338 | |
339 | QValueList <OLed> ODevice::ledList ( ) const | ||
340 | { | ||
341 | return QValueList <OLed> ( ); | ||
342 | } | ||
343 | |||
344 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const | ||
310 | { | 345 | { |
311 | return 0; | 346 | return QValueList <OLedState> ( ); |
312 | } | 347 | } |
313 | 348 | ||
314 | OLedState ODevice::led ( uint /*which*/ ) const | 349 | OLedState ODevice::ledState ( OLed /*which*/ ) const |
315 | { | 350 | { |
316 | return OLED_Off; | 351 | return Led_Off; |
317 | } | 352 | } |
318 | 353 | ||
319 | bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) | 354 | bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) |
320 | { | 355 | { |
321 | return false; | 356 | return false; |
322 | } | 357 | } |
323 | 358 | ||
324 | 359 | ||
325 | 360 | ||
361 | //QValueList <int> ODevice::keyList ( ) const | ||
362 | //{ | ||
363 | //return QValueList <int> ( ); | ||
364 | //} | ||
365 | |||
366 | |||
326 | 367 | ||
327 | /************************************************** | 368 | /************************************************** |
328 | * | 369 | * |
329 | * iPAQ | 370 | * iPAQ |
330 | * | 371 | * |
331 | **************************************************/ | 372 | **************************************************/ |
332 | 373 | ||
333 | void ODeviceIPAQ::init ( ) | 374 | void iPAQ::init ( ) |
334 | { | 375 | { |
335 | d-> m_vendorstr = "HP"; | 376 | d-> m_vendorstr = "HP"; |
336 | d-> m_vendor = OVENDOR_HP; | 377 | d-> m_vendor = Vendor_HP; |
337 | 378 | ||
338 | QFile f ( "/proc/hal/model" ); | 379 | QFile f ( "/proc/hal/model" ); |
339 | 380 | ||
340 | if ( f. open ( IO_ReadOnly )) { | 381 | if ( f. open ( IO_ReadOnly )) { |
@@ -342,33 +383,38 @@ void ODeviceIPAQ::init ( ) | |||
342 | 383 | ||
343 | d-> m_modelstr = "H" + ts. readLine ( ); | 384 | d-> m_modelstr = "H" + ts. readLine ( ); |
344 | 385 | ||
345 | if ( d-> m_modelstr == "H3100" ) | 386 | if ( d-> m_modelstr == "H3100" ) |
346 | d-> m_model = OMODEL_iPAQ_H31xx; | 387 | d-> m_model = Model_iPAQ_H31xx; |
347 | else if ( d-> m_modelstr == "H3600" ) | 388 | else if ( d-> m_modelstr == "H3600" ) |
348 | d-> m_model = OMODEL_iPAQ_H36xx; | 389 | d-> m_model = Model_iPAQ_H36xx; |
349 | else if ( d-> m_modelstr == "H3700" ) | 390 | else if ( d-> m_modelstr == "H3700" ) |
350 | d-> m_model = OMODEL_iPAQ_H37xx; | 391 | d-> m_model = Model_iPAQ_H37xx; |
351 | else if ( d-> m_modelstr == "H3800" ) | 392 | else if ( d-> m_modelstr == "H3800" ) |
352 | d-> m_model = OMODEL_iPAQ_H38xx; | 393 | d-> m_model = Model_iPAQ_H38xx; |
353 | else | 394 | else |
354 | d-> m_model = OMODEL_Unknown; | 395 | d-> m_model = Model_Unknown; |
355 | 396 | ||
356 | f. close ( ); | 397 | f. close ( ); |
357 | } | 398 | } |
358 | 399 | ||
359 | f. setName ( "/etc/familiar-version" ); | 400 | f. setName ( "/etc/familiar-version" ); |
360 | if ( f. open ( IO_ReadOnly )) { | 401 | if ( f. open ( IO_ReadOnly )) { |
361 | d-> m_systemstr = "Familiar"; | 402 | d-> m_systemstr = "Familiar"; |
362 | d-> m_system = OSYSTEM_Familiar; | 403 | d-> m_system = System_Familiar; |
363 | 404 | ||
364 | QTextStream ts ( &f ); | 405 | QTextStream ts ( &f ); |
365 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 406 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
366 | 407 | ||
367 | f. close ( ); | 408 | f. close ( ); |
368 | } | 409 | } |
369 | 410 | ||
370 | d-> m_leds [0] = OLED_Off; | 411 | m_leds [0] = m_leds [1] = Led_Off; |
412 | |||
413 | m_power_timer = 0; | ||
414 | |||
415 | if ( d-> m_qwsserver ) | ||
416 | QWSServer::setKeyboardFilter ( this ); | ||
371 | } | 417 | } |
372 | 418 | ||
373 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | 419 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... |
374 | 420 | ||
@@ -388,9 +434,145 @@ typedef struct { | |||
388 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 434 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
389 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 435 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
390 | 436 | ||
391 | 437 | ||
392 | void ODeviceIPAQ::alarmSound ( ) | 438 | |
439 | QValueList <OLed> iPAQ::ledList ( ) const | ||
440 | { | ||
441 | QValueList <OLed> vl; | ||
442 | vl << Led_Power; | ||
443 | |||
444 | if ( d-> m_model == Model_iPAQ_H38xx ) | ||
445 | vl << Led_BlueTooth; | ||
446 | return vl; | ||
447 | } | ||
448 | |||
449 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | ||
450 | { | ||
451 | QValueList <OLedState> vl; | ||
452 | |||
453 | if ( l == Led_Power ) | ||
454 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | ||
455 | else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) | ||
456 | vl << Led_Off; // << Led_On << ??? | ||
457 | |||
458 | return vl; | ||
459 | } | ||
460 | |||
461 | OLedState iPAQ::ledState ( OLed l ) const | ||
462 | { | ||
463 | switch ( l ) { | ||
464 | case Led_Power: | ||
465 | return m_leds [0]; | ||
466 | case Led_BlueTooth: | ||
467 | return m_leds [1]; | ||
468 | default: | ||
469 | return Led_Off; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | bool iPAQ::setLedState ( OLed l, OLedState st ) | ||
474 | { | ||
475 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); | ||
476 | |||
477 | if ( l == Led_Power ) { | ||
478 | if ( fd >= 0 ) { | ||
479 | LED_IN leds; | ||
480 | ::memset ( &leds, 0, sizeof( leds )); | ||
481 | leds. TotalTime = 0; | ||
482 | leds. OnTime = 0; | ||
483 | leds. OffTime = 1; | ||
484 | leds. OffOnBlink = 2; | ||
485 | |||
486 | switch ( st ) { | ||
487 | case Led_Off : leds. OffOnBlink = 0; break; | ||
488 | case Led_On : leds. OffOnBlink = 1; break; | ||
489 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | ||
490 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | ||
491 | } | ||
492 | |||
493 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | ||
494 | m_leds [0] = st; | ||
495 | return true; | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | return false; | ||
500 | } | ||
501 | |||
502 | |||
503 | //QValueList <int> iPAQ::keyList ( ) const | ||
504 | //{ | ||
505 | //QValueList <int> vl; | ||
506 | //vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight; | ||
507 | //return vl; | ||
508 | //} | ||
509 | |||
510 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | ||
511 | { | ||
512 | int newkeycode = keycode; | ||
513 | |||
514 | |||
515 | // simple susbstitutions | ||
516 | switch ( d-> m_model ) { | ||
517 | case Model_iPAQ_H38xx: | ||
518 | // H38xx has no "Q" key anymore - this is now the Mail key | ||
519 | if ( keycode == HardKey_Menu ) | ||
520 | newkeycode = HardKey_Mail; | ||
521 | //nobreak | ||
522 | |||
523 | case Model_iPAQ_H31xx: | ||
524 | // Rotate cursor keys 180° | ||
525 | switch ( keycode ) { | ||
526 | case Key_Left : newkeycode = Key_Right; break; | ||
527 | case Key_Right: newkeycode = Key_Left; break; | ||
528 | case Key_Up : newkeycode = Key_Down; break; | ||
529 | case Key_Down : newkeycode = Key_Up; break; | ||
530 | } | ||
531 | break; | ||
532 | |||
533 | case Model_iPAQ_H36xx: | ||
534 | case Model_iPAQ_H37xx: | ||
535 | // map Power Button short/long press to F34/F35 | ||
536 | if ( keycode == Key_SysReq ) { | ||
537 | if ( isPress ) { | ||
538 | if ( m_power_timer ) | ||
539 | killTimer ( m_power_timer ); | ||
540 | m_power_timer = startTimer ( 500 ); | ||
541 | } | ||
542 | else if ( m_power_timer ) { | ||
543 | killTimer ( m_power_timer ); | ||
544 | m_power_timer = 0; | ||
545 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | ||
546 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | ||
547 | } | ||
548 | newkeycode = Key_unknown; | ||
549 | } | ||
550 | break; | ||
551 | |||
552 | default: | ||
553 | break; | ||
554 | } | ||
555 | |||
556 | if ( newkeycode != keycode ) { | ||
557 | if ( newkeycode != Key_unknown ) | ||
558 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | ||
559 | return true; | ||
560 | } | ||
561 | else | ||
562 | return false; | ||
563 | } | ||
564 | |||
565 | void iPAQ::timerEvent ( QTimerEvent * ) | ||
566 | { | ||
567 | killTimer ( m_power_timer ); | ||
568 | m_power_timer = 0; | ||
569 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | ||
570 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | ||
571 | } | ||
572 | |||
573 | |||
574 | void iPAQ::alarmSound ( ) | ||
393 | { | 575 | { |
394 | #if defined( QT_QWS_IPAQ ) // IPAQ | 576 | #if defined( QT_QWS_IPAQ ) // IPAQ |
395 | #ifndef QT_NO_SOUND | 577 | #ifndef QT_NO_SOUND |
396 | static Sound snd ( "alarm" ); | 578 | static Sound snd ( "alarm" ); |
@@ -431,57 +613,16 @@ void ODeviceIPAQ::alarmSound ( ) | |||
431 | #endif | 613 | #endif |
432 | #endif | 614 | #endif |
433 | } | 615 | } |
434 | 616 | ||
435 | uint ODeviceIPAQ::hasLeds ( ) const | ||
436 | { | ||
437 | return 1; | ||
438 | } | ||
439 | |||
440 | OLedState ODeviceIPAQ::led ( uint which ) const | ||
441 | { | ||
442 | if ( which == 0 ) | ||
443 | return d-> m_leds [0]; | ||
444 | else | ||
445 | return OLED_Off; | ||
446 | } | ||
447 | 617 | ||
448 | bool ODeviceIPAQ::setLed ( uint which, OLedState st ) | 618 | bool iPAQ::setSoftSuspend ( bool soft ) |
449 | { | ||
450 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); | ||
451 | |||
452 | if ( which == 0 ) { | ||
453 | if ( fd >= 0 ) { | ||
454 | LED_IN leds; | ||
455 | ::memset ( &leds, 0, sizeof( leds )); | ||
456 | leds. TotalTime = 0; | ||
457 | leds. OnTime = 0; | ||
458 | leds. OffTime = 1; | ||
459 | leds. OffOnBlink = 2; | ||
460 | |||
461 | switch ( st ) { | ||
462 | case OLED_Off : leds. OffOnBlink = 0; break; | ||
463 | case OLED_On : leds. OffOnBlink = 1; break; | ||
464 | case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | ||
465 | case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | ||
466 | } | ||
467 | |||
468 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | ||
469 | d-> m_leds [0] = st; | ||
470 | return true; | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | return false; | ||
475 | } | ||
476 | |||
477 | bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | ||
478 | { | 619 | { |
479 | bool res = false; | 620 | bool res = false; |
480 | int fd; | 621 | int fd; |
481 | 622 | ||
482 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | 623 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { |
483 | if ( ::write ( fd, p == KERNEL ? "0" : "1", 1 ) == 1 ) | 624 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) |
484 | res = true; | 625 | res = true; |
485 | else | 626 | else |
486 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | 627 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); |
487 | 628 | ||
@@ -493,9 +634,9 @@ bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
493 | return res; | 634 | return res; |
494 | } | 635 | } |
495 | 636 | ||
496 | 637 | ||
497 | bool ODeviceIPAQ::setDisplayBrightness ( int bright ) | 638 | bool iPAQ::setDisplayBrightness ( int bright ) |
498 | { | 639 | { |
499 | bool res = false; | 640 | bool res = false; |
500 | int fd; | 641 | int fd; |
501 | 642 | ||
@@ -520,9 +661,9 @@ bool ODeviceIPAQ::setDisplayBrightness ( int bright ) | |||
520 | } | 661 | } |
521 | return res; | 662 | return res; |
522 | } | 663 | } |
523 | 664 | ||
524 | int ODeviceIPAQ::displayBrightnessResolution ( ) const | 665 | int iPAQ::displayBrightnessResolution ( ) const |
525 | { | 666 | { |
526 | return 255; // really 128, but logarithmic control is smoother this way | 667 | return 255; // really 128, but logarithmic control is smoother this way |
527 | } | 668 | } |
528 | 669 | ||
@@ -534,20 +675,20 @@ int ODeviceIPAQ::displayBrightnessResolution ( ) const | |||
534 | **************************************************/ | 675 | **************************************************/ |
535 | 676 | ||
536 | 677 | ||
537 | 678 | ||
538 | void ODeviceZaurus::init ( ) | 679 | void Zaurus::init ( ) |
539 | { | 680 | { |
540 | d-> m_modelstr = "Zaurus SL5000"; | 681 | d-> m_modelstr = "Zaurus SL5000"; |
541 | d-> m_model = OMODEL_Zaurus_SL5000; | 682 | d-> m_model = Model_Zaurus_SL5000; |
542 | d-> m_vendorstr = "Sharp"; | 683 | d-> m_vendorstr = "Sharp"; |
543 | d-> m_vendor = OVENDOR_Sharp; | 684 | d-> m_vendor = Vendor_Sharp; |
544 | 685 | ||
545 | QFile f ( "/proc/filesystems" ); | 686 | QFile f ( "/proc/filesystems" ); |
546 | 687 | ||
547 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { | 688 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { |
548 | d-> m_systemstr = "OpenZaurus"; | 689 | d-> m_systemstr = "OpenZaurus"; |
549 | d-> m_system = OSYSTEM_OpenZaurus; | 690 | d-> m_system = System_OpenZaurus; |
550 | 691 | ||
551 | f. close ( ); | 692 | f. close ( ); |
552 | 693 | ||
553 | f. setName ( "/etc/oz_version" ); | 694 | f. setName ( "/etc/oz_version" ); |
@@ -558,13 +699,13 @@ void ODeviceZaurus::init ( ) | |||
558 | } | 699 | } |
559 | } | 700 | } |
560 | else { | 701 | else { |
561 | d-> m_systemstr = "Zaurus"; | 702 | d-> m_systemstr = "Zaurus"; |
562 | d-> m_system = OSYSTEM_Zaurus; | 703 | d-> m_system = System_Zaurus; |
563 | } | 704 | } |
564 | 705 | ||
565 | 706 | ||
566 | d-> m_leds [0] = OLED_Off; | 707 | m_leds [0] = Led_Off; |
567 | } | 708 | } |
568 | 709 | ||
569 | #include <unistd.h> | 710 | #include <unistd.h> |
570 | #include <fcntl.h> | 711 | #include <fcntl.h> |
@@ -632,73 +773,85 @@ typedef struct sharp_led_status { | |||
632 | 773 | ||
633 | #define FL_IOCTL_STEP_CONTRAST 100 | 774 | #define FL_IOCTL_STEP_CONTRAST 100 |
634 | 775 | ||
635 | 776 | ||
636 | void ODeviceZaurus::buzzer ( int sound ) | 777 | void Zaurus::buzzer ( int sound ) |
637 | { | 778 | { |
638 | static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); | 779 | static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); |
639 | 780 | ||
640 | if ( fd >= 0 ) | 781 | if ( fd >= 0 ) |
641 | ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); | 782 | ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); |
642 | } | 783 | } |
643 | 784 | ||
644 | 785 | ||
645 | void ODeviceZaurus::alarmSound ( ) | 786 | void Zaurus::alarmSound ( ) |
646 | { | 787 | { |
647 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); | 788 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); |
648 | } | 789 | } |
649 | 790 | ||
650 | void ODeviceZaurus::touchSound ( ) | 791 | void Zaurus::touchSound ( ) |
651 | { | 792 | { |
652 | buzzer ( SHARP_BUZ_TOUCHSOUND ); | 793 | buzzer ( SHARP_BUZ_TOUCHSOUND ); |
653 | } | 794 | } |
654 | 795 | ||
655 | void ODeviceZaurus::keySound ( ) | 796 | void Zaurus::keySound ( ) |
656 | { | 797 | { |
657 | buzzer ( SHARP_BUZ_KEYSOUND ); | 798 | buzzer ( SHARP_BUZ_KEYSOUND ); |
658 | } | 799 | } |
659 | 800 | ||
660 | 801 | ||
661 | uint ODeviceZaurus::hasLeds ( ) const | 802 | QValueList <OLed> Zaurus::ledList ( ) const |
803 | { | ||
804 | QValueList <OLed> vl; | ||
805 | vl << Led_Mail; | ||
806 | return vl; | ||
807 | } | ||
808 | |||
809 | QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const | ||
662 | { | 810 | { |
663 | return 1; | 811 | QValueList <OLedState> vl; |
812 | |||
813 | if ( l == Led_Mail ) | ||
814 | vl << Led_Off << Led_On << Led_BlinkSlow; | ||
815 | return vl; | ||
664 | } | 816 | } |
665 | 817 | ||
666 | OLedState ODeviceZaurus::led ( uint which ) const | 818 | OLedState Zaurus::ledState ( OLed which ) const |
667 | { | 819 | { |
668 | if ( which == 0 ) | 820 | if ( which == Led_Mail ) |
669 | return d-> m_leds [0]; | 821 | return m_leds [0]; |
670 | else | 822 | else |
671 | return OLED_Off; | 823 | return Led_Off; |
672 | } | 824 | } |
673 | 825 | ||
674 | bool ODeviceZaurus::setLed ( uint which, OLedState st ) | 826 | bool Zaurus::setLedState ( OLed which, OLedState st ) |
675 | { | 827 | { |
676 | static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); | 828 | static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); |
677 | 829 | ||
678 | if ( which == 0 ) { | 830 | if ( which == Led_Mail ) { |
679 | if ( fd >= 0 ) { | 831 | if ( fd >= 0 ) { |
680 | struct sharp_led_status leds; | 832 | struct sharp_led_status leds; |
681 | ::memset ( &leds, 0, sizeof( leds )); | 833 | ::memset ( &leds, 0, sizeof( leds )); |
682 | leds. which = SHARP_LED_MAIL_EXISTS; | 834 | leds. which = SHARP_LED_MAIL_EXISTS; |
835 | bool ok = true; | ||
683 | 836 | ||
684 | switch ( st ) { | 837 | switch ( st ) { |
685 | case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; | 838 | case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; |
686 | case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; | 839 | case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; |
687 | case OLED_BlinkSlow: | 840 | case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; |
688 | case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; | 841 | default : ok = false; |
689 | } | 842 | } |
690 | 843 | ||
691 | if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { | 844 | if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { |
692 | d-> m_leds [0] = st; | 845 | m_leds [0] = st; |
693 | return true; | 846 | return true; |
694 | } | 847 | } |
695 | } | 848 | } |
696 | } | 849 | } |
697 | return false; | 850 | return false; |
698 | } | 851 | } |
699 | 852 | ||
700 | bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | 853 | bool Zaurus::setSoftSuspend ( bool soft ) |
701 | { | 854 | { |
702 | bool res = false; | 855 | bool res = false; |
703 | int fd; | 856 | int fd; |
704 | 857 | ||
@@ -707,14 +860,14 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
707 | 860 | ||
708 | int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources | 861 | int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources |
709 | 862 | ||
710 | if ( sources >= 0 ) { | 863 | if ( sources >= 0 ) { |
711 | if ( p == KERNEL ) | 864 | if ( soft ) |
712 | sources |= APM_EVT_POWER_BUTTON; | ||
713 | else | ||
714 | sources &= ~APM_EVT_POWER_BUTTON; | 865 | sources &= ~APM_EVT_POWER_BUTTON; |
866 | else | ||
867 | sources |= APM_EVT_POWER_BUTTON; | ||
715 | 868 | ||
716 | if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources & ~APM_EVT_POWER_BUTTON ) >= 0 ) // set new event sources | 869 | if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources |
717 | res = true; | 870 | res = true; |
718 | else | 871 | else |
719 | perror ( "APM_IOCGEVTSRC" ); | 872 | perror ( "APM_IOCGEVTSRC" ); |
720 | } | 873 | } |
@@ -729,9 +882,9 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
729 | return res; | 882 | return res; |
730 | } | 883 | } |
731 | 884 | ||
732 | 885 | ||
733 | bool ODeviceZaurus::setDisplayBrightness ( int bright ) | 886 | bool Zaurus::setDisplayBrightness ( int bright ) |
734 | { | 887 | { |
735 | bool res = false; | 888 | bool res = false; |
736 | int fd; | 889 | int fd; |
737 | 890 | ||
@@ -750,8 +903,16 @@ bool ODeviceZaurus::setDisplayBrightness ( int bright ) | |||
750 | return res; | 903 | return res; |
751 | } | 904 | } |
752 | 905 | ||
753 | 906 | ||
754 | int ODeviceZaurus::displayBrightnessResolution ( ) const | 907 | int Zaurus::displayBrightnessResolution ( ) const |
755 | { | 908 | { |
756 | return 4; | 909 | return 4; |
757 | } | 910 | } |
911 | |||
912 | //QValueList <int> Zaurus::keyList ( ) const | ||
913 | //{ | ||
914 | //QValueList <int> vl; | ||
915 | //vl << HardKey_Datebook << HardKey_Contacts << HardKey_Mail << HardKey_Menu << HardKey_Home << HardKey_Suspend << HardKey_Backlight; | ||
916 | //return vl; | ||
917 | //} | ||
918 | |||