From e85f02dd9186079cf67a4d3e7d1657d248e28963 Mon Sep 17 00:00:00 2001 From: xNUTx Date: Fri, 18 Jul 2014 01:30:58 +0200 Subject: Support reading since_epoch and secondary brightness files TWFunc::Fixup_Time_On_Boot: Will now try to read /sys/class/rtc/rtc0/since_epoch to correct time, if that fails it will try to use the ats files to correct time. TWFunc::Set_Brightness: One single function to set brightness from both the automated functions and the gui actions. It is able to set a second brightness path if present, it will set them both the same value. Many Sony devices have 2 brightness files in the sysfs that must be set to properly set the brightness. Change-Id: I7ca582109085dfbcb46b8de73ad031e4b7903fca --- gui/action.cpp | 5 +++++ gui/blanktimer.cpp | 40 +++++++++------------------------ gui/blanktimer.hpp | 4 ++-- gui/devices/landscape/res/landscape.xml | 2 +- gui/devices/portrait/res/portrait.xml | 2 +- gui/devices/watch/res/watch.xml | 2 +- 6 files changed, 21 insertions(+), 34 deletions(-) (limited to 'gui') diff --git a/gui/action.cpp b/gui/action.cpp index b77e7e751..c471533ef 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -824,6 +824,11 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } + if (function == "setbrightness") + { + return TWFunc::Set_Brightness(arg); + } + if (isThreaded) { if (function == "fileexists") diff --git a/gui/blanktimer.cpp b/gui/blanktimer.cpp index 383b15724..1b184297b 100644 --- a/gui/blanktimer.cpp +++ b/gui/blanktimer.cpp @@ -97,11 +97,11 @@ int blanktimer::setClockTimer(void) { if (sleepTimer > 2 && diff.tv_sec > (sleepTimer - 2) && conblank == 0) { orig_brightness = getBrightness(); setConBlank(1); - setBrightness(5); + TWFunc::Set_Brightness("5"); } if (sleepTimer && diff.tv_sec > sleepTimer && conblank < 2) { setConBlank(2); - setBrightness(0); + TWFunc::Set_Brightness("0"); screenoff = true; TWFunc::check_and_run_script("/sbin/postscreenblank.sh", "blank"); PageManager::ChangeOverlay("lock"); @@ -115,39 +115,20 @@ int blanktimer::setClockTimer(void) { return -1; //shouldn't get here } -int blanktimer::getBrightness(void) { - string results; +string blanktimer::getBrightness(void) { + string result; string brightness_path; DataManager::GetValue("tw_brightness_file", brightness_path); - if ((TWFunc::read_file(brightness_path, results)) != 0) - return -1; - int result = atoi(results.c_str()); - if (result == 0) { - int tw_brightness; - DataManager::GetValue("tw_brightness", tw_brightness); - if (tw_brightness) { - result = tw_brightness; - } else { - result = 255; - } + if (brightness_path == "/nobrightness") + return brightness_path; + DataManager::GetValue("tw_brightness", result); + if (result == "") { + result = "255"; } return result; } -int blanktimer::setBrightness(int brightness) { - string brightness_path; - string bstring; - char buff[100]; - DataManager::GetValue("tw_brightness_file", brightness_path); - sprintf(buff, "%d", brightness); - bstring = buff; - if ((TWFunc::write_file(brightness_path, bstring)) != 0) - return -1; - gui_forceRender(); - return 0; -} - void blanktimer::resetTimerAndUnblank(void) { setTimer(); switch (conblank) { @@ -165,7 +146,8 @@ void blanktimer::resetTimerAndUnblank(void) { screenoff = false; // No break here, we want to keep going case 1: - setBrightness(orig_brightness); + if (orig_brightness != "/nobrightness") + TWFunc::Set_Brightness(orig_brightness); setConBlank(0); break; } diff --git a/gui/blanktimer.hpp b/gui/blanktimer.hpp index 01c1dfb0c..c8159f643 100644 --- a/gui/blanktimer.hpp +++ b/gui/blanktimer.hpp @@ -41,7 +41,7 @@ private: void setConBlank(int blank); void setTimer(void); timespec getTimer(void); - int getBrightness(void); + string getBrightness(void); int setBrightness(int brightness); int setBlankTimer(void); int setClockTimer(void); @@ -51,7 +51,7 @@ private: int conblank; timespec btimer; unsigned long long sleepTimer; - int orig_brightness; + string orig_brightness; bool screenoff; }; diff --git a/gui/devices/landscape/res/landscape.xml b/gui/devices/landscape/res/landscape.xml index 902994917..2bed2a578 100644 --- a/gui/devices/landscape/res/landscape.xml +++ b/gui/devices/landscape/res/landscape.xml @@ -2589,7 +2589,7 @@ tw_brightness=%tw_brightness_max% tw_brightness*%tw_brightness_pct% tw_brightness/100 - echo %tw_brightness% > "%tw_brightness_file%" + %tw_brightness% diff --git a/gui/devices/portrait/res/portrait.xml b/gui/devices/portrait/res/portrait.xml index 6a3618e62..0be685517 100644 --- a/gui/devices/portrait/res/portrait.xml +++ b/gui/devices/portrait/res/portrait.xml @@ -2628,7 +2628,7 @@ tw_brightness=%tw_brightness_max% tw_brightness*%tw_brightness_pct% tw_brightness/100 - echo %tw_brightness% > "%tw_brightness_file%" + %tw_brightness% diff --git a/gui/devices/watch/res/watch.xml b/gui/devices/watch/res/watch.xml index b4b7062fe..686b24b3f 100644 --- a/gui/devices/watch/res/watch.xml +++ b/gui/devices/watch/res/watch.xml @@ -2592,7 +2592,7 @@ tw_brightness=%tw_brightness_max% tw_brightness*%tw_brightness_pct% tw_brightness/100 - echo %tw_brightness% > "%tw_brightness_file%" + %tw_brightness% -- cgit v1.2.3