summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2005-02-04 17:59:22 (UTC)
committer mickeyl <mickeyl>2005-02-04 17:59:22 (UTC)
commitee4b479d3e0b67a4418914231c0ec38ef31b8290 (patch) (unidiff)
treeb4bde4c8544444d260f98619bf82a0c5ec8a584e /libopie2
parentc0248a2c02381b5a5dce5c4543db6ff46486f2f1 (diff)
downloadopie-ee4b479d3e0b67a4418914231c0ec38ef31b8290.zip
opie-ee4b479d3e0b67a4418914231c0ec38ef31b8290.tar.gz
opie-ee4b479d3e0b67a4418914231c0ec38ef31b8290.tar.bz2
implement computing the hinge status for Zaurus w/ Kernel 2.6
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_zaurus.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp
index 780d130..a59e799 100644
--- a/libopie2/opiecore/device/odevice_zaurus.cpp
+++ b/libopie2/opiecore/device/odevice_zaurus.cpp
@@ -15,48 +15,49 @@
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_zaurus.h" 30#include "odevice_zaurus.h"
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
37 37
38/* OPIE */ 38/* OPIE */
39#include <opie2/oinputsystem.h>
39#include <qpe/config.h> 40#include <qpe/config.h>
40#include <qpe/resource.h> 41#include <qpe/resource.h>
41#include <qpe/sound.h> 42#include <qpe/sound.h>
42#include <qpe/qcopenvelope_qws.h> 43#include <qpe/qcopenvelope_qws.h>
43 44
44/* STD */ 45/* STD */
45#include <fcntl.h> 46#include <fcntl.h>
46#include <math.h> 47#include <math.h>
47#include <stdlib.h> 48#include <stdlib.h>
48#include <signal.h> 49#include <signal.h>
49#include <sys/ioctl.h> 50#include <sys/ioctl.h>
50#include <sys/time.h> 51#include <sys/time.h>
51#include <unistd.h> 52#include <unistd.h>
52#ifndef QT_NO_SOUND 53#ifndef QT_NO_SOUND
53#include <linux/soundcard.h> 54#include <linux/soundcard.h>
54#endif 55#endif
55 56
56using namespace Opie::Core; 57using namespace Opie::Core;
57using namespace Opie::Core::Internal; 58using namespace Opie::Core::Internal;
58 59
59struct z_button z_buttons [] = { 60struct z_button z_buttons [] = {
60 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 61 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
61 "devicebuttons/z_calendar", 62 "devicebuttons/z_calendar",
62 "datebook", "nextView()", 63 "datebook", "nextView()",
@@ -79,49 +80,58 @@ struct z_button z_buttons [] = {
79 "opiemail", "newMail()" }, 80 "opiemail", "newMail()" },
80}; 81};
81 82
82struct z_button z_buttons_c700 [] = { 83struct z_button z_buttons_c700 [] = {
83 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 84 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
84 "devicebuttons/z_calendar", 85 "devicebuttons/z_calendar",
85 "datebook", "nextView()", 86 "datebook", "nextView()",
86 "today", "raise()" }, 87 "today", "raise()" },
87 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 88 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
88 "devicebuttons/z_contact", 89 "devicebuttons/z_contact",
89 "addressbook", "raise()", 90 "addressbook", "raise()",
90 "addressbook", "beamBusinessCard()" }, 91 "addressbook", "beamBusinessCard()" },
91 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 92 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
92 "devicebuttons/z_home", 93 "devicebuttons/z_home",
93 "QPE/Launcher", "home()", 94 "QPE/Launcher", "home()",
94 "buttonsettings", "raise()" }, 95 "buttonsettings", "raise()" },
95 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 96 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
96 "devicebuttons/z_menu", 97 "devicebuttons/z_menu",
97 "QPE/TaskBar", "toggleMenu()", 98 "QPE/TaskBar", "toggleMenu()",
98 "QPE/TaskBar", "toggleStartMenu()" }, 99 "QPE/TaskBar", "toggleStartMenu()" },
99 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 100 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
100 "devicebuttons/z_mail", 101 "devicebuttons/z_mail",
101 "opiemail", "raise()", 102 "opiemail", "raise()",
102 "opiemail", "newMail()" }, 103 "opiemail", "newMail()" },
103 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), 104
105 { Qt::Key_F15, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
106 "devicebuttons/z_hinge",
107 "QPE/Rotation", "rotateDefault()",
108 "QPE/Dummy", "doNothing()" },
109 { Qt::Key_F16, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
110 "devicebuttons/z_hinge",
111 "QPE/Rotation", "rotateDefault()",
112 "QPE/Dummy", "doNothing()" },
113 { Qt::Key_F17, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
104 "devicebuttons/z_hinge", 114 "devicebuttons/z_hinge",
105 "QPE/Rotation", "rotateDefault()", 115 "QPE/Rotation", "rotateDefault()",
106 "QPE/Dummy", "doNothing()" }, 116 "QPE/Dummy", "doNothing()" },
107}; 117};
108 118
109// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus 119// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus
110// class up into individual classes. We need three classes 120// class up into individual classes. We need three classes
111// 121//
112// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) 122// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000)
113// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) 123// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600)
114// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, C860, C3000) 124// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, C860, C3000)
115// Zaurus-Tosa (PXA-model w/ 480x640 lcd, for SL6000) 125// Zaurus-Tosa (PXA-model w/ 480x640 lcd, for SL6000)
116// 126//
117// Only question right now is: Do we really need to do it? Because as soon 127// Only question right now is: Do we really need to do it? Because as soon
118// as the OpenZaurus kernel is ready, there will be a unified interface for all 128// as the OpenZaurus kernel is ready, there will be a unified interface for all
119// Zaurus models (concerning apm, backlight, buttons, etc.) 129// Zaurus models (concerning apm, backlight, buttons, etc.)
120// 130//
121// Comments? - mickeyl. 131// Comments? - mickeyl.
122 132
123void Zaurus::init(const QString& cpu_info) 133void Zaurus::init(const QString& cpu_info)
124{ 134{
125 // generic distribution code already scanned /etc/issue at that point - 135 // generic distribution code already scanned /etc/issue at that point -
126 // embedix releases contain "Embedix <version> | Linux for Embedded Devices" 136 // embedix releases contain "Embedix <version> | Linux for Embedded Devices"
127 if ( d->m_sysverstr.contains( "embedix", false ) ) 137 if ( d->m_sysverstr.contains( "embedix", false ) )
@@ -486,74 +496,74 @@ bool Zaurus::suspend()
486 496
487 struct timeval tvs, tvn; 497 struct timeval tvs, tvn;
488 ::gettimeofday ( &tvs, 0 ); 498 ::gettimeofday ( &tvs, 0 );
489 499
490 ::sync(); // flush fs caches 500 ::sync(); // flush fs caches
491 res = ( ::system ( "apm --suspend" ) == 0 ); 501 res = ( ::system ( "apm --suspend" ) == 0 );
492 502
493 // This is needed because the apm implementation is asynchronous and we 503 // This is needed because the apm implementation is asynchronous and we
494 // can not be sure when exactly the device is really suspended 504 // can not be sure when exactly the device is really suspended
495 if ( res ) { 505 if ( res ) {
496 do { // Yes, wait 15 seconds. This APM sucks big time. 506 do { // Yes, wait 15 seconds. This APM sucks big time.
497 ::usleep ( 200 * 1000 ); 507 ::usleep ( 200 * 1000 );
498 ::gettimeofday ( &tvn, 0 ); 508 ::gettimeofday ( &tvn, 0 );
499 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); 509 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 );
500 } 510 }
501 511
502 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); 512 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" );
503 return res; 513 return res;
504} 514}
505 515
506 516
507Transformation Zaurus::rotation() const 517Transformation Zaurus::rotation() const
508{ 518{
509 Transformation rot; 519 Transformation rot;
510 520
511 switch ( d->m_model ) { 521 switch ( d->m_model ) {
512 case Model_Zaurus_SLC3000: // fallthrough 522 case Model_Zaurus_SLC3000: // fallthrough
513 case Model_Zaurus_SLC7x0: { 523 case Model_Zaurus_SLC7x0: {
514 OHingeStatus hs = readHingeSensor(); 524 OHingeStatus hs = readHingeSensor();
515 if ( hs == CASE_PORTRAIT ) rot = Rot0; 525 if ( hs == CASE_PORTRAIT ) rot = Rot0;
516 else if ( hs == CASE_UNKNOWN ) rot = Rot0; 526 else if ( hs == CASE_UNKNOWN ) rot = Rot0;
517 else rot = Rot270; 527 else rot = Rot270;
518 } 528 }
519 break; 529 break;
520 case Model_Zaurus_SL6000: 530 case Model_Zaurus_SL6000:
521 case Model_Zaurus_SLB600: 531 case Model_Zaurus_SLB600:
522 case Model_Zaurus_SLA300: 532 case Model_Zaurus_SLA300:
523 case Model_Zaurus_SL5500: 533 case Model_Zaurus_SL5500:
524 case Model_Zaurus_SL5000: 534 case Model_Zaurus_SL5000:
525 default: 535 default:
526 rot = d->m_rotation; 536 rot = d->m_rotation;
527 break; 537 break;
528 } 538 }
529 539
530 return rot; 540 return rot;
531} 541}
532ODirection Zaurus::direction() const 542ODirection Zaurus::direction() const
533{ 543{
534 ODirection dir; 544 ODirection dir;
535 545
536 switch ( d->m_model ) { 546 switch ( d->m_model ) {
537 case Model_Zaurus_SLC3000: // fallthrough 547 case Model_Zaurus_SLC3000: // fallthrough
538 case Model_Zaurus_SLC7x0: { 548 case Model_Zaurus_SLC7x0: {
539 OHingeStatus hs = readHingeSensor(); 549 OHingeStatus hs = readHingeSensor();
540 if ( hs == CASE_PORTRAIT ) dir = CCW; 550 if ( hs == CASE_PORTRAIT ) dir = CCW;
541 else if ( hs == CASE_UNKNOWN ) dir = CCW; 551 else if ( hs == CASE_UNKNOWN ) dir = CCW;
542 else dir = CW; 552 else dir = CW;
543 } 553 }
544 break; 554 break;
545 case Model_Zaurus_SL6000: 555 case Model_Zaurus_SL6000:
546 case Model_Zaurus_SLA300: 556 case Model_Zaurus_SLA300:
547 case Model_Zaurus_SLB600: 557 case Model_Zaurus_SLB600:
548 case Model_Zaurus_SL5500: 558 case Model_Zaurus_SL5500:
549 case Model_Zaurus_SL5000: 559 case Model_Zaurus_SL5000:
550 default: dir = d->m_direction; 560 default: dir = d->m_direction;
551 break; 561 break;
552 } 562 }
553 return dir; 563 return dir;
554 564
555} 565}
556 566
557bool Zaurus::hasHingeSensor() const 567bool Zaurus::hasHingeSensor() const
558{ 568{
559 return d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLC3000; 569 return d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLC3000;
@@ -566,28 +576,33 @@ OHingeStatus Zaurus::readHingeSensor() const
566 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 576 int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
567 if (handle == -1) 577 if (handle == -1)
568 { 578 {
569 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror 579 qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror
570 return CASE_UNKNOWN; 580 return CASE_UNKNOWN;
571 } 581 }
572 else 582 else
573 { 583 {
574 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 584 int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
575 ::close (handle); 585 ::close (handle);
576 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) 586 if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE )
577 { 587 {
578 qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); 588 qDebug( "Zaurus::readHingeSensor() - result = %d", retval );
579 return static_cast<OHingeStatus>( retval ); 589 return static_cast<OHingeStatus>( retval );
580 } 590 }
581 else 591 else
582 { 592 {
583 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); 593 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
584 return CASE_UNKNOWN; 594 return CASE_UNKNOWN;
585 } 595 }
586 } 596 }
587 } 597 }
588 else 598 else
589 { 599 {
590 qDebug( "Zaurus::readHingeSensor: ODevice handling for non-embedix kernels not yet implemented" ); 600 // corgi keyboard is event source 0 in OZ kernel 2.6
601 OInputDevice* keyboard = OInputSystem::instance()->device( "event0" );
602 if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP0 ) ) return CASE_LANDSCAPE;
603 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP1 ) ) return CASE_PORTRAIT;
604 else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP2 ) ) return CASE_CLOSED;
605 qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" );
591 return CASE_UNKNOWN; 606 return CASE_UNKNOWN;
592 } 607 }
593} 608}