-rw-r--r-- | libopie2/opiecore/device/odevice_zaurus.cpp | 70 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_zaurus.h | 16 |
2 files changed, 32 insertions, 54 deletions
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp index 1894e15..e75e777 100644 --- a/libopie2/opiecore/device/odevice_zaurus.cpp +++ b/libopie2/opiecore/device/odevice_zaurus.cpp @@ -363,248 +363,228 @@ bool Zaurus::setLedState ( OLed which, OLedState st ) return true; } } } return false; } bool Zaurus::setSoftSuspend ( bool soft ) { if (!m_embedix) { /* non-Embedix kernels dont have kernel autosuspend */ return ODevice::setSoftSuspend( soft ); } bool res = false; int fd; if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources if ( sources >= 0 ) { if ( soft ) sources &= ~APM_EVT_POWER_BUTTON; else sources |= APM_EVT_POWER_BUTTON; if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources res = true; else perror ( "APM_IOCGEVTSRC" ); } else perror ( "APM_IOCGEVTSRC" ); ::close ( fd ); } else perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); return res; } bool Zaurus::setDisplayBrightness( int bright ) { //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); bool res = false; - int fd; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; if ( m_embedix ) { - if ( d->m_model == Model_Zaurus_SLC7x0 ) - { - //qDebug( "using special treatment for devices with the corgi backlight interface" ); - // special treatment for devices with the corgi backlight interface - if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) + int numberOfSteps = displayBrightnessResolution(); + int fd = ::open( SHARP_FL_IOCTL_DEVICE, O_WRONLY|O_NONBLOCK ); + if ( fd ) { - int value = ( bright == 1 ) ? 1 : static_cast<int>( bright * ( 17.0 / 255.0 ) ); - char writeCommand[100]; - const int count = sprintf( writeCommand, "%x\n", value ); - res = ( ::write ( fd, writeCommand, count ) != -1 ); + int val = ( numberOfSteps * 255 ) / 255; + res = ( ::ioctl ( fd, SHARP_FL_IOCTL_STEP_CONTRAST, val ) == 0 ); ::close ( fd ); } - return res; } else - if ( d->m_model == Model_Zaurus_SL6000 ) - { - //qDebug( "using special treatment for devices with the tosa backlight interface" ); - // special treatment for devices with the tosa backlight interface - if (( fd = ::open ( "/proc/driver/fl/tosa-bl", O_WRONLY )) >= 0 ) { - int value = ( bright == 1 ) ? 1 : static_cast<int>( bright * ( 17.0 / 255.0 ) ); - char writeCommand[100]; - const int count = sprintf( writeCommand, "%x\n", value ); - res = ( ::write ( fd, writeCommand, count ) != -1 ); - ::close ( fd ); + qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); } return res; } - else + +bool Zaurus::setDisplayStatus( bool on ) +{ + bool res = false; + if ( m_embedix ) { - // standard treatment for devices with the dumb embedix frontlight interface - if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { - int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus - if ( bright && !bl ) - bl = 1; - res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); + 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 { - // special treatment for the OpenZaurus unified interface - #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ - if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { - res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); - ::close ( fd ); - } + qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); } return res; } bool Zaurus::suspend() { qDebug("ODevice::suspend"); if ( !isQWS( ) ) // only qwsserver is allowed to suspend return false; if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices return false; bool res = false; ODevice::sendSuspendmsg(); struct timeval tvs, tvn; ::gettimeofday ( &tvs, 0 ); ::sync(); // flush fs caches res = ( ::system ( "apm --suspend" ) == 0 ); - // This is needed because the iPAQ apm implementation is asynchronous and we + // This is needed because the apm implementation is asynchronous and we // can not be sure when exactly the device is really suspended - // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. - if ( res ) { - do { // Yes, wait 15 seconds. This APM bug sucks big time. + do { // Yes, wait 15 seconds. This APM sucks big time. ::usleep ( 200 * 1000 ); ::gettimeofday ( &tvn, 0 ); } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); } QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); return res; } Transformation Zaurus::rotation() const { Transformation rot; int handle = 0; int retval = 0; switch ( d->m_model ) { case Model_Zaurus_SLC7x0: handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { return Rot270; } else { retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); ::close (handle); if (retval == 2 ) rot = Rot0; else rot = Rot270; } break; case Model_Zaurus_SLA300: case Model_Zaurus_SLB600: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: default: rot = d->m_rotation; break; } return rot; } ODirection Zaurus::direction() const { ODirection dir; int handle = 0; int retval = 0; switch ( d->m_model ) { case Model_Zaurus_SLC7x0: handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { dir = CW; } else { retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); ::close (handle); if (retval == 2 ) dir = CCW; else dir = CW; } break; case Model_Zaurus_SLA300: case Model_Zaurus_SLB600: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: - default: - dir = d->m_direction; + default: dir = d->m_direction; break; } return dir; } int Zaurus::displayBrightnessResolution() const { if (m_embedix) { - if ( d->m_model == Model_Zaurus_SLC7x0 ) return 18; - if ( d->m_model == Model_Zaurus_SL6000 ) return 18; - return 5; + int handle = ::open( SHARP_FL_IOCTL_DEVICE, O_RDWR|O_NONBLOCK ); + if ( handle != -1 ) return ::ioctl( handle, SHARP_FL_IOCTL_GET_STEP, 0 ); + else return 1; } else { - return 256; + qDebug( "ODevice handling for non-embedix kernels not yet implemented" ); + return 1; } } bool Zaurus::hasHingeSensor() const { return d->m_model == Model_Zaurus_SLC7x0; } OHingeStatus Zaurus::readHingeSensor() { 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; } } } diff --git a/libopie2/opiecore/device/odevice_zaurus.h b/libopie2/opiecore/device/odevice_zaurus.h index dc21546..37ab876 100644 --- a/libopie2/opiecore/device/odevice_zaurus.h +++ b/libopie2/opiecore/device/odevice_zaurus.h @@ -31,109 +31,107 @@ #define ODEVICE_ZAURUS #include <opie2/odevice.h> #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endif // _IO and friends are only defined in kernel headers ... #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) #define OD_IO(type,number) OD_IOC(0,type,number,0) #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) // Audio #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 #define SHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ #define SHARP_BUZ_KEYSOUND 2 /* key sound */ #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) #define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) #define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) #define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) #define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) // LED #define SHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) #define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) #define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ #define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ #define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ #define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ // Rotation and Power Management #define SHARP_IOCTL_GET_ROTATION 0x413c #define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) #define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) #define APM_EVT_POWER_BUTTON (1 << 0) // Brightness -#define FL_IOCTL_STEP_CONTRAST 100 - -#define CORGI_TOSA_BL_IOCTL_ON 1 -#define CORGI_TOSA_BL_IOCTL_OFF 2 -#define CORGI_TOSA_BL_IOCTL_STEP_CONTRAST 100 -#define CORGI_TOSA_BL_IOCTL_GET_STEP_CONTRAST 101 -#define CORGI_TOSA_BL_IOCTL_GET_STEP 102 -#define CORGI_BL_PROC_DEVICE corgi-bl -#define TOSA_BL_PROC_DEVICE tosa-bl +#define SHARP_FL_IOCTL_DEVICE "/dev/sharp_fl" +#define SHARP_FL_IOCTL_ON 1 +#define SHARP_FL_IOCTL_OFF 2 +#define SHARP_FL_IOCTL_STEP_CONTRAST 100 +#define SHARP_FL_IOCTL_GET_STEP_CONTRAST 101 +#define SHARP_FL_IOCTL_GET_STEP 102 namespace Opie { namespace Core { namespace Internal { class Zaurus : public ODevice { protected: virtual void init(const QString&); virtual void initButtons(); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); + virtual bool setDisplayStatus( bool on ); virtual int displayBrightnessResolution() const; virtual void playAlarmSound(); virtual void playKeySound(); virtual void playTouchSound(); virtual QValueList <OLed> ledList() const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState( OLed led ) const; virtual bool setLedState( OLed led, OLedState st ); virtual bool hasHingeSensor() const; virtual OHingeStatus readHingeSensor(); virtual bool suspend(); virtual Transformation rotation() const; virtual ODirection direction() const; protected: virtual void buzzer ( int snd ); OLedState m_leds [1]; bool m_embedix; }; struct z_button { Qt::Key code; char *utext; char *pix; char *fpressedservice; char *fpressedaction; char *fheldservice; char *fheldaction; }; } } } #endif |