-rw-r--r-- | libopie/odevice.cpp | 407 | ||||
-rw-r--r-- | libopie/odevice.h | 121 |
2 files changed, 355 insertions, 173 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 3bc1e0c..c84312e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -37,4 +37,7 @@ | |||
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 | ||
@@ -46,7 +49,10 @@ | |||
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; |
@@ -59,14 +65,13 @@ public: | |||
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 ); |
@@ -75,15 +80,26 @@ public: | |||
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 ); |
@@ -94,10 +110,15 @@ public: | |||
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 | ||
@@ -105,4 +126,7 @@ protected: | |||
105 | 126 | ||
106 | 127 | ||
128 | |||
129 | |||
130 | |||
107 | ODevice *ODevice::inst ( ) | 131 | ODevice *ODevice::inst ( ) |
108 | { | 132 | { |
@@ -111,7 +135,7 @@ ODevice *ODevice::inst ( ) | |||
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 ( ); |
@@ -134,10 +158,12 @@ ODevice::ODevice ( ) | |||
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 | } |
@@ -152,5 +178,5 @@ ODevice::~ODevice ( ) | |||
152 | } | 178 | } |
153 | 179 | ||
154 | bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | 180 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
155 | { | 181 | { |
156 | return false; | 182 | return false; |
@@ -164,5 +190,8 @@ bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | |||
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 | ||
@@ -174,5 +203,5 @@ bool ODevice::suspend ( ) | |||
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 | ||
@@ -180,7 +209,8 @@ bool ODevice::suspend ( ) | |||
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 |
@@ -189,9 +219,8 @@ bool ODevice::suspend ( ) | |||
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 | ||
@@ -212,5 +241,5 @@ bool ODevice::suspend ( ) | |||
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 | ||
@@ -235,35 +264,35 @@ int ODevice::displayBrightnessResolution ( ) const | |||
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; |
@@ -307,15 +336,21 @@ void ODevice::touchSound ( ) | |||
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; |
@@ -324,4 +359,10 @@ bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) | |||
324 | 359 | ||
325 | 360 | ||
361 | //QValueList <int> ODevice::keyList ( ) const | ||
362 | //{ | ||
363 | //return QValueList <int> ( ); | ||
364 | //} | ||
365 | |||
366 | |||
326 | 367 | ||
327 | /************************************************** | 368 | /************************************************** |
@@ -331,8 +372,8 @@ bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) | |||
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" ); |
@@ -344,13 +385,13 @@ void ODeviceIPAQ::init ( ) | |||
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 ( ); |
@@ -360,5 +401,5 @@ void ODeviceIPAQ::init ( ) | |||
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 ); |
@@ -368,5 +409,10 @@ void ODeviceIPAQ::init ( ) | |||
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 | ||
@@ -390,5 +436,141 @@ typedef struct { | |||
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 |
@@ -433,47 +615,6 @@ void ODeviceIPAQ::alarmSound ( ) | |||
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; |
@@ -481,5 +622,5 @@ bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
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 |
@@ -495,5 +636,5 @@ bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
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; |
@@ -522,5 +663,5 @@ bool ODeviceIPAQ::setDisplayBrightness ( int bright ) | |||
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 |
@@ -536,10 +677,10 @@ int ODeviceIPAQ::displayBrightnessResolution ( ) const | |||
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" ); |
@@ -547,5 +688,5 @@ void ODeviceZaurus::init ( ) | |||
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 ( ); |
@@ -560,9 +701,9 @@ void ODeviceZaurus::init ( ) | |||
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 | ||
@@ -634,5 +775,5 @@ typedef struct sharp_led_status { | |||
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 ); |
@@ -643,15 +784,15 @@ void ODeviceZaurus::buzzer ( int sound ) | |||
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 ); |
@@ -659,36 +800,48 @@ void ODeviceZaurus::keySound ( ) | |||
659 | 800 | ||
660 | 801 | ||
661 | uint ODeviceZaurus::hasLeds ( ) const | 802 | QValueList <OLed> Zaurus::ledList ( ) const |
662 | { | 803 | { |
663 | return 1; | 804 | QValueList <OLed> vl; |
805 | vl << Led_Mail; | ||
806 | return vl; | ||
664 | } | 807 | } |
665 | 808 | ||
666 | OLedState ODeviceZaurus::led ( uint which ) const | 809 | QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const |
667 | { | 810 | { |
668 | if ( which == 0 ) | 811 | QValueList <OLedState> vl; |
669 | return d-> m_leds [0]; | 812 | |
813 | if ( l == Led_Mail ) | ||
814 | vl << Led_Off << Led_On << Led_BlinkSlow; | ||
815 | return vl; | ||
816 | } | ||
817 | |||
818 | OLedState Zaurus::ledState ( OLed which ) const | ||
819 | { | ||
820 | if ( which == Led_Mail ) | ||
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 | } |
@@ -698,5 +851,5 @@ bool ODeviceZaurus::setLed ( uint which, OLedState st ) | |||
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; |
@@ -709,10 +862,10 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
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 |
@@ -731,5 +884,5 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) | |||
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; |
@@ -752,6 +905,14 @@ bool ODeviceZaurus::setDisplayBrightness ( int bright ) | |||
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 | |||
diff --git a/libopie/odevice.h b/libopie/odevice.h index 2f676ff..38f3787 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h | |||
@@ -22,39 +22,58 @@ | |||
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | 24 | #include <qnamespace.h> | |
25 | 25 | ||
26 | class ODeviceData; | 26 | class ODeviceData; |
27 | 27 | ||
28 | namespace Opie { | ||
29 | |||
28 | enum OModel { | 30 | enum OModel { |
29 | OMODEL_Unknown, | 31 | Model_Unknown, |
30 | 32 | ||
31 | OMODEL_iPAQ_H31xx, | 33 | Model_iPAQ_H31xx, |
32 | OMODEL_iPAQ_H36xx, | 34 | Model_iPAQ_H36xx, |
33 | OMODEL_iPAQ_H37xx, | 35 | Model_iPAQ_H37xx, |
34 | OMODEL_iPAQ_H38xx, | 36 | Model_iPAQ_H38xx, |
35 | 37 | ||
36 | OMODEL_Zaurus_SL5000 | 38 | Model_Zaurus_SL5000 |
37 | }; | 39 | }; |
38 | 40 | ||
39 | enum OVendor { | 41 | enum OVendor { |
40 | OVENDOR_Unknown, | 42 | Vendor_Unknown, |
41 | 43 | ||
42 | OVENDOR_HP, | 44 | Vendor_HP, |
43 | OVENDOR_Sharp | 45 | Vendor_Sharp |
44 | }; | 46 | }; |
45 | 47 | ||
46 | enum OSystem { | 48 | enum OSystem { |
47 | OSYSTEM_Unknown, | 49 | System_Unknown, |
48 | 50 | ||
49 | OSYSTEM_Familiar, | 51 | System_Familiar, |
50 | OSYSTEM_Zaurus, | 52 | System_Zaurus, |
51 | OSYSTEM_OpenZaurus | 53 | System_OpenZaurus |
52 | }; | 54 | }; |
53 | 55 | ||
54 | enum OLedState { | 56 | enum OLedState { |
55 | OLED_Off, | 57 | Led_Off, |
56 | OLED_On, | 58 | Led_On, |
57 | OLED_BlinkSlow, | 59 | Led_BlinkSlow, |
58 | OLED_BlinkFast | 60 | Led_BlinkFast |
61 | }; | ||
62 | |||
63 | enum OLed { | ||
64 | Led_Mail, | ||
65 | Led_Power, | ||
66 | Led_BlueTooth | ||
67 | }; | ||
68 | |||
69 | enum OHardKey { | ||
70 | HardKey_Datebook = Qt::Key_F9, | ||
71 | HardKey_Contacts = Qt::Key_F10, | ||
72 | HardKey_Menu = Qt::Key_F11, | ||
73 | HardKey_Home = Qt::Key_F12, | ||
74 | HardKey_Mail = Qt::Key_F14, | ||
75 | HardKey_Record = Qt::Key_F24, | ||
76 | HardKey_Suspend = Qt::Key_F34, | ||
77 | HardKey_Backlight = Qt::Key_F35, | ||
59 | }; | 78 | }; |
60 | 79 | ||
@@ -62,32 +81,41 @@ enum OLedState { | |||
62 | class ODevice | 81 | class ODevice |
63 | { | 82 | { |
83 | private: | ||
84 | ODevice ( const ODevice & ); | ||
85 | |||
86 | protected: | ||
87 | ODevice ( ); | ||
88 | virtual void init ( ); | ||
89 | |||
90 | ODeviceData *d; | ||
91 | |||
64 | public: | 92 | public: |
65 | static ODevice *inst ( ); | 93 | virtual ~ODevice ( ); |
66 | 94 | ||
67 | // system | 95 | static ODevice *inst ( ); |
68 | enum PowerButtonHandler { | ||
69 | KERNEL, | ||
70 | OPIE | ||
71 | }; | ||
72 | 96 | ||
73 | virtual bool setPowerButtonHandler ( PowerButtonHandler h ); | ||
74 | virtual bool suspend ( ); | ||
75 | 97 | ||
76 | virtual bool setDisplayStatus ( bool on ); | ||
77 | virtual bool setDisplayBrightness ( int brightness ); | ||
78 | virtual int displayBrightnessResolution ( ) const; | ||
79 | 98 | ||
80 | // information | 99 | // information |
81 | 100 | ||
82 | QString modelString ( ); | 101 | QString modelString ( ) const; |
83 | OModel model ( ); | 102 | OModel model ( ) const; |
103 | |||
104 | QString vendorString ( ) const; | ||
105 | OVendor vendor ( ) const; | ||
84 | 106 | ||
85 | QString vendorString ( ); | 107 | QString systemString ( ) const; |
86 | OVendor vendor ( ); | 108 | OSystem system ( ) const; |
87 | 109 | ||
88 | QString systemString ( ); | 110 | QString systemVersionString ( ) const; |
89 | OSystem system ( ); | ||
90 | 111 | ||
91 | QString systemVersionString ( ); | 112 | // system |
113 | |||
114 | virtual bool setSoftSuspend ( bool on ); | ||
115 | virtual bool suspend ( ); | ||
116 | |||
117 | virtual bool setDisplayStatus ( bool on ); | ||
118 | virtual bool setDisplayBrightness ( int brightness ); | ||
119 | virtual int displayBrightnessResolution ( ) const; | ||
92 | 120 | ||
93 | // input / output | 121 | // input / output |
@@ -97,21 +125,14 @@ public: | |||
97 | virtual void touchSound ( ); | 125 | virtual void touchSound ( ); |
98 | 126 | ||
99 | virtual uint hasLeds ( ) const; | 127 | virtual QValueList <OLed> ledList ( ) const; |
100 | virtual OLedState led ( uint which ) const; | 128 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
101 | virtual bool setLed ( uint which, OLedState st ); | 129 | virtual OLedState ledState ( OLed led ) const; |
102 | 130 | virtual bool setLedState ( OLed led, OLedState st ); | |
103 | virtual ~ODevice ( ); | ||
104 | |||
105 | protected: | ||
106 | ODevice ( ); | ||
107 | virtual void init ( ); | ||
108 | 131 | ||
109 | ODeviceData *d; | 132 | //virtual QValueList <int> keyList ( ) const; |
110 | |||
111 | private: | ||
112 | ODevice ( const ODevice & ); | ||
113 | }; | 133 | }; |
114 | 134 | ||
115 | #endif | 135 | } |
116 | 136 | ||
137 | #endif | ||
117 | 138 | ||