-rw-r--r-- | libopie2/opiecore/device/odevice_zaurus.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp index 7302d2c..b7f3104 100644 --- a/libopie2/opiecore/device/odevice_zaurus.cpp +++ b/libopie2/opiecore/device/odevice_zaurus.cpp @@ -457,212 +457,223 @@ bool Zaurus::setLedState( OLed which, OLedState st ) int Zaurus::displayBrightnessResolution() const { int res = 1; if (m_embedix) { int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK ); if ( fd ) { int value = ::ioctl( fd, SHARP_FL_IOCTL_GET_STEP, 0 ); ::close( fd ); return value ? value : res; } } else { int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK ); if ( fd ) { char buf[100]; if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res ); ::close( fd ); } } return res; } bool Zaurus::setDisplayBrightness( int bright ) { //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); bool res = false; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; int numberOfSteps = displayBrightnessResolution(); int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255; if ( m_embedix ) { int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); if ( fd ) { res = ( ::ioctl( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 ); ::close( fd ); } } else { int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[100]; int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); res = ( ::write( fd, &buf[0], len ) == 0 ); ::close( fd ); } } return res; } bool Zaurus::setDisplayStatus( bool on ) { bool res = false; if ( m_embedix ) { int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); if ( fd ) { int ioctlnum = on ? SHARP_FL_IOCTL_ON : SHARP_FL_IOCTL_OFF; res = ( ::ioctl ( fd, ioctlnum, 0 ) == 0 ); ::close ( fd ); } } else { int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[10]; buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; buf[1] = '\0'; res = ( ::write( fd, &buf[0], 2 ) == 0 ); ::close( fd ); } } return res; } Transformation Zaurus::rotation() const { qDebug( "Zaurus::rotation()" ); Transformation rot; switch ( d->m_model ) { case Model_Zaurus_SLC3000: // fallthrough - case Model_Zaurus_SLC1000: // fallthrough + case Model_Zaurus_SLC1000: + { + OHingeStatus hs = readHingeSensor(); + qDebug( "Zaurus::rotation() - hinge sensor = %d", (int) hs ); + if ( hs == CASE_PORTRAIT ) rot = Rot0; + else if ( hs == CASE_UNKNOWN ) rot = Rot270; + else rot = Rot270; + } + break; + + // SLC7x0 needs a special case here, because we were able to set the W100 + // hardware default rotation on kernel 2.6 to Rot0 case Model_Zaurus_SLC7x0: { OHingeStatus hs = readHingeSensor(); qDebug( "Zaurus::rotation() - hinge sensor = %d", (int) hs ); if ( m_embedix ) { if ( hs == CASE_PORTRAIT ) rot = Rot0; - else if ( hs == CASE_UNKNOWN ) rot = Rot0; + else if ( hs == CASE_UNKNOWN ) rot = Rot270; else rot = Rot270; } else { if ( hs == CASE_PORTRAIT ) rot = Rot90; else if ( hs == CASE_UNKNOWN ) rot = Rot0; else rot = Rot0; } } - break; + break; case Model_Zaurus_SL6000: case Model_Zaurus_SLB600: case Model_Zaurus_SLA300: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: default: rot = d->m_rotation; break; } return rot; } ODirection Zaurus::direction() const { ODirection dir; switch ( d->m_model ) { case Model_Zaurus_SLC3000: // fallthrough case Model_Zaurus_SLC1000: // fallthrough case Model_Zaurus_SLC7x0: { OHingeStatus hs = readHingeSensor(); if ( hs == CASE_PORTRAIT ) dir = CCW; else if ( hs == CASE_UNKNOWN ) dir = CCW; else dir = CW; } break; case Model_Zaurus_SL6000: case Model_Zaurus_SLA300: case Model_Zaurus_SLB600: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: default: dir = d->m_direction; break; } return dir; } bool Zaurus::hasHingeSensor() const { return d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLC3000 || d->m_model == Model_Zaurus_SLC1000; } OHingeStatus Zaurus::readHingeSensor() const { if (m_embedix) { int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror return CASE_UNKNOWN; } else { int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); ::close (handle); if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) { qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); return static_cast<OHingeStatus>( retval ); } else { qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); return CASE_UNKNOWN; } } } else { // corgi keyboard is event source 0 in OZ kernel 2.6 OInputDevice* keyboard = OInputSystem::instance()->device( "event0" ); if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP0 ) ) return CASE_LANDSCAPE; else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP1 ) ) return CASE_PORTRAIT; else if ( keyboard && keyboard->isHeld( OInputDevice::Key_KP2 ) ) return CASE_CLOSED; qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); return CASE_UNKNOWN; } } /* * Take code from iPAQ device. * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction. * I hope that is ok - Alwin */ bool Zaurus::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) { int newkeycode = keycode; if (d->m_model != Model_Zaurus_SLC7x0 && d->m_model != Model_Zaurus_SLC3000 && d->m_model != Model_Zaurus_SLC1000) return false; /* map cursor keys depending on the hinge status */ switch ( keycode ) { // Rotate cursor keys case Key_Left : |