QTOPIABASE_EXPORT void qpe_setBrightness(int b) { static int previous = 0; static int max = qpe_sysBrightnessSteps(); /* get it once */ if (b < 0) b = max; /*if (b > 1 && previous == 0) { fb_power(true); */ // sleep(1); /* ugly: let it a little of time to avoid an lcd flash */ //} QFile brightness("/sys/class/backlight/corgi-bl/brightness"); if(!brightness.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { qWarning() << "/sys/class/backlight/corgi-bl/brightness not opened"; } else { QTextStream out(&brightness); out << QString::number(b); brightness.close(); } /*if (b == 0) fb_power(false); previous = b;*/ }
QTOPIABASE_EXPORT void qpe_setBrightness(int b) { int brightessSteps = qpe_sysBrightnessSteps(); if(b > brightessSteps) b = brightessSteps; if(b == 1) { // dim b = brightessSteps / 4; } else if (b == -1) { //bright b = brightessSteps; } QFile brightness; if (QFileInfo("/sys/class/backlight/gta01-bl/brightness").exists() ) { brightness.setFileName("/sys/class/backlight/gta01-bl/brightness"); //ficgta01 } else if (QFileInfo("/sys/class/backlight/gta02-bl/brightness").exists() ) { //ficgta02, recent kernel (> 2.6.28 ) brightness.setFileName("/sys/class/backlight/gta02-bl/brightness"); } else { brightness.setFileName("/sys/class/backlight/pcf50633-bl/brightness"); //ficgta02 } if(!brightness.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { qWarning() << "qpe_setBrightness: File not opened"; } else { QTextStream out(&brightness); out << QString::number(b); brightness.close(); } }
/*! \internal Sets the back light to \a bright. \sa backlight */ void QtopiaPowerManager::setBacklight(int bright) { qLog(PowerManagement) << "QtopiaPowerManager: setBacklight =>" << bright ; if ( bright == -3 ) { // Forced on forced_off = false; bright = -1; } if ( forced_off && bright != -2 ) return; if ( bright == -2 ) { // Toggle between off and on bright = currentBacklight ? 0 : -1; forced_off = !bright; } if ( bright == -1 ) { // Read from config QSettings config("Trolltech","qpe"); if (powerstatus.wallStatus() == QPowerStatus::Available) config.beginGroup( "ExternalPower" ); else config.beginGroup( "BatteryPower" ); bright = config.value("Brightness", qpe_sysBrightnessSteps()).toInt(); } qpe_setBrightness(bright); currentBacklight = bright; if (m_vso) m_vso->setAttribute("Display/0/Backlight", bright); }
/*! \internal Returns the current level of the backlight. The return value has a range between 0 and the vlaue set by qpe_sysBrightnessSteps() ( qpe_sysBrightnessSteps() being the brightest backlight setting ). \sa setBacklight */ int QtopiaPowerManager::backlight() { if (currentBacklight == -1) { QSettings config("Trolltech","qpe"); if (powerstatus.wallStatus() == QPowerStatus::Available) config.beginGroup( "ExternalPower" ); else config.beginGroup( "BatteryPower" ); currentBacklight = config.value("Brightness", qpe_sysBrightnessSteps()).toInt(); } return currentBacklight; }
void LightSettings::writeMode(QSettings &config, PowerMode *mode) { config.setValue( "Dim", mode->dim ); config.setValue( "LightOff", mode->lightoff ); config.setValue( "Interval_Dim", mode->intervalDim ); config.setValue( "Interval_LightOff", mode->intervalLightOff ); config.setValue( "Brightness", (mode->brightness * 255 + qpe_sysBrightnessSteps()/2) / qpe_sysBrightnessSteps() ); if (mode->canSuspend) { config.setValue( "Interval", mode->intervalSuspend ); config.setValue( "Suspend", mode->suspend ); } else { config.setValue( "Interval", 0 ); config.setValue( "Suspend", false ); } }
void LightSettings::reject() { // Set settings for current power source if ( powerStatus.wallStatus() == QPowerStatus::Available ) currentMode = &externalMode; else currentMode = &batteryMode; set_fl(currentMode->initBrightness); // Restore brightness settings QSettings config("Trolltech", "qpe"); config.beginGroup("LockPower"); config.setValue("Brightness", (batteryMode.initBrightness * 255 + qpe_sysBrightnessSteps()/2) / qpe_sysBrightnessSteps()); config.endGroup(); config.beginGroup("BatteryPower"); config.setValue("Brightness", (batteryMode.initBrightness * 255 + qpe_sysBrightnessSteps()/2) / qpe_sysBrightnessSteps()); config.endGroup(); config.beginGroup("ExternalPower"); config.setValue("Brightness", (externalMode.initBrightness * 255 + qpe_sysBrightnessSteps()/2) / qpe_sysBrightnessSteps()); config.endGroup(); QDialog::reject(); }
void LightSettings::applyBrightness() { // slot called, but we haven't changed the powerMode values yet currentMode->brightness = b->brightness->value(); set_fl(currentMode->brightness); QSettings config("Trolltech", "qpe"); if (currentMode == &lockMode) config.beginGroup("LockPower"); else if (currentMode == &batteryMode) config.beginGroup("BatteryPower"); else config.beginGroup("ExternalPower"); config.setValue("Brightness", (currentMode->brightness * 255 + qpe_sysBrightnessSteps()/2) / qpe_sysBrightnessSteps()); }
QTOPIABASE_EXPORT void qpe_setBrightness(int b) { int brightessSteps = qpe_sysBrightnessSteps(); if(b > brightessSteps) b = brightessSteps; if(b == 1) { // dim b = brightessSteps / 4; } else if (b == -1) { //bright b = brightessSteps; } QByteArray str = QByteArray::number(b); qWriteFile("/sys/class/backlight/pcf50633-backlight/brightness", str.constData()); }
QTOPIABASE_EXPORT void qpe_setBrightness(int b) { int brightessSteps = qpe_sysBrightnessSteps(); if(b > brightessSteps) b = brightessSteps; if(b == 1) { // dim b = brightessSteps / 4; } else if (b == -1) { //bright b = brightessSteps; } QFile f("/sys/class/backlight/pcf50633-backlight/brightness"); if(!f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { qWarning() << "qpe_setBrightness: " + f.errorString(); return; } QTextStream out(&f); out << QString::number(b); f.close(); }
LightSettings::LightSettings( QWidget* parent, Qt::WFlags fl ) : QDialog( parent, fl), isStatusView( false ) { setWindowTitle(tr("Power Management")); QVBoxLayout * baseLayout = new QVBoxLayout( this ); baseLayout->setMargin( 0 ); QWidget * container = new QWidget(); QScrollArea *sView = new QScrollArea; sView->setFocusPolicy(Qt::NoFocus); sView->setFrameStyle(QFrame::NoFrame); sView->setWidget( container ); sView->setWidgetResizable( true ); sView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QVBoxLayout *lightLayout = new QVBoxLayout(container); lightLayout->setMargin( 0 ); b = new LightSettingsContainer(); QtopiaApplication::setInputMethodHint( b->interval_dim, QtopiaApplication::AlwaysOff ); QtopiaApplication::setInputMethodHint( b->interval_lightoff, QtopiaApplication::AlwaysOff ); QtopiaApplication::setInputMethodHint( b->interval_suspend, QtopiaApplication::AlwaysOff ); lightLayout->addWidget(b); baseLayout->addWidget(sView); // add context menu to push its status to Profiles contextMenu = QSoftMenuBar::menuFor( this ); QAction* actionCapture = new QAction( QIcon( ":icon/Note" ), tr( "Add to current profile" ), this ); contextMenu->addAction( actionCapture ); connect( actionCapture, SIGNAL(triggered()), this, SLOT(pushSettingStatus()) ); connect( qApp, SIGNAL(appMessage(QString,QByteArray)), this, SLOT(receive(QString,QByteArray)) ); connect( b->interval_dim, SIGNAL(valueChanged(int)), this, SLOT(updateLightOffMinValue(int)) ); connect( b->interval_dim, SIGNAL(valueChanged(int)), this, SLOT(updateSuspendMinValue(int)) ); connect( b->interval_lightoff, SIGNAL(valueChanged(int)), this, SLOT(updateSuspendMinValue(int)) ); b->officon->setPixmap(QPixmap(":image/off").scaled(24, 24, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); b->brighticon->setPixmap(QPixmap(":image/Light").scaled(24, 24, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); QSettings hwConfig("Trolltech", "Hardware"); hwConfig.beginGroup("PowerManagement"); lockMode.canSuspend = hwConfig.value("CanSuspendLock", false).toBool(); batteryMode.canSuspend = hwConfig.value("CanSuspend", false).toBool(); externalMode.canSuspend = hwConfig.value("CanSuspendAC", false).toBool(); hwConfig.endGroup(); b->notnetworkedsuspend->hide(); if (batteryMode.canSuspend || externalMode.canSuspend || lockMode.canSuspend) { b->interval_suspend->setEnabled(true); } else { b->interval_suspend->hide(); b->label_suspend->hide(); } QSettings config("Trolltech","qpe"); config.beginGroup("LockPower"); lockMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt(); lockMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt(); lockMode.intervalSuspend = config.value("Interval", 60).toInt(); lockMode.brightness = config.value("Brightness", 255).toInt(); lockMode.brightness = qMax(1,lockMode.brightness * qpe_sysBrightnessSteps() / 255); lockMode.initBrightness = lockMode.brightness; lockMode.dim = config.value("Dim", true).toBool(); lockMode.lightoff = config.value("LightOff", false).toBool(); lockMode.suspend = config.value("Suspend", true).toBool(); lockMode.networkedsuspend = config.value("NetworkedSuspend", true).toBool(); config.endGroup(); config.beginGroup("BatteryPower"); batteryMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt(); batteryMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt(); batteryMode.intervalSuspend = config.value("Interval", 60).toInt(); batteryMode.brightness = config.value("Brightness", 255).toInt(); batteryMode.brightness = qMax(1,batteryMode.brightness * qpe_sysBrightnessSteps() / 255); batteryMode.initBrightness = batteryMode.brightness; batteryMode.dim = config.value("Dim", true).toBool(); batteryMode.lightoff = config.value("LightOff", false).toBool(); batteryMode.suspend = config.value("Suspend", true).toBool(); batteryMode.networkedsuspend = config.value("NetworkedSuspend", true).toBool(); config.endGroup(); config.beginGroup("ExternalPower"); externalMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt(); externalMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt(); externalMode.intervalSuspend = config.value("Interval", 240).toInt(); externalMode.brightness = config.value("Brightness", 255).toInt(); externalMode.brightness = qMax(1,externalMode.brightness * qpe_sysBrightnessSteps() / 255); externalMode.initBrightness = externalMode.brightness; externalMode.dim = config.value("Dim", true).toBool(); externalMode.lightoff = config.value("LightOff", false).toBool(); //default to leave on externalMode.suspend = config.value("Suspend", true).toBool(); externalMode.networkedsuspend = config.value("NetworkedSuspend",false).toBool(); config.endGroup(); //must set min > 0 the screen will become completely black int maxbright = qpe_sysBrightnessSteps(); b->brightness->setMaximum( maxbright ); b->brightness->setMinimum( 1 ); b->brightness->setTickInterval( qMax(1,maxbright/16) ); b->brightness->setSingleStep( qMax(1,maxbright/16) ); b->brightness->setPageStep( qMax(1,maxbright/16) ); currentMode = &batteryMode; applyMode(); connect(b->powerSource, SIGNAL(currentIndexChanged(int)), this, SLOT(powerTypeChanged(int))); if ( powerStatus.wallStatus() == QPowerStatus::Available ) { b->powerSource->setCurrentIndex(1); } connect(b->brightness, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness())); QtopiaChannel *channel = new QtopiaChannel("Qtopia/PowerStatus", this); connect(channel, SIGNAL(received(QString,QByteArray)), this, SLOT(sysMessage(QString,QByteArray))); }
/* Apply light/power settings for current power source */ static void applyLightSettings(QPowerStatus *p) { int initbright; int intervalDim; int intervalLightOff; int intervalSuspend; bool dim; bool lightoff; bool suspend; bool canSuspend; QSettings config("Trolltech","qpe"); QSettings hwConfig("Trolltech", "Hardware"); hwConfig.beginGroup("PowerManagement"); if (p->wallStatus() == QPowerStatus::Available) { config.beginGroup("ExternalPower"); canSuspend = hwConfig.value("CanSuspendAC", false).toBool(); } else { config.beginGroup("BatteryPower"); canSuspend = hwConfig.value("CanSuspend", false).toBool(); } intervalDim = config.value("Interval_Dim", 20).toInt(); config.setValue("Interval_Dim", intervalDim); intervalLightOff = config.value("Interval_LightOff", 30).toInt(); config.setValue("Interval_LightOff", intervalLightOff); if (canSuspend) { if (p->wallStatus() == QPowerStatus::Available) { intervalSuspend = config.value("Interval", 240).toInt(); config.setValue("Interval", intervalSuspend); } else { intervalSuspend = config.value("Interval", 60).toInt(); config.setValue("Interval", intervalSuspend); } suspend = config.value("Suspend", true).toBool(); config.setValue("Suspend", suspend); } else { intervalSuspend = 0; config.setValue("Interval", intervalSuspend); suspend = false; config.setValue("Suspend", suspend); } initbright = config.value("Brightness", qpe_sysBrightnessSteps()).toInt(); config.setValue("Brightness", initbright); dim = config.value("Dim", true).toBool(); config.setValue("Dim", dim); lightoff = config.value("LightOff", false).toBool(); config.setValue("LightOff", lightoff); config.sync(); //write out for syncronisation with light app int i_dim = (dim ? intervalDim : 0); int i_lightoff = (lightoff ? intervalLightOff : 0); int i_suspend = (suspend ? intervalSuspend : 0); QtopiaServiceRequest eB("QtopiaPowerManager", "setBacklight(int)" ); eB << -3; //forced on eB.send(); QtopiaServiceRequest e("QtopiaPowerManager", "setIntervals(int,int,int)" ); e << i_dim << i_lightoff << i_suspend; e.send(); }