mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-05 05:08:05 +02:00
PowerSaver: re-layouted code.
No functional changes.
This commit is contained in:
parent
e73a8d06ea
commit
ae685a9729
@ -1,34 +1,35 @@
|
||||
#include "powersaver.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "powersaver.h"
|
||||
#include "debug.h"
|
||||
PowerSaver* PowerSaver::instance = NULL;
|
||||
Uint32 screenTimerCallback(Uint32, void *)
|
||||
{
|
||||
DEBUG("Disable Backlight Event\n");
|
||||
PowerSaver::getInstance()->disableScreen();
|
||||
return 0;
|
||||
PowerSaver *PowerSaver::instance = NULL;
|
||||
|
||||
Uint32 screenTimerCallback(Uint32, void *) {
|
||||
DEBUG("Disable Backlight Event\n");
|
||||
PowerSaver::getInstance()->disableScreen();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PowerSaver* PowerSaver::getInstance() {
|
||||
if ( instance == NULL ) {
|
||||
instance = new PowerSaver();
|
||||
}
|
||||
return instance;
|
||||
PowerSaver *PowerSaver::getInstance() {
|
||||
if (instance == NULL) {
|
||||
instance = new PowerSaver();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool PowerSaver::isRunning() {
|
||||
return instance != NULL;
|
||||
}
|
||||
|
||||
PowerSaver::PowerSaver( ) {
|
||||
PowerSaver::PowerSaver() {
|
||||
SDL_InitSubSystem(SDL_INIT_TIMER);
|
||||
setScreenTimeout(0);
|
||||
screenTimer = NULL;
|
||||
setScreenTimeout(0);
|
||||
screenTimer = NULL;
|
||||
}
|
||||
|
||||
PowerSaver::~PowerSaver() {
|
||||
@ -37,40 +38,40 @@ PowerSaver::~PowerSaver() {
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
void PowerSaver::setScreenTimeout( unsigned int seconds ) {
|
||||
screenTimeout = seconds;
|
||||
resetScreenTimer();
|
||||
void PowerSaver::setScreenTimeout(unsigned int seconds) {
|
||||
screenTimeout = seconds;
|
||||
resetScreenTimer();
|
||||
}
|
||||
|
||||
void PowerSaver::resetScreenTimer() {
|
||||
if ( screenTimer != NULL ) {
|
||||
SDL_RemoveTimer(screenTimer);
|
||||
}
|
||||
if (screenTimer != NULL) {
|
||||
SDL_RemoveTimer(screenTimer);
|
||||
}
|
||||
|
||||
addScreenTimer();
|
||||
//If display is off, turn on it
|
||||
if ( !screenState ) {
|
||||
enableScreen();
|
||||
}
|
||||
addScreenTimer();
|
||||
// If display is off, turn on it.
|
||||
if (!screenState) {
|
||||
enableScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void PowerSaver::addScreenTimer() {
|
||||
//if timeout is zero, don't set timeout
|
||||
if ( screenTimeout == 0 ) {
|
||||
screenTimer = NULL;
|
||||
return;
|
||||
}
|
||||
// If timeout is zero, don't set timeout.
|
||||
if (screenTimeout == 0) {
|
||||
screenTimer = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
screenTimer = SDL_AddTimer(screenTimeout*1000, screenTimerCallback,NULL);
|
||||
if ( screenTimer == NULL ) {
|
||||
screenTimer = SDL_AddTimer(screenTimeout * 1000, screenTimerCallback, NULL);
|
||||
if (screenTimer == NULL) {
|
||||
ERROR("Could not initialize SDLTimer: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define SCREEN_BLANK_PATH "/sys/class/graphics/fb0/blank"
|
||||
void PowerSaver::setScreenBlanking( bool state ) {
|
||||
const char* path = SCREEN_BLANK_PATH;
|
||||
const char* blank = state ? "0" : "1";
|
||||
void PowerSaver::setScreenBlanking(bool state) {
|
||||
const char *path = SCREEN_BLANK_PATH;
|
||||
const char *blank = state ? "0" : "1";
|
||||
|
||||
int fd = open(path, O_RDWR);
|
||||
if (fd == -1) {
|
||||
@ -82,18 +83,17 @@ void PowerSaver::setScreenBlanking( bool state ) {
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
screenState = state;
|
||||
screenState = state;
|
||||
}
|
||||
|
||||
void PowerSaver::enableScreen() {
|
||||
if ( !screenState ) {
|
||||
setScreenBlanking(true);
|
||||
}
|
||||
if (!screenState) {
|
||||
setScreenBlanking(true);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerSaver::disableScreen() {
|
||||
if ( screenState ) {
|
||||
setScreenBlanking(false);
|
||||
}
|
||||
if (screenState) {
|
||||
setScreenBlanking(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,26 +1,29 @@
|
||||
#ifndef POWERSAVER_H
|
||||
#define POWERSAVER_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
class PowerSaver {
|
||||
public:
|
||||
static PowerSaver *getInstance();
|
||||
static bool isRunning();
|
||||
~PowerSaver();
|
||||
void resetScreenTimer();
|
||||
|
||||
public:
|
||||
static PowerSaver* getInstance();
|
||||
static bool isRunning();
|
||||
~PowerSaver();
|
||||
void addScreenTimer();
|
||||
void resetScreenTimer();
|
||||
void enableScreen();
|
||||
void disableScreen();
|
||||
|
||||
void enableScreen();
|
||||
void disableScreen();
|
||||
void setScreenTimeout(unsigned int seconds);
|
||||
|
||||
void setScreenTimeout( unsigned int seconds );
|
||||
private:
|
||||
PowerSaver( );
|
||||
static PowerSaver* instance;
|
||||
bool screenState;
|
||||
unsigned int screenTimeout;
|
||||
SDL_TimerID screenTimer;
|
||||
|
||||
void setScreenBlanking( bool state );
|
||||
private:
|
||||
PowerSaver();
|
||||
void addScreenTimer();
|
||||
void setScreenBlanking(bool state);
|
||||
|
||||
static PowerSaver *instance;
|
||||
bool screenState;
|
||||
unsigned int screenTimeout;
|
||||
SDL_TimerID screenTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user