summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-30 21:09:13 (UTC)
committer sandman <sandman>2002-09-30 21:09:13 (UTC)
commit3ff016b281a3c059e6ecb728c60fd6847756f291 (patch) (unidiff)
tree6d7b341ef586552b1a2154af047b41fb567b59d9
parent5158385997be6b64cab623674f9e9e1835f94fc6 (diff)
downloadopie-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"
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp409
-rw-r--r--libopie/odevice.h121
2 files changed, 356 insertions, 174 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 3bc1e0c..c84312e 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -36,6 +36,9 @@
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 ))
@@ -45,9 +48,12 @@
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
51using namespace Opie;
48 52
49class ODeviceData { 53class ODeviceData {
50public: 54public:
55 bool m_qwsserver;
56
51 QString m_vendorstr; 57 QString m_vendorstr;
52 OVendor m_vendor; 58 OVendor m_vendor;
53 59
@@ -58,33 +64,43 @@ public:
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
65class ODeviceIPAQ : public ODevice { 69
70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter {
66protected: 71protected:
67 virtual void init ( ); 72 virtual void init ( );
68 73
69public: 74public:
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
89protected:
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
82class ODeviceZaurus : public ODevice { 98class Zaurus : public ODevice {
83protected: 99protected:
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;
@@ -93,26 +109,34 @@ public:
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
100protected: 119protected:
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
107ODevice *ODevice::inst ( ) 131ODevice *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
@@ -133,12 +157,14 @@ 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
@@ -151,7 +177,7 @@ ODevice::~ODevice ( )
151 delete d; 177 delete d;
152} 178}
153 179
154bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) 180bool ODevice::setSoftSuspend ( bool /*soft*/ )
155{ 181{
156 return false; 182 return false;
157} 183}
@@ -163,7 +189,10 @@ bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler )
163 189
164bool ODevice::suspend ( ) 190bool 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;
@@ -173,26 +202,26 @@ bool ODevice::suspend ( )
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;
@@ -211,7 +240,7 @@ bool ODevice::suspend ( )
211 240
212bool ODevice::setDisplayStatus ( bool on ) 241bool 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;
@@ -234,37 +263,37 @@ int ODevice::displayBrightnessResolution ( ) const
234 return 16; 263 return 16;
235} 264}
236 265
237QString ODevice::vendorString ( ) 266QString ODevice::vendorString ( ) const
238{ 267{
239 return d-> m_vendorstr; 268 return d-> m_vendorstr;
240} 269}
241 270
242OVendor ODevice::vendor ( ) 271OVendor ODevice::vendor ( ) const
243{ 272{
244 return d-> m_vendor; 273 return d-> m_vendor;
245} 274}
246 275
247QString ODevice::modelString ( ) 276QString ODevice::modelString ( ) const
248{ 277{
249 return d-> m_modelstr; 278 return d-> m_modelstr;
250} 279}
251 280
252OModel ODevice::model ( ) 281OModel ODevice::model ( ) const
253{ 282{
254 return d-> m_model; 283 return d-> m_model;
255} 284}
256 285
257QString ODevice::systemString ( ) 286QString ODevice::systemString ( ) const
258{ 287{
259 return d-> m_systemstr; 288 return d-> m_systemstr;
260} 289}
261 290
262OSystem ODevice::system ( ) 291OSystem ODevice::system ( ) const
263{ 292{
264 return d-> m_system; 293 return d-> m_system;
265} 294}
266 295
267QString ODevice::systemVersionString ( ) 296QString ODevice::systemVersionString ( ) const
268{ 297{
269 return d-> m_sysverstr; 298 return d-> m_sysverstr;
270} 299}
@@ -306,23 +335,35 @@ void ODevice::touchSound ( )
306#endif 335#endif
307} 336}
308 337
309uint ODevice::hasLeds ( ) const 338
339QValueList <OLed> ODevice::ledList ( ) const
340{
341 return QValueList <OLed> ( );
342}
343
344QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
310{ 345{
311 return 0; 346 return QValueList <OLedState> ( );
312} 347}
313 348
314OLedState ODevice::led ( uint /*which*/ ) const 349OLedState ODevice::ledState ( OLed /*which*/ ) const
315{ 350{
316 return OLED_Off; 351 return Led_Off;
317} 352}
318 353
319bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ ) 354bool 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 *
@@ -330,10 +371,10 @@ bool ODevice::setLed ( uint /*which*/, OLedState /*st*/ )
330 * 371 *
331 **************************************************/ 372 **************************************************/
332 373
333void ODeviceIPAQ::init ( ) 374void 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
@@ -343,15 +384,15 @@ void ODeviceIPAQ::init ( )
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 }
@@ -359,7 +400,7 @@ void ODeviceIPAQ::init ( )
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 );
@@ -367,7 +408,12 @@ void ODeviceIPAQ::init ( )
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 ...
@@ -389,7 +435,143 @@ typedef struct {
389#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 435#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
390 436
391 437
392void ODeviceIPAQ::alarmSound ( ) 438
439QValueList <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
449QValueList <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
461OLedState 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
473bool 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
510bool 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
565void 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
574void 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
@@ -432,55 +614,14 @@ void ODeviceIPAQ::alarmSound ( )
432#endif 614#endif
433} 615}
434 616
435uint ODeviceIPAQ::hasLeds ( ) const
436{
437 return 1;
438}
439
440OLedState 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
448bool ODeviceIPAQ::setLed ( uint which, OLedState st ) 618bool 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
477bool 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" );
@@ -494,7 +635,7 @@ bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
494} 635}
495 636
496 637
497bool ODeviceIPAQ::setDisplayBrightness ( int bright ) 638bool iPAQ::setDisplayBrightness ( int bright )
498{ 639{
499 bool res = false; 640 bool res = false;
500 int fd; 641 int fd;
@@ -521,7 +662,7 @@ bool ODeviceIPAQ::setDisplayBrightness ( int bright )
521 return res; 662 return res;
522} 663}
523 664
524int ODeviceIPAQ::displayBrightnessResolution ( ) const 665int 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}
@@ -535,18 +676,18 @@ int ODeviceIPAQ::displayBrightnessResolution ( ) const
535 676
536 677
537 678
538void ODeviceZaurus::init ( ) 679void 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
@@ -559,11 +700,11 @@ void ODeviceZaurus::init ( )
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>
@@ -633,7 +774,7 @@ typedef struct sharp_led_status {
633#define FL_IOCTL_STEP_CONTRAST 100 774#define FL_IOCTL_STEP_CONTRAST 100
634 775
635 776
636void ODeviceZaurus::buzzer ( int sound ) 777void 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
@@ -642,54 +783,66 @@ void ODeviceZaurus::buzzer ( int sound )
642} 783}
643 784
644 785
645void ODeviceZaurus::alarmSound ( ) 786void Zaurus::alarmSound ( )
646{ 787{
647 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 788 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
648} 789}
649 790
650void ODeviceZaurus::touchSound ( ) 791void Zaurus::touchSound ( )
651{ 792{
652 buzzer ( SHARP_BUZ_TOUCHSOUND ); 793 buzzer ( SHARP_BUZ_TOUCHSOUND );
653} 794}
654 795
655void ODeviceZaurus::keySound ( ) 796void Zaurus::keySound ( )
656{ 797{
657 buzzer ( SHARP_BUZ_KEYSOUND ); 798 buzzer ( SHARP_BUZ_KEYSOUND );
658} 799}
659 800
660 801
661uint ODeviceZaurus::hasLeds ( ) const 802QValueList <OLed> Zaurus::ledList ( ) const
803{
804 QValueList <OLed> vl;
805 vl << Led_Mail;
806 return vl;
807}
808
809QValueList <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
666OLedState ODeviceZaurus::led ( uint which ) const 818OLedState 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
674bool ODeviceZaurus::setLed ( uint which, OLedState st ) 826bool 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 }
@@ -697,7 +850,7 @@ bool ODeviceZaurus::setLed ( uint which, OLedState st )
697 return false; 850 return false;
698} 851}
699 852
700bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p ) 853bool Zaurus::setSoftSuspend ( bool soft )
701{ 854{
702 bool res = false; 855 bool res = false;
703 int fd; 856 int fd;
@@ -708,12 +861,12 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
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" );
@@ -730,7 +883,7 @@ bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
730} 883}
731 884
732 885
733bool ODeviceZaurus::setDisplayBrightness ( int bright ) 886bool Zaurus::setDisplayBrightness ( int bright )
734{ 887{
735 bool res = false; 888 bool res = false;
736 int fd; 889 int fd;
@@ -751,7 +904,15 @@ bool ODeviceZaurus::setDisplayBrightness ( int bright )
751} 904}
752 905
753 906
754int ODeviceZaurus::displayBrightnessResolution ( ) const 907int 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
@@ -21,97 +21,118 @@
21#define _LIBOPIE_ODEVICE_H_ 21#define _LIBOPIE_ODEVICE_H_
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24#include <qnamespace.h>
25 25
26class ODeviceData; 26class ODeviceData;
27 27
28namespace Opie {
29
28enum OModel { 30enum 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
46enum OSystem { 48enum 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
54enum OLedState { 56enum 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
63enum OLed {
64 Led_Mail,
65 Led_Power,
66 Led_BlueTooth
67};
68
69enum 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
61 80
62class ODevice 81class ODevice
63{ 82{
83private:
84 ODevice ( const ODevice & );
85
86protected:
87 ODevice ( );
88 virtual void init ( );
89
90 ODeviceData *d;
91
64public: 92public:
93 virtual ~ODevice ( );
94
65 static ODevice *inst ( ); 95 static ODevice *inst ( );
66 96
67 // system
68 enum PowerButtonHandler {
69 KERNEL,
70 OPIE
71 };
72 97
73 virtual bool setPowerButtonHandler ( PowerButtonHandler h );
74 virtual bool suspend ( );
75 98
76 virtual bool setDisplayStatus ( bool on );
77 virtual bool setDisplayBrightness ( int brightness );
78 virtual int displayBrightnessResolution ( ) const;
79
80// information 99// information
81 100
82 QString modelString ( ); 101 QString modelString ( ) const;
83 OModel model ( ); 102 OModel model ( ) const;
84 103
85 QString vendorString ( ); 104 QString vendorString ( ) const;
86 OVendor vendor ( ); 105 OVendor vendor ( ) const;
106
107 QString systemString ( ) const;
108 OSystem system ( ) const;
109
110 QString systemVersionString ( ) const;
87 111
88 QString systemString ( ); 112 // system
89 OSystem system ( );
90 113
91 QString systemVersionString ( ); 114 virtual bool setSoftSuspend ( bool on );
115 virtual bool suspend ( );
92 116
117 virtual bool setDisplayStatus ( bool on );
118 virtual bool setDisplayBrightness ( int brightness );
119 virtual int displayBrightnessResolution ( ) const;
120
93// input / output 121// input / output
94 122
95 virtual void alarmSound ( ); 123 virtual void alarmSound ( );
96 virtual void keySound ( ); 124 virtual void keySound ( );
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 131
105protected: 132 //virtual QValueList <int> keyList ( ) const;
106 ODevice ( );
107 virtual void init ( );
108
109 ODeviceData *d;
110
111private:
112 ODevice ( const ODevice & );
113}; 133};
114 134
115#endif 135}
116 136
137#endif
117 138