-rw-r--r-- | libopie/odevice.cpp | 70 |
1 files changed, 65 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 | |||
@@ -38,60 +38,64 @@ | |||
38 | #include "odevice.h" | 38 | #include "odevice.h" |
39 | 39 | ||
40 | 40 | ||
41 | class ODeviceData { | 41 | class ODeviceData { |
42 | public: | 42 | public: |
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 | ||
57 | class ODeviceIPAQ : public ODevice { | 57 | class ODeviceIPAQ : public ODevice { |
58 | protected: | 58 | protected: |
59 | virtual void init ( ); | 59 | virtual void init ( ); |
60 | 60 | ||
61 | public: | 61 | public: |
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 | ||
69 | class ODeviceZaurus : public ODevice { | 71 | class ODeviceZaurus : public ODevice { |
70 | protected: | 72 | protected: |
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 | ||
82 | protected: | 86 | protected: |
83 | virtual void buzzer ( int snd ); | 87 | virtual void buzzer ( int snd ); |
84 | }; | 88 | }; |
85 | 89 | ||
86 | 90 | ||
87 | 91 | ||
88 | 92 | ||
89 | ODevice *ODevice::inst ( ) | 93 | ODevice *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 ( ); |
@@ -110,66 +114,71 @@ ODevice::ODevice ( ) | |||
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 | ||
119 | void ODevice::init ( ) | 123 | void ODevice::init ( ) |
120 | { | 124 | { |
121 | } | 125 | } |
122 | 126 | ||
123 | ODevice::~ODevice ( ) | 127 | ODevice::~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 | ||
138 | bool ODevice::setPowerButtonHandler ( ODevice::PowerButtonHandler ) | ||
139 | { | ||
140 | return false; | ||
141 | } | ||
142 | |||
134 | bool ODevice::suspend ( ) | 143 | bool 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 | ||
172 | QString ODevice::vendorString ( ) | 181 | QString ODevice::vendorString ( ) |
173 | { | 182 | { |
174 | return d-> m_vendorstr; | 183 | return d-> m_vendorstr; |
175 | } | 184 | } |
@@ -383,56 +392,71 @@ bool ODeviceIPAQ::setLed ( uint which, OLedState st ) | |||
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 | 416 | bool 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 | ||
416 | void ODeviceZaurus::init ( ) | 440 | void 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 | ||
@@ -473,48 +497,54 @@ void ODeviceZaurus::init ( ) | |||
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 | ||
486 | typedef struct sharp_led_status { | 510 | typedef 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 | ||
499 | void ODeviceZaurus::buzzer ( int sound ) | 529 | void 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 | ||
508 | void ODeviceZaurus::alarmSound ( ) | 538 | void ODeviceZaurus::alarmSound ( ) |
509 | { | 539 | { |
510 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); | 540 | buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); |
511 | } | 541 | } |
512 | 542 | ||
513 | void ODeviceZaurus::touchSound ( ) | 543 | void ODeviceZaurus::touchSound ( ) |
514 | { | 544 | { |
515 | buzzer ( SHARP_BUZ_TOUCHSOUND ); | 545 | buzzer ( SHARP_BUZ_TOUCHSOUND ); |
516 | } | 546 | } |
517 | 547 | ||
518 | void ODeviceZaurus::keySound ( ) | 548 | void ODeviceZaurus::keySound ( ) |
519 | { | 549 | { |
520 | buzzer ( SHARP_BUZ_KEYSOUND ); | 550 | buzzer ( SHARP_BUZ_KEYSOUND ); |
@@ -539,25 +569,55 @@ bool ODeviceZaurus::setLed ( uint which, OLedState st ) | |||
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 | 593 | bool 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 | } | ||