summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-05 21:23:09 (UTC)
committer sandman <sandman>2002-09-05 21:23:09 (UTC)
commitbaea6aaf4f0c9672a4383470a9389bca1a20bdba (patch) (unidiff)
treedef42730d45a0aa47eeb4f637cf140633b8d2c7c
parent930e178bf07eb5685852f56a3ecb05b8b823f42c (diff)
downloadopie-baea6aaf4f0c9672a4383470a9389bca1a20bdba.zip
opie-baea6aaf4f0c9672a4383470a9389bca1a20bdba.tar.gz
opie-baea6aaf4f0c9672a4383470a9389bca1a20bdba.tar.bz2
- added a setPowerButtonHandler() for iPAQs and Zs
(-> disableAPM() in launcher can be removed) - another try to fix the OZ suspend code
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp70
-rw-r--r--libopie/odevice.h6
2 files changed, 71 insertions, 5 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 2f40731..95fd6bd 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -14,186 +14,195 @@
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <sys/ioctl.h> 23#include <sys/ioctl.h>
24#include <signal.h> 24#include <signal.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#include <linux/soundcard.h> 26#include <linux/soundcard.h>
27 27
28#include <qapplication.h> 28#include <qapplication.h>
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qtextstream.h> 31#include <qtextstream.h>
32#include <qpe/sound.h> 32#include <qpe/sound.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35 35
36 36
37 37
38#include "odevice.h" 38#include "odevice.h"
39 39
40 40
41class ODeviceData { 41class ODeviceData {
42public: 42public:
43 QString m_vendorstr; 43 QString m_vendorstr;
44 OVendor m_vendor; 44 OVendor m_vendor;
45 45
46 QString m_modelstr; 46 QString m_modelstr;
47 OModel m_model; 47 OModel m_model;
48 48
49 QString m_systemstr; 49 QString m_systemstr;
50 OSystem m_system; 50 OSystem m_system;
51 51
52 QString m_sysverstr; 52 QString m_sysverstr;
53 53
54 OLedState m_leds [4]; // just for convenience ... 54 OLedState m_leds [4]; // just for convenience ...
55}; 55};
56 56
57class ODeviceIPAQ : public ODevice { 57class ODeviceIPAQ : public ODevice {
58protected: 58protected:
59 virtual void init ( ); 59 virtual void init ( );
60 60
61public: 61public:
62 virtual bool setPowerButtonHandler ( PowerButtonHandler h );
63
62 virtual void alarmSound ( ); 64 virtual void alarmSound ( );
63 65
64 virtual uint hasLeds ( ) const; 66 virtual uint hasLeds ( ) const;
65 virtual OLedState led ( uint which ) const; 67 virtual OLedState led ( uint which ) const;
66 virtual bool setLed ( uint which, OLedState st ); 68 virtual bool setLed ( uint which, OLedState st );
67}; 69};
68 70
69class ODeviceZaurus : public ODevice { 71class ODeviceZaurus : public ODevice {
70protected: 72protected:
71 virtual void init ( ); 73 virtual void init ( );
72 74
73 public: 75 public:
76 virtual bool setPowerButtonHandler ( PowerButtonHandler h );
77
74 virtual void alarmSound ( ); 78 virtual void alarmSound ( );
75 virtual void keySound ( ); 79 virtual void keySound ( );
76 virtual void touchSound ( ); 80 virtual void touchSound ( );
77 81
78 virtual uint hasLeds ( ) const; 82 virtual uint hasLeds ( ) const;
79 virtual OLedState led ( uint which ) const; 83 virtual OLedState led ( uint which ) const;
80 virtual bool setLed ( uint which, OLedState st ); 84 virtual bool setLed ( uint which, OLedState st );
81 85
82protected: 86protected:
83 virtual void buzzer ( int snd ); 87 virtual void buzzer ( int snd );
84}; 88};
85 89
86 90
87 91
88 92
89ODevice *ODevice::inst ( ) 93ODevice *ODevice::inst ( )
90{ 94{
91 static ODevice *dev = 0; 95 static ODevice *dev = 0;
92 96
93 if ( !dev ) { 97 if ( !dev ) {
94 if ( QFile::exists ( "/proc/hal/model" )) 98 if ( QFile::exists ( "/proc/hal/model" ))
95 dev = new ODeviceIPAQ ( ); 99 dev = new ODeviceIPAQ ( );
96 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 100 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
97 dev = new ODeviceZaurus ( ); 101 dev = new ODeviceZaurus ( );
98 else 102 else
99 dev = new ODevice ( ); 103 dev = new ODevice ( );
100 104
101 dev-> init ( ); 105 dev-> init ( );
102 } 106 }
103 return dev; 107 return dev;
104} 108}
105 109
106ODevice::ODevice ( ) 110ODevice::ODevice ( )
107{ 111{
108 d = new ODeviceData; 112 d = new ODeviceData;
109 113
110 d-> m_modelstr = "Unknown"; 114 d-> m_modelstr = "Unknown";
111 d-> m_model = OMODEL_Unknown; 115 d-> m_model = OMODEL_Unknown;
112 d-> m_vendorstr = "Unkown"; 116 d-> m_vendorstr = "Unkown";
113 d-> m_vendor = OVENDOR_Unknown; 117 d-> m_vendor = OVENDOR_Unknown;
114 d-> m_systemstr = "Unkown"; 118 d-> m_systemstr = "Unkown";
115 d-> m_system = OSYSTEM_Unknown; 119 d-> m_system = OSYSTEM_Unknown;
116 d-> m_sysverstr = "0.0"; 120 d-> m_sysverstr = "0.0";
117} 121}
118 122
119void ODevice::init ( ) 123void ODevice::init ( )
120{ 124{
121} 125}
122 126
123ODevice::~ODevice ( ) 127ODevice::~ODevice ( )
124{ 128{
125 delete d; 129 delete d;
126} 130}
127 131
128//#include <linux/apm_bios.h> 132//#include <linux/apm_bios.h>
129 133
130//#define APM_IOC_SUSPEND _IO('A',2) 134//#define APM_IOC_SUSPEND _IO('A',2)
131 135
132#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 )) 136#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 ))
133 137
138bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler )
139{
140 return false;
141}
142
134bool ODevice::suspend ( ) 143bool ODevice::suspend ( )
135{ 144{
136 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices 145 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices
137 return false; 146 return false;
138 147
139 int fd; 148 int fd;
140 bool res = false; 149 bool res = false;
141 150
142 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 151 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
143 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 152 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
144 struct timeval tvs, tvn; 153 struct timeval tvs, tvn;
145 154
146 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped 155 ::signal ( SIGTSTP, SIG_IGN );// we don't want to be stopped
147 ::gettimeofday ( &tvs, 0 ); 156 ::gettimeofday ( &tvs, 0 );
148 157
149 ::sync ( ); // flush fs caches 158 ::sync ( ); // flush fs caches
150 159
151 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); // tell the kernel to "start" suspending 160 res = ( ::ioctl ( fd, APM_IOC_SUSPEND, 0 ) == 0 ); // tell the kernel to "start" suspending
152 161
153 if ( res ) { 162 if ( res ) {
154 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group 163 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in our process group
155 164
156 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 165 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
157 ::usleep ( 200 * 1000 ); 166 ::usleep ( 200 * 1000 );
158 ::gettimeofday ( &tvn, 0 ); 167 ::gettimeofday ( &tvn, 0 );
159 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 168 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
160 169
161 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group 170 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
162 } 171 }
163 172
164 ::close ( fd ); 173 ::close ( fd );
165 ::signal ( SIGTSTP, SIG_DFL ); 174 ::signal ( SIGTSTP, SIG_DFL );
166 } 175 }
167 176
168 return res; 177 return res;
169} 178}
170 179
171 180
172QString ODevice::vendorString ( ) 181QString ODevice::vendorString ( )
173{ 182{
174 return d-> m_vendorstr; 183 return d-> m_vendorstr;
175} 184}
176 185
177OVendor ODevice::vendor ( ) 186OVendor ODevice::vendor ( )
178{ 187{
179 return d-> m_vendor; 188 return d-> m_vendor;
180} 189}
181 190
182QString ODevice::modelString ( ) 191QString ODevice::modelString ( )
183{ 192{
184 return d-> m_modelstr; 193 return d-> m_modelstr;
185} 194}
186 195
187OModel ODevice::model ( ) 196OModel ODevice::model ( )
188{ 197{
189 return d-> m_model; 198 return d-> m_model;
190} 199}
191 200
192QString ODevice::systemString ( ) 201QString ODevice::systemString ( )
193{ 202{
194 return d-> m_systemstr; 203 return d-> m_systemstr;
195} 204}
196 205
197OSystem ODevice::system ( ) 206OSystem ODevice::system ( )
198{ 207{
199 return d-> m_system; 208 return d-> m_system;
@@ -359,205 +368,256 @@ void ODeviceIPAQ::alarmSound ( )
359 ::close ( fd ); 368 ::close ( fd );
360 } 369 }
361#endif 370#endif
362#endif 371#endif
363} 372}
364 373
365uint ODeviceIPAQ::hasLeds ( ) const 374uint ODeviceIPAQ::hasLeds ( ) const
366{ 375{
367 return 1; 376 return 1;
368} 377}
369 378
370OLedState ODeviceIPAQ::led ( uint which ) const 379OLedState ODeviceIPAQ::led ( uint which ) const
371{ 380{
372 if ( which == 0 ) 381 if ( which == 0 )
373 return d-> m_leds [0]; 382 return d-> m_leds [0];
374 else 383 else
375 return OLED_Off; 384 return OLED_Off;
376} 385}
377 386
378bool ODeviceIPAQ::setLed ( uint which, OLedState st ) 387bool ODeviceIPAQ::setLed ( uint which, OLedState st )
379{ 388{
380 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK ); 389 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR|O_NONBLOCK );
381 390
382 if ( which == 0 ) { 391 if ( which == 0 ) {
383 if ( fd >= 0 ) { 392 if ( fd >= 0 ) {
384 struct h3600_ts_led leds; 393 struct h3600_ts_led leds;
385 ::memset ( &leds, 0, sizeof( leds )); 394 ::memset ( &leds, 0, sizeof( leds ));
386 leds. TotalTime = 0; 395 leds. TotalTime = 0;
387 leds. OnTime = 0; 396 leds. OnTime = 0;
388 leds. OffTime = 1; 397 leds. OffTime = 1;
389 leds. OffOnBlink = 2; 398 leds. OffOnBlink = 2;
390 399
391 switch ( st ) { 400 switch ( st ) {
392 case OLED_Off : leds. OffOnBlink = 0; break; 401 case OLED_Off : leds. OffOnBlink = 0; break;
393 case OLED_On : leds. OffOnBlink = 1; break; 402 case OLED_On : leds. OffOnBlink = 1; break;
394 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 403 case OLED_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
395 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 404 case OLED_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
396 } 405 }
397 406
398 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 407 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
399 d-> m_leds [0] = st; 408 d-> m_leds [0] = st;
400 return true; 409 return true;
401 } 410 }
402 } 411 }
403 } 412 }
404 return false; 413 return false;
405} 414}
406 415
407 416bool ODeviceIPAQ::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
408//#endif 417{
418 bool res = false;
419 int fd;
420
421 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
422 if ( ::write ( fd, p == KERNEL ? "0" : "1", 1 ) == 1 )
423 res = true;
424 else
425 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
426
427 ::close ( fd );
428 }
429 else
430 ::perror ( "/proc/sys/ts/suspend_button_mode" );
431
432 return res;
433}
409 434
410 435
411 436
412 437
413 438
414//#if defined( QT_QWS_EBX ) // Zaurus
415 439
416void ODeviceZaurus::init ( ) 440void ODeviceZaurus::init ( )
417{ 441{
418 d-> m_modelstr = "Zaurus SL5000"; 442 d-> m_modelstr = "Zaurus SL5000";
419 d-> m_model = OMODEL_Zaurus_SL5000; 443 d-> m_model = OMODEL_Zaurus_SL5000;
420 d-> m_vendorstr = "Sharp"; 444 d-> m_vendorstr = "Sharp";
421 d-> m_vendor = OVENDOR_Sharp; 445 d-> m_vendor = OVENDOR_Sharp;
422 446
423 QFile f ( "/proc/filesystems" ); 447 QFile f ( "/proc/filesystems" );
424 448
425 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 449 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
426 d-> m_systemstr = "OpenZaurus"; 450 d-> m_systemstr = "OpenZaurus";
427 d-> m_system = OSYSTEM_OpenZaurus; 451 d-> m_system = OSYSTEM_OpenZaurus;
428 452
429 f. close ( ); 453 f. close ( );
430 } 454 }
431 else { 455 else {
432 d-> m_systemstr = "Zaurus"; 456 d-> m_systemstr = "Zaurus";
433 d-> m_system = OSYSTEM_Zaurus; 457 d-> m_system = OSYSTEM_Zaurus;
434 } 458 }
435 459
436 d-> m_leds [0] = OLED_Off; 460 d-> m_leds [0] = OLED_Off;
437} 461}
438 462
439#include <unistd.h> 463#include <unistd.h>
440#include <fcntl.h> 464#include <fcntl.h>
441#include <sys/ioctl.h> 465#include <sys/ioctl.h>
442 466
443//#include <asm/sharp_char.h> // including kernel headers is evil ... 467//#include <asm/sharp_char.h> // including kernel headers is evil ...
444 468
445#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 469#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
446 470
447 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 471 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
448#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 472#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
449 473
450#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 474#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
451#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 475#define SHARP_BUZ_KEYSOUND 2 /* key sound */
452#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 476#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
453 477
454/* --- for SHARP_BUZZER device --- */ 478/* --- for SHARP_BUZZER device --- */
455 479
456 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 480 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
457//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 481//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
458 482
459#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 483#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
460#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 484#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
461#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 485#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
462#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 486#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
463#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 487#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
464 488
465//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 489//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
466//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 490//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
467 491
468//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 492//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
469//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 493//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
470//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 494//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
471//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 495//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
472//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 496//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
473//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 497//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
474//#define SHARP_PDA_APPSTART 9 /* application start */ 498//#define SHARP_PDA_APPSTART 9 /* application start */
475//#define SHARP_PDA_APPQUIT 10 /* application ends */ 499//#define SHARP_PDA_APPQUIT 10 /* application ends */
476 500
477//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 501//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
478//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 502//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
479//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 503//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
480//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 504//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
481// 505//
482 506
483 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 507 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
484#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 508#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
485 509
486typedef struct sharp_led_status { 510typedef struct sharp_led_status {
487 int which; /* select which LED status is wanted. */ 511 int which; /* select which LED status is wanted. */
488 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 512 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
489} sharp_led_status; 513} sharp_led_status;
490 514
491#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 515#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
492 516
493#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 517#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
494#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 518#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
495#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 519#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
496 520
521// #include <asm/sharp_apm.h> // including kernel headers is evil ...
522
523#define APM_IOCGEVTSRC (( 2 ) | ( 'A'<<8 ) | ( 203 ) | ( sizeof(int) ))
524#define APM_IOCSEVTSRC (( 3 ) | ( 'A'<<8 ) | ( 204 ) | ( sizeof(int) ))
525#define APM_EVT_POWER_BUTTON (1 << 0)
526
497 527
498 528
499void ODeviceZaurus::buzzer ( int sound ) 529void ODeviceZaurus::buzzer ( int sound )
500{ 530{
501 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); 531 static int fd = ::open ( "/dev/sharp_buz", O_RDWR|O_NONBLOCK );
502 532
503 if ( fd >= 0 ) 533 if ( fd >= 0 )
504 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 534 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
505} 535}
506 536
507 537
508void ODeviceZaurus::alarmSound ( ) 538void ODeviceZaurus::alarmSound ( )
509{ 539{
510 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 540 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
511} 541}
512 542
513void ODeviceZaurus::touchSound ( ) 543void ODeviceZaurus::touchSound ( )
514{ 544{
515 buzzer ( SHARP_BUZ_TOUCHSOUND ); 545 buzzer ( SHARP_BUZ_TOUCHSOUND );
516} 546}
517 547
518void ODeviceZaurus::keySound ( ) 548void ODeviceZaurus::keySound ( )
519{ 549{
520 buzzer ( SHARP_BUZ_KEYSOUND ); 550 buzzer ( SHARP_BUZ_KEYSOUND );
521} 551}
522 552
523 553
524uint ODeviceZaurus::hasLeds ( ) const 554uint ODeviceZaurus::hasLeds ( ) const
525{ 555{
526 return 1; 556 return 1;
527} 557}
528 558
529OLedState ODeviceZaurus::led ( uint which ) const 559OLedState ODeviceZaurus::led ( uint which ) const
530{ 560{
531 if ( which == 0 ) 561 if ( which == 0 )
532 return d-> m_leds [0]; 562 return d-> m_leds [0];
533 else 563 else
534 return OLED_Off; 564 return OLED_Off;
535} 565}
536 566
537bool ODeviceZaurus::setLed ( uint which, OLedState st ) 567bool ODeviceZaurus::setLed ( uint which, OLedState st )
538{ 568{
539 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 569 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
540 570
541 if ( which == 0 ) { 571 if ( which == 0 ) {
542 if ( fd >= 0 ) { 572 if ( fd >= 0 ) {
543 struct sharp_led_status leds; 573 struct sharp_led_status leds;
544 ::memset ( &leds, 0, sizeof( leds )); 574 ::memset ( &leds, 0, sizeof( leds ));
545 leds. which = SHARP_LED_MAIL_EXISTS; 575 leds. which = SHARP_LED_MAIL_EXISTS;
546 576
547 switch ( st ) { 577 switch ( st ) {
548 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 578 case OLED_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
549 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 579 case OLED_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
550 case OLED_BlinkSlow: 580 case OLED_BlinkSlow:
551 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 581 case OLED_BlinkFast: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
552 } 582 }
553 583
554 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) { 584 if ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 ) {
555 d-> m_leds [0] = st; 585 d-> m_leds [0] = st;
556 return true; 586 return true;
557 } 587 }
558 } 588 }
559 } 589 }
560 return false; 590 return false;
561} 591}
562 592
563//#endif 593bool ODeviceZaurus::setPowerButtonHandler ( ODevice::PowerButtonHandler p )
594{
595 bool res = false;
596 int fd;
597
598 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
599 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
600
601 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
602
603 if ( sources >= 0 ) {
604 if ( p == KERNEL )
605 sources |= APM_EVT_POWER_BUTTON;
606 else
607 sources &= ~APM_EVT_POWER_BUTTON;
608
609 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources & ~APM_EVT_POWER_BUTTON ) >= 0 ) // set new event sources
610 res = true;
611 else
612 perror ( "APM_IOCGEVTSRC" );
613 }
614 else
615 perror ( "APM_IOCGEVTSRC" );
616
617 ::close ( fd );
618 }
619 else
620 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
621
622 return res;
623}
diff --git a/libopie/odevice.h b/libopie/odevice.h
index 5009b91..ee01f0f 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -22,88 +22,94 @@
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24
25 25
26class ODeviceData; 26class ODeviceData;
27 27
28enum OModel { 28enum OModel {
29 OMODEL_Unknown, 29 OMODEL_Unknown,
30 30
31 OMODEL_iPAQ_H31xx, 31 OMODEL_iPAQ_H31xx,
32 OMODEL_iPAQ_H36xx, 32 OMODEL_iPAQ_H36xx,
33 OMODEL_iPAQ_H37xx, 33 OMODEL_iPAQ_H37xx,
34 OMODEL_iPAQ_H38xx, 34 OMODEL_iPAQ_H38xx,
35 35
36 OMODEL_Zaurus_SL5000 36 OMODEL_Zaurus_SL5000
37}; 37};
38 38
39 enum OVendor { 39 enum OVendor {
40 OVENDOR_Unknown, 40 OVENDOR_Unknown,
41 41
42 OVENDOR_HP, 42 OVENDOR_HP,
43 OVENDOR_Sharp 43 OVENDOR_Sharp
44 }; 44 };
45 45
46enum OSystem { 46enum OSystem {
47 OSYSTEM_Unknown, 47 OSYSTEM_Unknown,
48 48
49 OSYSTEM_Familiar, 49 OSYSTEM_Familiar,
50 OSYSTEM_Zaurus, 50 OSYSTEM_Zaurus,
51 OSYSTEM_OpenZaurus 51 OSYSTEM_OpenZaurus
52}; 52};
53 53
54enum OLedState { 54enum OLedState {
55 OLED_Off, 55 OLED_Off,
56 OLED_On, 56 OLED_On,
57 OLED_BlinkSlow, 57 OLED_BlinkSlow,
58 OLED_BlinkFast 58 OLED_BlinkFast
59}; 59};
60 60
61 61
62class ODevice 62class ODevice
63{ 63{
64public: 64public:
65 65
66public: 66public:
67 static ODevice *inst ( ); 67 static ODevice *inst ( );
68 68
69 // system 69 // system
70 enum PowerButtonHandler {
71 KERNEL,
72 OPIE
73 };
74
75 virtual bool setPowerButtonHandler ( PowerButtonHandler h );
70 virtual bool suspend ( ); 76 virtual bool suspend ( );
71 77
72// information 78// information
73 79
74 QString modelString ( ); 80 QString modelString ( );
75 OModel model ( ); 81 OModel model ( );
76 82
77 QString vendorString ( ); 83 QString vendorString ( );
78 OVendor vendor ( ); 84 OVendor vendor ( );
79 85
80 QString systemString ( ); 86 QString systemString ( );
81 OSystem system ( ); 87 OSystem system ( );
82 88
83 QString systemVersionString ( ); 89 QString systemVersionString ( );
84 90
85// input / output 91// input / output
86 92
87 virtual void alarmSound ( ); 93 virtual void alarmSound ( );
88 virtual void keySound ( ); 94 virtual void keySound ( );
89 virtual void touchSound ( ); 95 virtual void touchSound ( );
90 96
91 virtual uint hasLeds ( ) const; 97 virtual uint hasLeds ( ) const;
92 virtual OLedState led ( uint which ) const; 98 virtual OLedState led ( uint which ) const;
93 virtual bool setLed ( uint which, OLedState st ); 99 virtual bool setLed ( uint which, OLedState st );
94 100
95 virtual ~ODevice ( ); 101 virtual ~ODevice ( );
96 102
97protected: 103protected:
98 ODevice ( ); 104 ODevice ( );
99 virtual void init ( ); 105 virtual void init ( );
100 106
101 ODeviceData *d; 107 ODeviceData *d;
102 108
103private: 109private:
104 ODevice ( const ODevice & ); 110 ODevice ( const ODevice & );
105}; 111};
106 112
107#endif 113#endif
108 114
109 115