-rw-r--r-- | libopie/odevice.cpp | 142 |
1 files changed, 112 insertions, 30 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index a134810..3ff029e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -118,28 +118,31 @@ public: virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual void keySound ( ); virtual void touchSound ( ); 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 ); + static bool isZaurus(); + protected: virtual void buzzer ( int snd ); OLedState m_leds [1]; + bool m_embedix; }; class SIMpad : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool suspend(); virtual bool setDisplayStatus( bool on ); @@ -374,28 +377,28 @@ static QCString makeChannel ( const char *str ) return str; } static inline bool isQWS() { return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; } ODevice *ODevice::inst ( ) { static ODevice *dev = 0; - if ( !dev ) { + if ( !dev ) { if ( QFile::exists ( "/proc/hal/model" )) dev = new iPAQ ( ); - else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) + else if ( Zaurus::isZaurus() ) dev = new Zaurus ( ); else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) dev = new SIMpad ( ); else if ( QFile::exists ( "/proc/sys/board/name" )) dev = new Ramses ( ); else dev = new ODevice ( ); dev-> init ( ); } return dev; } @@ -1311,54 +1314,105 @@ int iPAQ::readLightSensor ( ) int iPAQ::lightSensorResolution ( ) const { return 256; } /************************************************** * * Zaurus * **************************************************/ +// Check whether this device is the sharp zaurus.. +bool Zaurus::isZaurus() +{ + + // If the special devices by embedix exist, it is quite simple: it is a Zaurus ! + if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){ + return true; + } + + // On non-embedix kenrnels, we have too look closer. + bool is_zaurus = false; + QFile f ( "/proc/cpuinfo" ); + if ( f. open ( IO_ReadOnly ) ) { + QString model; + QFile f ( "/proc/cpuinfo" ); + + QTextStream ts ( &f ); + QString line; + while( line = ts. readLine ( ) ) { + if ( line. left ( 8 ) == "Hardware" ) + break; + } + int loc = line. find ( ":" ); + if ( loc != -1 ) + model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); + + if ( model == "Sharp-Collie" + || model == "Collie" + || model == "SHARP Corgi" + || model == "SHARP Shepherd" + || model == "SHARP Poodle" + ) + is_zaurus = true; + + } + return is_zaurus; +} void Zaurus::init ( ) { d-> m_vendorstr = "Sharp"; d-> m_vendor = Vendor_Sharp; + m_embedix = true; // Not openzaurus means: It has an embedix kernel ! // QFile f ( "/proc/filesystems" ); QString model; // It isn't a good idea to check the system configuration to // detect the distribution ! // Otherwise it may happen that any other distribution is detected as openzaurus, just // because it uses a jffs2 filesystem.. // (eilers) // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { QFile f ("/etc/oz_version"); if ( f.exists() ){ d-> m_vendorstr = "OpenZaurus Team"; d-> m_systemstr = "OpenZaurus"; d-> m_system = System_OpenZaurus; - // f. close ( ); - - // f. setName ( "/etc/oz_version" ); if ( f. open ( IO_ReadOnly )) { QTextStream ts ( &f ); d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); f. close ( ); } + + // Openzaurus sometimes uses the embedix kernel! + // => Check whether this is an embedix kernel + FILE *uname = popen("uname -r", "r"); + QString line; + if ( f.open(IO_ReadOnly, uname) ) { + QTextStream ts ( &f ); + line = ts. readLine ( ); + int loc = line. find ( "embedix" ); + if ( loc != -1 ) + m_embedix = true; + else + m_embedix = false; + f. close ( ); + } + pclose(uname); } else { d-> m_systemstr = "Zaurus"; d-> m_system = System_Zaurus; } f. setName ( "/proc/cpuinfo" ); if ( f. open ( IO_ReadOnly ) ) { QTextStream ts ( &f ); QString line; while( line = ts. readLine ( ) ) { if ( line. left ( 8 ) == "Hardware" ) @@ -1366,28 +1420,28 @@ void Zaurus::init ( ) } int loc = line. find ( ":" ); if ( loc != -1 ) model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); } if ( model == "SHARP Corgi" ) { d-> m_model = Model_Zaurus_SLC700; d-> m_modelstr = "Zaurus SL-C700"; } else if ( model == "SHARP Shepherd" ) { d-> m_model = Model_Zaurus_SLC700; // Do we need a special type for the C750 ? (eilers) d-> m_modelstr = "Zaurus SL-C750"; - }else if ( model == "SHARP Poodle" ) { + } else if ( model == "SHARP Poodle" ) { d-> m_model = Model_Zaurus_SLB600; d-> m_modelstr = "Zaurus SL-B500 or SL-5600"; - } else if ( model = "Sharp-Collie" ) { + } else if ( model == "Sharp-Collie" || model == "Collie" ) { d-> m_model = Model_Zaurus_SL5500; d-> m_modelstr = "Zaurus SL-5500 or SL-5000d"; } else { d-> m_model = Model_Zaurus_SL5500; d-> m_modelstr = "Zaurus (Model unknown)"; } bool flipstate = false; switch ( d-> m_model ) { case Model_Zaurus_SLA300: d-> m_rotation = Rot0; break; @@ -1434,34 +1488,37 @@ void Zaurus::initButtons ( ) pz_buttons = z_buttons; buttoncount = ARRAY_SIZE(z_buttons); break; } for ( int i = 0; i < buttoncount; i++ ) { struct z_button *zb = pz_buttons + i; ODeviceButton b; b. setKeycode ( zb-> code ); b. setUserText ( QObject::tr ( "Button", zb-> utext )); b. setPixmap ( Resource::loadPixmap ( zb-> pix )); - b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction )); - b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction )); + b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), + zb-> fpressedaction )); + b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), + zb-> fheldaction )); d-> m_buttons-> append ( b ); } reloadButtonMapping ( ); QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); - connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); + connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), + this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); } #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> //#include <asm/sharp_char.h> // including kernel headers is evil ... #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) @@ -1515,48 +1572,56 @@ typedef struct sharp_led_status { // #include <asm/sharp_apm.h> // including kernel headers is evil ... #define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) #define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) #define APM_EVT_POWER_BUTTON (1 << 0) #define FL_IOCTL_STEP_CONTRAST 100 void Zaurus::buzzer ( int sound ) { - // Not all devices have real sound. #ifndef QT_NO_SOUND - switch ( d-> m_model ) { - case Model_Zaurus_SLC700:{ - int fd; - int vol; - bool vol_reset = false; + QString soundname; + + // Not all devices have real sound. But I expect + // that Openzaurus now has a sound driver which + // I will use instead the buzzer... + if ( ( d->m_model == Model_Zaurus_SLC700 ) + || d->m_system == System_OpenZaurus ){ - QString soundname; - switch ( sound ){ case SHARP_BUZ_SCHEDULE_ALARM: soundname = "alarm"; break; case SHARP_BUZ_TOUCHSOUND: soundname = "touchsound"; break; case SHARP_BUZ_KEYSOUND: soundname = "keysound"; break; default: soundname = "alarm"; } + } + + // If a soundname is defined, we expect that this device has + // sound capabilities.. Otherwise we expect to have the buzzer + // device.. + if ( !soundname.isEmpty() ){ + int fd; + int vol; + bool vol_reset = false; Sound snd ( soundname ); if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { Config cfg ( "qpe" ); cfg. setGroup ( "Volume" ); int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); if ( volalarm < 0 ) volalarm = 0; else if ( volalarm > 100 ) @@ -1568,35 +1633,33 @@ void Zaurus::buzzer ( int sound ) } } snd. play ( ); while ( !snd. isFinished ( )) qApp-> processEvents ( ); if ( fd >= 0 ) { if ( vol_reset ) ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); ::close ( fd ); } - break; - } - default:{ // Devices with buzzer + } else { int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); if ( fd >= 0 ) { ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); ::close ( fd ); } - } - } + + } #endif } void Zaurus::alarmSound ( ) { buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); } void Zaurus::touchSound ( ) { buzzer ( SHARP_BUZ_TOUCHSOUND ); @@ -1625,24 +1688,27 @@ QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const } OLedState Zaurus::ledState ( OLed which ) const { if ( which == Led_Mail ) return m_leds [0]; else return Led_Off; } bool Zaurus::setLedState ( OLed which, OLedState st ) { + if (!m_embedix) // Currently not supported on non_embedix kernels + return false; + static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); if ( which == Led_Mail ) { if ( fd >= 0 ) { struct sharp_led_status leds; ::memset ( &leds, 0, sizeof( leds )); leds. which = SHARP_LED_MAIL_EXISTS; bool ok = true; switch ( st ) { case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; @@ -1652,24 +1718,29 @@ bool Zaurus::setLedState ( OLed which, OLedState st ) if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { m_leds [0] = 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 @@ -1693,38 +1764,49 @@ bool Zaurus::setSoftSuspend ( bool soft ) bool Zaurus::setDisplayBrightness ( int bright ) { bool res = false; int fd; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; - 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 ); - ::close ( fd ); + if (m_embedix) { + 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 ); + ::close ( fd ); + } + } else { +#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 ); + } } return res; } int Zaurus::displayBrightnessResolution ( ) const { - return 5; + if (m_embedix) + return 5; + else + return 256; } /************************************************** * * SIMpad * **************************************************/ void SIMpad::init ( ) { d-> m_vendorstr = "SIEMENS"; d-> m_vendor = Vendor_SIEMENS; |