-rw-r--r-- | libopie/odevice.cpp | 61 | ||||
-rw-r--r-- | libopie/odevice.h | 6 |
2 files changed, 63 insertions, 4 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index f808960..4b5a54e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -11,128 +11,129 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <signal.h> #include <sys/time.h> #include <linux/soundcard.h> #include <math.h> #include <qapplication.h> #include <qfile.h> #include <qtextstream.h> #include <qpe/sound.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include "odevice.h" #include <qwindowsystem_qws.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)) using namespace Opie; class ODeviceData { public: QString m_vendorstr; OVendor m_vendor; QString m_modelstr; OModel m_model; QString m_systemstr; OSystem m_system; QString m_sysverstr; Transformation m_rotation; ODirection m_direction; QValueList <ODeviceButton> *m_buttons; uint m_holdtime; + QStrList *m_cpu_frequencies; }; class iPAQ : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); 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 hasLightSensor ( ) const; virtual int readLightSensor ( ); virtual int lightSensorResolution ( ) const; protected: virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); virtual void timerEvent ( QTimerEvent *te ); int m_power_timer; OLedState m_leds [2]; }; class Zaurus : public ODevice { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); 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 ); protected: virtual void buzzer ( int snd ); OLedState m_leds [1]; }; class SIMpad : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); @@ -362,128 +363,129 @@ struct r_button { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), "devicebuttons/ipaq_home", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, }; static QCString makeChannel ( const char *str ) { if ( str && !::strchr ( str, '/' )) return QCString ( "QPE/Application/" ) + str; else return str; } static inline bool isQWS() { return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; } ODevice *ODevice::inst ( ) { static ODevice *dev = 0; if ( !dev ) { if ( QFile::exists ( "/proc/hal/model" )) dev = new iPAQ ( ); else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 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; } /************************************************** * * common * **************************************************/ ODevice::ODevice ( ) { d = new ODeviceData; d-> m_modelstr = "Unknown"; d-> m_model = Model_Unknown; d-> m_vendorstr = "Unknown"; d-> m_vendor = Vendor_Unknown; d-> m_systemstr = "Unknown"; d-> m_system = System_Unknown; d-> m_sysverstr = "0.0"; d-> m_rotation = Rot0; d-> m_direction = CW; d-> m_holdtime = 1000; // 1000ms d-> m_buttons = 0; + d-> m_cpu_frequencies = new QStrList; } void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) { if ( msg == "deviceButtonMappingChanged()" ) { reloadButtonMapping ( ); } } void ODevice::init ( ) { } /** * This method initialises the button mapping */ void ODevice::initButtons ( ) { if ( d-> m_buttons ) return; // Simulation uses iPAQ 3660 device buttons qDebug ( "init Buttons" ); d-> m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { i_button *ib = ipaq_buttons + i; ODeviceButton b; if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { b. setKeycode ( ib-> code ); b. setUserText ( QObject::tr ( "Button", ib-> utext )); b. setPixmap ( Resource::loadPixmap ( ib-> pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> 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 & ))); } ODevice::~ODevice ( ) { delete d; } bool ODevice::setSoftSuspend ( bool /*soft*/ ) { return false; } //#include <linux/apm_bios.h> #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) /** * This method will try to suspend the device * It only works if the user is the QWS Server and the apm application * is installed. * It tries to suspend and then waits some time cause some distributions @@ -712,128 +714,168 @@ void ODevice::touchSound ( ) /** * This method will return a list of leds * available on this device * @return a list of LEDs. */ QValueList <OLed> ODevice::ledList ( ) const { return QValueList <OLed> ( ); } /** * This does return the state of the LEDs */ QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const { return QValueList <OLedState> ( ); } /** * @return the state for a given OLed */ OLedState ODevice::ledState ( OLed /*which*/ ) const { return Led_Off; } /** * Set the state for a LED * @param which Which OLed to use * @param st The state to set * @return success or failure */ bool ODevice::setLedState ( OLed which, OLedState st ) { Q_UNUSED( which ) Q_UNUSED( st ) return false; } /** * @return if the device has a light sensor */ bool ODevice::hasLightSensor ( ) const { return false; } /** * @return a value from the light senso */ int ODevice::readLightSensor ( ) { return -1; } /** * @return the light sensor resolution whatever that is ;) */ int ODevice::lightSensorResolution ( ) const { return 0; } /** + * @return a list with valid CPU frequency + */ +QStrList &ODevice::cpuFrequencies ( ) const +{ +qWarning("ODevice::cpuFrequencies: m_cpu_frequencies is %d", (int) d->m_cpu_frequencies); + return *d->m_cpu_frequencies; +} + + +/** + * Set desired cpu frequency + * + * @param index index into d->m_cpu_frequencies of the frequency to be set + */ +bool ODevice::setCpuFrequency(uint index) +{ + if (index >= d->m_cpu_frequencies->count()) + return false; + + char *freq = d->m_cpu_frequencies->at(index); + qWarning("set freq to %s", freq); + + //TODO: do the change in /proc/sys/cpu/0/speed + + return false; +} + +/** + * Returns current frequency index out of d->m_cpu_frequencies + */ +uint ODevice::cpuFrequency() const +{ + // TODO: get freq from /proc/sys/cpu/0/speed and return index + + return 0; +} + + + +/** * @return a list of hardware buttons */ const QValueList <ODeviceButton> &ODevice::buttons ( ) { initButtons ( ); return *d-> m_buttons; } /** * @return The amount of time that would count as a hold */ uint ODevice::buttonHoldTime ( ) const { return d-> m_holdtime; } /** * This method return a ODeviceButton for a key code * or 0 if no special hardware button is available for the device * * @return The devicebutton or 0l * @see ODeviceButton */ const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) { initButtons ( ); for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { if ( (*it). keycode ( ) == code ) return &(*it); } return 0; } void ODevice::reloadButtonMapping ( ) { initButtons ( ); Config cfg ( "ButtonSettings" ); for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { ODeviceButton &b = ( *d-> m_buttons ) [i]; QString group = "Button" + QString::number ( i ); QCString pch, hch; QCString pm, hm; QByteArray pdata, hdata; if ( cfg. hasGroup ( group )) { cfg. setGroup ( group ); pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); } b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); } @@ -1889,214 +1931,227 @@ bool SIMpad::setDisplayBrightness ( int bright ) if ( bright < 0 ) bright = 0; if (( fd = ::open ( SIMPAD_BACKLIGHT_CONTROL, O_WRONLY )) >= 0 ) { int value = 255 - bright; const int mask = SIMPAD_BACKLIGHT_MASK; value = value << 8; value += mask; char writeCommand[100]; const int count = sprintf( writeCommand, "0x%x\n", value ); res = ( ::write ( fd, writeCommand, count ) != -1 ); ::close ( fd ); } return res; } int SIMpad::displayBrightnessResolution ( ) const { switch ( model ( )) { case Model_SIMpad_CL4: case Model_SIMpad_SL4: case Model_SIMpad_SLC: case Model_SIMpad_TSinus: return 255; //TODO find out if this is save default: return 2; } } /************************************************** * * Ramses * **************************************************/ void Ramses::init() { d->m_vendorstr = "M und N"; d->m_vendor = Vendor_MundN; QFile f("/proc/sys/board/ramses"); d->m_modelstr = "Ramses"; d->m_model = Model_Ramses_MNCI; d->m_rotation = Rot0; d->m_holdtime = 1000; f.setName("/etc/oz_version"); if (f.open(IO_ReadOnly)) { d->m_systemstr = "OpenEmbedded/Ramses"; d->m_system = System_OpenZaurus; QTextStream ts(&f); ts.setDevice(&f); d->m_sysverstr = ts.readLine(); f.close(); } m_power_timer = 0; +qWarning("adding freq"); + d->m_cpu_frequencies->append("100"); + d->m_cpu_frequencies->append("200"); + d->m_cpu_frequencies->append("300"); + d->m_cpu_frequencies->append("400"); } bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) { Q_UNUSED( keycode ); Q_UNUSED( modifiers ); Q_UNUSED( isPress ); Q_UNUSED( autoRepeat ); return false; } void Ramses::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); } bool Ramses::setSoftSuspend(bool soft) { qDebug("Ramses::setSoftSuspend(%d)", soft); #if 0 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; #else return true; #endif } bool Ramses::suspend ( ) { qDebug("Ramses::suspend"); + return false; } /** * This sets the display on or off */ bool Ramses::setDisplayStatus(bool on) { qDebug("Ramses::setDisplayStatus(%d)", on); #if 0 bool res = false; int fd; if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); ::close(fd); } return res; #else return true; #endif } /* * We get something between 0..255 into us */ bool Ramses::setDisplayBrightness(int bright) { qDebug("Ramses::setDisplayBrightness(%d)", bright); bool res = false; int fd; // pwm1 brighness: 20 steps 500..0 (dunkel->hell) if (bright > 255 ) bright = 255; if (bright < 0) bright = 0; - bright = 500-(bright * 500 / 255); + // Turn backlight completely off + if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { + char writeCommand[10]; + const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); + res = (::write(fd, writeCommand, count) != -1); + ::close(fd); + } + + // scale backlight brightness to hardware + bright = 500-(bright * 500 / 255); if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { qDebug(" %d -> pwm1", bright); char writeCommand[100]; const int count = sprintf(writeCommand, "%d\n", bright); res = (::write(fd, writeCommand, count) != -1); ::close(fd); - } else { - qWarning("no write"); } return res; } int Ramses::displayBrightnessResolution() const { return 32; } bool Ramses::setDisplayContrast(int contr) { qDebug("Ramses::setDisplayContrast(%d)", contr); bool res = false; int fd; // pwm0 contrast: 20 steps 79..90 (dunkel->hell) if (contr > 255 ) contr = 255; if (contr < 0) contr = 0; contr = 90 - (contr * 20 / 255); if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { qDebug(" %d -> pwm0", contr); char writeCommand[100]; const int count = sprintf(writeCommand, "%d\n", contr); res = (::write(fd, writeCommand, count) != -1); res = true; ::close(fd); } else { qWarning("no write"); } return res; } int Ramses::displayContrastResolution() const { return 20; } diff --git a/libopie/odevice.h b/libopie/odevice.h index 0974e8d..7f6f856 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h @@ -1,89 +1,90 @@ /* This file is part of the OPIE libraries Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _LIBOPIE_ODEVICE_H_ #define _LIBOPIE_ODEVICE_H_ #include <qobject.h> #include <qstring.h> #include <qnamespace.h> +#include <qstrlist.h> #include <opie/odevicebutton.h> #include <qpe/qpeapplication.h> /* for Transformation enum.. */ class ODeviceData; namespace Opie { /** * The available devices */ enum OModel { Model_Unknown, // = 0 Model_Series_Mask = 0xff000000, Model_iPAQ = ( 1 << 24 ), Model_iPAQ_All = ( Model_iPAQ | 0xffffff ), Model_iPAQ_H31xx = ( Model_iPAQ | 0x000001 ), Model_iPAQ_H36xx = ( Model_iPAQ | 0x000002 ), Model_iPAQ_H37xx = ( Model_iPAQ | 0x000004 ), Model_iPAQ_H38xx = ( Model_iPAQ | 0x000008 ), Model_iPAQ_H39xx = ( Model_iPAQ | 0x000010 ), Model_Zaurus = ( 2 << 24 ), Model_Zaurus_SL5000 = ( Model_Zaurus | 0x000001 ), Model_Zaurus_SL5500 = ( Model_Zaurus | 0x000002 ), Model_Zaurus_SLA300 = ( Model_Zaurus | 0x000003 ), Model_Zaurus_SLB600 = ( Model_Zaurus | 0x000004 ), Model_Zaurus_SLC700 = ( Model_Zaurus | 0x000005 ), Model_SIMpad = ( 3 << 24 ), Model_SIMpad_All = ( Model_SIMpad | 0xffffff ), Model_SIMpad_CL4 = ( Model_SIMpad | 0x000001 ), Model_SIMpad_SL4 = ( Model_SIMpad | 0x000002 ), Model_SIMpad_SLC = ( Model_SIMpad | 0x000004 ), Model_SIMpad_TSinus = ( Model_SIMpad | 0x000008 ), Model_Ramses = ( 4 << 24 ), Model_Ramses_All = ( Model_Ramses | 0xffffff ), Model_Ramses_MNCI = ( Model_Ramses | 0x000001 ), }; /** * The vendor of the device */ enum OVendor { Vendor_Unknown, Vendor_HP, Vendor_Sharp, Vendor_SIEMENS, Vendor_MundN, }; /** * The System used */ enum OSystem { @@ -91,155 +92,158 @@ enum OSystem { System_Familiar, System_Zaurus, System_OpenZaurus }; enum OLedState { Led_Off, Led_On, Led_BlinkSlow, Led_BlinkFast }; enum OLed { Led_Mail, Led_Power, Led_BlueTooth }; enum OHardKey { HardKey_Datebook = Qt::Key_F9, HardKey_Contacts = Qt::Key_F10, HardKey_Menu = Qt::Key_F11, HardKey_Home = Qt::Key_F12, HardKey_Mail = Qt::Key_F13, HardKey_Record = Qt::Key_F24, HardKey_Suspend = Qt::Key_F34, HardKey_Backlight = Qt::Key_F35, }; enum ODirection { CW = 0, CCW = 1, Flip = 2, }; /** * A singleton which gives informations about device specefic option * like the Hardware used, LEDs, the Base Distribution and * hardware key mappings. * * @short A small class for device specefic options * @see QObject * @author Robert Griebl * @version 1.0 */ class ODevice : public QObject { Q_OBJECT private: /* disable copy */ ODevice ( const ODevice & ); protected: ODevice ( ); virtual void init ( ); virtual void initButtons ( ); ODeviceData *d; public: // sandman do we want to allow destructions? -zecke? virtual ~ODevice ( ); - static ODevice *inst ( ); // information QString modelString ( ) const; OModel model ( ) const; inline OModel series ( ) const { return (OModel) ( model ( ) & Model_Series_Mask ); } QString vendorString ( ) const; OVendor vendor ( ) const; QString systemString ( ) const; OSystem system ( ) const; QString systemVersionString ( ) const; Transformation rotation ( ) const; ODirection direction ( ) const; // system virtual bool setSoftSuspend ( bool on ); virtual bool suspend ( ); virtual bool setDisplayStatus ( bool on ); virtual bool setDisplayBrightness ( int brightness ); virtual int displayBrightnessResolution ( ) const; virtual bool setDisplayContrast ( int contrast ); virtual int displayContrastResolution ( ) const; // input / output //FIXME playAlarmSound and al might be better -zecke 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 ); virtual bool hasLightSensor ( ) const; virtual int readLightSensor ( ); virtual int lightSensorResolution ( ) const; + QStrList &cpuFrequencies() const; + bool setCpuFrequency(uint index); + uint cpuFrequency() const; + /** * Returns the available buttons on this device. The number and location * of buttons will vary depending on the device. Button numbers will be assigned * by the device manufacturer and will be from most preferred button to least preffered * button. Note that this list only contains "user mappable" buttons. */ const QValueList<ODeviceButton> &buttons ( ); /** * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it * returns 0L */ const ODeviceButton *buttonForKeycode ( ushort keyCode ); /** * Reassigns the pressed action for \a button. To return to the factory * default pass an empty string as \a qcopMessage. */ void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); /** * Reassigns the held action for \a button. To return to the factory * default pass an empty string as \a qcopMessage. */ void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); /** * How long (in ms) you have to press a button for a "hold" action */ uint buttonHoldTime ( ) const; signals: void buttonMappingChanged ( ); private slots: void systemMessage ( const QCString &, const QByteArray & ); protected: void reloadButtonMapping ( ); }; } #endif |