src/Makefile.am |
12 | 12 | textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ |
13 | 13 | utilities.cpp wallpaperdialog.cpp \ |
14 | 14 | browsedialog.cpp buttonbox.cpp dialog.cpp \ |
15 | | imageio.cpp |
| 15 | imageio.cpp powersaver.cpp |
16 | 16 | |
17 | 17 | noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \ |
18 | 18 | filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \ |
... | ... | |
25 | 25 | surfacecollection.h surface.h textdialog.h textmanualdialog.h \ |
26 | 26 | touchscreen.h translator.h utilities.h wallpaperdialog.h \ |
27 | 27 | browsedialog.h buttonbox.h dialog.h \ |
28 | | imageio.h |
| 28 | imageio.h powersaver.h |
29 | 29 | |
30 | 30 | AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@ |
31 | 31 | |
src/gmenu2x.cpp |
194 | 194 | #endif |
195 | 195 | } |
196 | 196 | |
| 197 | |
197 | 198 | GMenu2X::GMenu2X() { |
198 | 199 | //Detect firmware version and type |
199 | 200 | if (fileExists("/etc/open2x")) { |
... | ... | |
271 | 272 | #endif |
272 | 273 | |
273 | 274 | //Screen |
274 | | if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK)<0 ) { |
| 275 | if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK|SDL_INIT_TIMER)<0 ) { |
275 | 276 | ERROR("Could not initialize SDL: %s\n", SDL_GetError()); |
276 | 277 | quit(); |
277 | 278 | } |
... | ... | |
309 | 310 | |
310 | 311 | initBG(); |
311 | 312 | input.init(path+"input.conf"); |
| 313 | PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] ); |
312 | 314 | setInputSpeed(); |
313 | 315 | initServices(); |
314 | 316 | setBacklight(confInt["backlight"]); |
... | ... | |
319 | 321 | readTmp(); |
320 | 322 | if (lastSelectorElement>-1 && menu->selLinkApp()!=NULL && (!menu->selLinkApp()->getSelectorDir().empty() || !lastSelectorDir.empty())) |
321 | 323 | menu->selLinkApp()->selector(lastSelectorElement,lastSelectorDir); |
| 324 | |
322 | 325 | } |
323 | 326 | |
324 | 327 | GMenu2X::~GMenu2X() { |
... | ... | |
561 | 564 | evalIntConf( &confInt["maxClock"], 430, 30, 500 ); |
562 | 565 | evalIntConf( &confInt["menuClock"], 200, 30, 430 ); |
563 | 566 | evalIntConf( &confInt["globalVolume"], 67, 0,100 ); |
| 567 | evalIntConf( &confInt["backlightTimeout"], 15, 0,120 ); |
564 | 568 | evalIntConf( &confInt["backlight"], 100, 5,100 ); |
565 | 569 | evalIntConf( &confInt["videoBpp"], 32,32,32 ); // 8,16 |
566 | 570 | |
... | ... | |
816 | 820 | if (!fileExists(CARD_ROOT)) |
817 | 821 | CARD_ROOT = "/"; |
818 | 822 | |
819 | | |
820 | 823 | while (!quit) { |
821 | 824 | tickNow = SDL_GetTicks(); |
822 | 825 | |
... | ... | |
1112 | 1115 | sd.addSetting(new MenuSettingBool(this,tr["Output logs"],tr["Logs the output of the links. Use the Log Viewer to read them."],&confInt["outputLogs"])); |
1113 | 1116 | //G |
1114 | 1117 | sd.addSetting(new MenuSettingInt(this,tr["Lcd Backlight"],tr["Set dingoo's Lcd Backlight value (default: 100)"],&confInt["backlight"],5,100)); |
| 1118 | sd.addSetting(new MenuSettingInt(this,tr["Screen Timeout"],tr["Set screen's backlight timeout in seconds"],&confInt["backlightTimeout"],0,120)); |
1115 | 1119 | // sd.addSetting(new MenuSettingMultiString(this,tr["Tv-Out encoding"],tr["Encoding of the tv-out signal"],&confStr["tvoutEncoding"],&encodings)); |
1116 | 1120 | sd.addSetting(new MenuSettingBool(this,tr["Show root"],tr["Show root folder in the file selection dialogs"],&showRootFolder)); |
1117 | 1121 | |
... | ... | |
1120 | 1124 | if (prevbacklight != confInt["backlight"]) setBacklight(confInt["backlight"]); |
1121 | 1125 | if (curMenuClock!=confInt["menuClock"]) setClock(confInt["menuClock"]); |
1122 | 1126 | if (curGlobalVolume!=confInt["globalVolume"]) setVolume(confInt["globalVolume"]); |
| 1127 | PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] ); |
1123 | 1128 | if (lang == "English") lang = ""; |
1124 | 1129 | if (lang != tr.lang()) { |
1125 | 1130 | tr.setLang(lang); |
src/powersaver.cpp |
| 1 | #include <errno.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include "powersaver.h" |
| 8 | #include "debug.h" |
| 9 | PowerSaver* PowerSaver::instance = NULL; |
| 10 | Uint32 screenTimerCallback(Uint32 interval, void *param) |
| 11 | { |
| 12 | DEBUG("Disable Backlight Event\n"); |
| 13 | PowerSaver::getInstance()->disableScreen(); |
| 14 | return 0; |
| 15 | } |
| 16 | |
| 17 | PowerSaver* PowerSaver::getInstance() { |
| 18 | if ( instance == NULL ) { |
| 19 | instance = new PowerSaver(); |
| 20 | } |
| 21 | return instance; |
| 22 | } |
| 23 | |
| 24 | PowerSaver::PowerSaver( ) { |
| 25 | setScreenTimeout(0); |
| 26 | screenTimer = NULL; |
| 27 | } |
| 28 | |
| 29 | PowerSaver::~PowerSaver() { |
| 30 | SDL_RemoveTimer(screenTimer); |
| 31 | } |
| 32 | |
| 33 | void PowerSaver::setScreenTimeout( unsigned int seconds ) { |
| 34 | screenTimeout = seconds; |
| 35 | resetScreenTimer(); |
| 36 | } |
| 37 | |
| 38 | void PowerSaver::resetScreenTimer() { |
| 39 | if ( screenTimer != NULL ) { |
| 40 | SDL_RemoveTimer(screenTimer); |
| 41 | } |
| 42 | addScreenTimer(); |
| 43 | //If display is off, turn on it |
| 44 | if ( !screenState ) { |
| 45 | enableScreen(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void PowerSaver::addScreenTimer() { |
| 50 | //if timeout is zero, don't set timeout |
| 51 | if ( screenTimeout == 0 ) { |
| 52 | screenTimer = NULL; |
| 53 | return; |
| 54 | } |
| 55 | screenTimer = SDL_AddTimer(screenTimeout*1000, screenTimerCallback,NULL); |
| 56 | if ( screenTimer == NULL ) { |
| 57 | ERROR("Could not initialize SDLTimer: %s\n", SDL_GetError()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | #define SCREEN_BLANK_PATH "/sys/class/graphics/fb0/blank" |
| 62 | void PowerSaver::setScreenBlanking( bool state ) { |
| 63 | const char* path = SCREEN_BLANK_PATH; |
| 64 | const char* blank = state ? "0" : "1"; |
| 65 | |
| 66 | int fd = open(path, O_RDWR); |
| 67 | if (fd == -1) { |
| 68 | WARNING("Failed to open '%s': %s\n", path, strerror(errno)); |
| 69 | } else { |
| 70 | ssize_t written = write(fd, blank, strlen(blank)); |
| 71 | if (written == -1) { |
| 72 | WARNING("Error writing '%s': %s\n", path, strerror(errno)); |
| 73 | } |
| 74 | close(fd); |
| 75 | } |
| 76 | screenState = state; |
| 77 | } |
| 78 | |
| 79 | void PowerSaver::enableScreen() { |
| 80 | if ( !screenState ) { |
| 81 | setScreenBlanking(true); |
| 82 | } |
| 83 | } |
| 84 | void PowerSaver::disableScreen() { |
| 85 | if ( screenState ) { |
| 86 | setScreenBlanking(false); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |