-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.cpp | 65 |
2 files changed, 32 insertions, 36 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 6dc1295..b18fd32 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -388,131 +388,130 @@ bool iPAQ::setDisplayBrightness ( int bright ) bool res = false; int fd; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; QDir sysClass( "/sys/class/backlight/" ); sysClass.setFilter(QDir::Dirs); if ( sysClass.exists() && sysClass.count() > 2 ) { QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[100]; int val = bright * displayBrightnessResolution() / 255; int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); res = ( ::write( fd, &buf[0], len ) == 0 ); ::close( fd ); } } else { if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { FLITE_IN bl; bl. mode = 1; bl. pwr = bright ? 1 : 0; bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); ::close ( fd ); } } return res; } int iPAQ::displayBrightnessResolution() const { int res = 16; QDir sysClass( "/sys/class/backlight/" ); sysClass.setFilter(QDir::Dirs); if ( sysClass.exists() && sysClass.count() > 2 ) { QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); int fd = ::open( sysClassPath, 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; } switch ( model()) { case Model_iPAQ_H31xx: case Model_iPAQ_H36xx: case Model_iPAQ_H37xx: return 128; // really 256, but >128 could damage the LCD case Model_iPAQ_H38xx: case Model_iPAQ_H39xx: return 64; case Model_iPAQ_H5xxx: case Model_iPAQ_HX4700: case Model_iPAQ_H4xxx: - return 255; case Model_iPAQ_H191x: - return 7; + return 255; case Model_iPAQ_H1940: return 44; default: return 2; } } bool iPAQ::setDisplayStatus ( bool on ) { bool res = false; QString cmdline; QDir sysClass( "/sys/class/lcd/" ); sysClass.setFilter(QDir::Dirs); if ( sysClass.exists() && sysClass.count() > 2 ) { QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[10]; buf[0] = on ? 0 : 4; buf[1] = '\0'; res = ( ::write( fd, &buf[0], 2 ) == 0 ); ::close( fd ); } } else { res = OAbstractMobileDevice::setDisplayStatus(on); } return res; } bool iPAQ::hasLightSensor() const { switch (model()) { case Model_iPAQ_H191x: case Model_iPAQ_H22xx: case Model_iPAQ_H4xxx: return false; default: return true; } } int iPAQ::readLightSensor() { int fd; int val = -1; if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { char buffer [8]; if ( ::read ( fd, buffer, 5 ) == 5 ) { char *endptr; buffer [4] = 0; val = ::strtol ( buffer + 2, &endptr, 16 ); if ( *endptr != 0 ) val = -1; } ::close ( fd ); } diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp index 73b31cb..28e92bf 100644 --- a/libopie2/opiecore/device/odevice_mypal.cpp +++ b/libopie2/opiecore/device/odevice_mypal.cpp @@ -79,190 +79,187 @@ struct m_button mypal_buttons [] = { "devicebuttons/ipaq_mail", "opiemail", "raise()", "opiemail", "newMail()" }, { Model_Keyboardless_2_6, Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), "devicebuttons/ipaq_home", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, { Model_Keyboardless_2_6, Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), "devicebuttons/ipaq_record", "QPE/VMemo", "toggleRecord()", "sound", "raise()" }, }; void MyPal::init(const QString& model) { d->m_vendorstr = "Asus"; d->m_vendor = Vendor_Asus; d->m_modelstr = model.mid(model.findRev('A')); if ( d->m_modelstr == "A716" ) d->m_model = Model_MyPal_716; else d->m_model = Model_Unknown; d->m_rotation = Rot0; m_power_timer = 0; } void MyPal::initButtons() { if ( d->m_buttons ) return; if ( isQWS( ) ) { addPreHandler(this); } d->m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( mypal_buttons ) / sizeof( m_button )); i++ ) { m_button *mb = mypal_buttons + i; ODeviceButton b; if (( mb->model & d->m_model ) == d->m_model ) { b. setKeycode ( mb->code ); b. setUserText ( QObject::tr ( "Button", mb->utext )); b. setPixmap ( OResource::loadPixmap ( mb->pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( mb->fpressedservice ), mb->fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( mb->fheldservice ), mb->fheldaction )); d->m_buttons->append ( b ); } } reloadButtonMapping(); } bool MyPal::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) { int newkeycode = keycode; switch ( keycode ) { - case Key_Left : - case Key_Right: - case Key_Up : - case Key_Down : { - // Rotate the cursor keys by 270 - // keycode - Key_Left = position of the button starting from left clockwise - // add the rotation to it and modolo. No we've the original offset - // add the offset to the Key_Left key - if ( d->m_model == Model_MyPal_716 ) - newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; - break; - } + // QT has strange screen coordinate system, so depending + // on native device screen orientation, we need to rotate cursor keys + case Key_Left : + case Key_Right: + case Key_Up : + case Key_Down : { + int quarters; + switch (d->m_rotation) { + case Rot0: quarters = 3/*270deg*/; break; + case Rot90: quarters = 2/*270deg*/; break; + case Rot180: quarters = 1/*270deg*/; break; + case Rot270: quarters = 0/*270deg*/; break; + } + newkeycode = Key_Left + ( keycode - Key_Left + quarters ) % 4; + break; + } // map Power Button short/long press case HardKey_Suspend: { // Hope we don't have infinite recursion here: if ( isPress ) { if ( m_power_timer ) killTimer ( m_power_timer ); m_power_timer = startTimer ( 500 ); } else if ( m_power_timer ) { killTimer ( m_power_timer ); m_power_timer = 0; QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); } newkeycode = Key_unknown; break; } } if ( newkeycode != keycode ) { if ( newkeycode != Key_unknown ) QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); return true; } else return false; } void MyPal::timerEvent ( QTimerEvent * ) { killTimer ( m_power_timer ); m_power_timer = 0; QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); } void MyPal::playAlarmSound() { #ifndef QT_NO_SOUND static Sound snd ( "alarm" ); if(!snd.isFinished()) return; changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); snd. play(); #endif } bool MyPal::setDisplayBrightness ( int bright ) { bool res = false; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; - QDir sysClass( "/sys/class/backlight/pxafb/" ); + QDir sysClass( "/sys/class/backlight/" ); sysClass.setFilter(QDir::Dirs); - int fd; - if ( sysClass.exists() ) { - QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); - fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); - if ( fd ) { - char buf[10]; - buf[0] = bright ? 0 : 4; - buf[1] = '\0'; - res = ( ::write( fd, &buf[0], 2 ) == 0 ); - ::close( fd ); - } - sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" ); - fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); + if ( sysClass.exists() && sysClass.count() > 2 ) { + QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); + int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); if ( fd ) { - char buf[100]; - int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); - res = ( ::write( fd, &buf[0], len ) == 0 ); - ::close( fd ); + char buf[100]; + int val = bright * displayBrightnessResolution() / 255; + int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); + res = ( ::write( fd, &buf[0], len ) == 0 ); + ::close( fd ); } } return res; } int MyPal::displayBrightnessResolution() const { switch ( model()) { case Model_MyPal_716: - return 7; + return 255; default: return OAbstractMobileDevice::displayBrightnessResolution(); } } bool MyPal::setDisplayStatus ( bool on ) { bool res = false; QDir sysClass( "/sys/class/lcd/" ); sysClass.setFilter(QDir::Dirs); - if ( sysClass.exists() ) { - QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); - int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); + if ( sysClass.exists() && sysClass.count() > 2 ) { + QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); + int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[10]; buf[0] = on ? 0 : 4; buf[1] = '\0'; res = ( ::write( fd, &buf[0], 2 ) == 0 ); ::close( fd ); } + } else { + res = OAbstractMobileDevice::setDisplayStatus(on); } return res; } |