-rw-r--r-- | libopie/odevice.cpp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 4b5a54e..4c33a0e 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -686,227 +686,223 @@ void ODevice::alarmSound ( ) } /** * This plays a key sound */ void ODevice::keySound ( ) { #ifndef QT_NO_SOUND static Sound snd ( "keysound" ); if ( snd. isFinished ( )) snd. play ( ); #endif } /** * This plays a touch sound */ void ODevice::touchSound ( ) { #ifndef QT_NO_SOUND static Sound snd ( "touchsound" ); if ( snd. isFinished ( )) snd. play ( ); #endif } /** * 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; -} + int fd; -/** - * 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 + if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { + char writeCommand[50]; + const int count = sprintf(writeCommand, "%s\n", freq); + int res = (::write(fd, writeCommand, count) != -1); + ::close(fd); + return res; + } - return 0; + return false; } - /** * @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 )); } } void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) { initButtons ( ); QString mb_chan; if ( button >= (int) d-> m_buttons-> count ( )) return; ODeviceButton &b = ( *d-> m_buttons ) [button]; b. setPressedAction ( action ); mb_chan=b. pressedAction ( ). channel ( ); Config buttonFile ( "ButtonSettings" ); buttonFile. setGroup ( "Button" + QString::number ( button )); buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); } void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) { initButtons ( ); if ( button >= (int) d-> m_buttons-> count ( )) @@ -1899,259 +1895,272 @@ bool SIMpad::suspend ( ) // Must override because SIMpad does NOT have apm bool SIMpad::setSoftSuspend ( bool soft ) { qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); return false; } bool SIMpad::setDisplayStatus ( bool on ) { qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); bool res = false; int fd; QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { res = ( ::system( (const char*) cmdline ) == 0 ); ::close ( fd ); } return res; } bool SIMpad::setDisplayBrightness ( int bright ) { qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); bool res = false; int fd; if ( bright > 255 ) bright = 255; 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"); +#ifdef QT_QWS_ALLOW_OVERCLOCK +#warning *** Overclocking enabled - this may fry your hardware - you have been warned *** +#define OC(x...) x +#else +#define OC(x...) +#endif + + + // This table is true for a Intel XScale PXA 255 + + d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 +OC( d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem + d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 +OC( d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem + d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 +OC( d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem + d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 + d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 +OC( d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus + } 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; // 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); } 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; } |