From 1710bf254756d49355e9156ba1907545addfb319 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Thu, 2 Oct 2014 20:22:21 -0400 Subject: display cpu temperature in twrp use TW_NO_CPU_TEMP := true to disable display use TW_CPU_CUSTOM_PATH := path to set custom path Change-Id: Id260ecbb4ec36a78442387329944f67003d0f6a0 --- Android.mk | 9 ++++++++ data.cpp | 49 ++++++++++++++++++++++++++++++++++++++-- gui/devices/1024x600/res/ui.xml | 17 ++++++++++---- gui/devices/1024x768/res/ui.xml | 17 ++++++++++---- gui/devices/1080x1920/res/ui.xml | 9 ++++++++ gui/devices/1200x1920/res/ui.xml | 9 ++++++++ gui/devices/1280x800/res/ui.xml | 9 ++++++++ gui/devices/1440x2560/res/ui.xml | 15 +++++++++--- gui/devices/1600x2560/res/ui.xml | 9 ++++++++ gui/devices/1920x1200/res/ui.xml | 11 ++++++++- gui/devices/240x240/res/ui.xml | 13 +++++++++-- gui/devices/2560x1600/res/ui.xml | 9 ++++++++ gui/devices/280x280/res/ui.xml | 11 ++++++++- gui/devices/320x320/res/ui.xml | 11 ++++++++- gui/devices/320x480/res/ui.xml | 11 ++++++++- gui/devices/480x800/res/ui.xml | 11 ++++++++- gui/devices/480x854/res/ui.xml | 11 ++++++++- gui/devices/540x960/res/ui.xml | 11 ++++++++- gui/devices/720x1280/res/ui.xml | 9 ++++++++ gui/devices/800x1280/res/ui.xml | 9 ++++++++ gui/devices/800x480/res/ui.xml | 11 ++++++++- twrp-functions.cpp | 6 +++++ twrp-functions.hpp | 1 + 23 files changed, 255 insertions(+), 23 deletions(-) diff --git a/Android.mk b/Android.mk index 03e1a6962..5ec184e9d 100644 --- a/Android.mk +++ b/Android.mk @@ -199,6 +199,9 @@ endif ifeq ($(TW_NO_BATT_PERCENT), true) LOCAL_CFLAGS += -DTW_NO_BATT_PERCENT endif +ifeq ($(TW_NO_CPU_TEMP), true) + LOCAL_CFLAGS += -DTW_NO_CPU_TEMP +endif ifneq ($(TW_CUSTOM_POWER_BUTTON),) LOCAL_CFLAGS += -DTW_CUSTOM_POWER_BUTTON=$(TW_CUSTOM_POWER_BUTTON) endif @@ -288,6 +291,12 @@ endif ifneq ($(TW_CUSTOM_BATTERY_PATH),) LOCAL_CFLAGS += -DTW_CUSTOM_BATTERY_PATH=$(TW_CUSTOM_BATTERY_PATH) endif +ifneq ($(TW_CUSTOM_CPU_TEMP_PATH),) + LOCAL_CFLAGS += -DTW_CUSTOM_CPU_TEMP_PATH=$(TW_CUSTOM_CPU_TEMP_PATH) +endif +ifneq ($(TW_NO_CPU_TEMP),) + LOCAL_CFLAGS += -DTW_NO_CPU_TEMP=$(TW_NO_CPU_TEMP) +endif ifneq ($(TW_EXCLUDE_ENCRYPTED_BACKUPS), true) LOCAL_SHARED_LIBRARIES += libopenaes else diff --git a/data.cpp b/data.cpp index be851584e..0e46b3bdb 100644 --- a/data.cpp +++ b/data.cpp @@ -72,6 +72,7 @@ map DataManager::mValues; map DataManager::mConstValues; string DataManager::mBackingFile; int DataManager::mInitialized = 0; + #ifndef TW_NO_SCREEN_TIMEOUT extern blanktimer blankTimer; #endif @@ -353,7 +354,6 @@ int DataManager::GetValue(const string varName, string& value) // Handle magic values if (GetMagicValue(localStr, value) == 0) return 0; - map::iterator constPos; constPos = mConstValues.find(localStr); if (constPos != mConstValues.end()) @@ -660,6 +660,23 @@ void DataManager::SetDefaultValues() #else mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0")); #endif +#ifdef TW_NO_CPU_TEMP + printf("TW_NO_CPU_TEMP := true\n"); + mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); +#else + string cpu_temp_file; +#ifdef TW_CUSTOM_CPU_TEMP_PATH + cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); +#else + cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; +#endif + if (TWFunc::Path_Exists(cpu_temp_file)) { + mConstValues.insert(make_pair("tw_no_cpu_temp", "0")); + } else { + LOGINFO("CPU temperature file '%s' not found, disabling CPU temp.\n", cpu_temp_file.c_str()); + mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); + } +#endif #ifdef TW_CUSTOM_POWER_BUTTON printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON)); mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON))); @@ -862,13 +879,41 @@ int DataManager::GetMagicValue(const string varName, string& value) value = tmp; return 0; } + else if (varName == "tw_cpu_temp") + { + string cpu_temp_file; + static unsigned long convert_temp = 0; + static time_t cpuSecCheck = 0; + int divisor = 0; + struct timeval curTime; + string results; + + gettimeofday(&curTime, NULL); + if (curTime.tv_sec > cpuSecCheck) + { +#ifdef TW_CUSTOM_CPU_TEMP_PATH + cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); + if (TWFunc::read_file(cpu_temp_file, results) != 0) + return -1; +#else + cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; + if (TWFunc::read_file(cpu_temp_file, results) != 0) + return -1; +#endif + convert_temp = strtoul(results.c_str(), NULL, 0) / 1000; + if (convert_temp <= 0) + convert_temp = strtoul(results.c_str(), NULL, 0); + cpuSecCheck = curTime.tv_sec + 5; + } + value = TWFunc::to_string(convert_temp); + return 0; + } else if (varName == "tw_battery") { char tmp[16]; static char charging = ' '; static int lastVal = -1; static time_t nextSecCheck = 0; - struct timeval curTime; gettimeofday(&curTime, NULL); if (curTime.tv_sec > nextSecCheck) diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml index 4d6f3178f..7b7ad8ce7 100644 --- a/gui/devices/1024x600/res/ui.xml +++ b/gui/devices/1024x600/res/ui.xml @@ -231,13 +231,13 @@ - + Team Win Recovery Project v%tw_version% - + @@ -248,14 +248,23 @@ - + %tw_time% + + + + + + + CPU: %tw_cpu_temp% C + + - + SIMULATING ACTIONS diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml index 29f169089..b5ce1b40b 100644 --- a/gui/devices/1024x768/res/ui.xml +++ b/gui/devices/1024x768/res/ui.xml @@ -231,13 +231,13 @@ - + Team Win Recovery Project v%tw_version% - + @@ -248,14 +248,23 @@ - + %tw_time% + + + + + + + CPU: %tw_cpu_temp% C + + - + SIMULATING ACTIONS diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml index 95c48a513..1367015bf 100644 --- a/gui/devices/1080x1920/res/ui.xml +++ b/gui/devices/1080x1920/res/ui.xml @@ -246,6 +246,15 @@ Battery: %tw_battery% + + + + + + + CPU: %tw_cpu_temp% C + + diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml index 428880d76..77af05ba7 100644 --- a/gui/devices/1200x1920/res/ui.xml +++ b/gui/devices/1200x1920/res/ui.xml @@ -249,6 +249,15 @@ Battery: %tw_battery% + + + + + + + CPU: %tw_cpu_temp% C + + diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml index 6f6c2bd36..716dadc1e 100644 --- a/gui/devices/1280x800/res/ui.xml +++ b/gui/devices/1280x800/res/ui.xml @@ -252,6 +252,15 @@ %tw_time% + + + + + + + CPU: %tw_cpu_temp% C + + diff --git a/gui/devices/1440x2560/res/ui.xml b/gui/devices/1440x2560/res/ui.xml index fe55dfdbf..79f12cfce 100644 --- a/gui/devices/1440x2560/res/ui.xml +++ b/gui/devices/1440x2560/res/ui.xml @@ -9,9 +9,9 @@ preview.jpg - - - + + + @@ -246,6 +246,15 @@ Battery: %tw_battery% + + + + + + + CPU: %tw_cpu_temp% C + + diff --git a/gui/devices/1600x2560/res/ui.xml b/gui/devices/1600x2560/res/ui.xml index 8561b2ddf..09c740866 100644 --- a/gui/devices/1600x2560/res/ui.xml +++ b/gui/devices/1600x2560/res/ui.xml @@ -249,6 +249,15 @@ Battery: %tw_battery% + + + + + + + CPU: %tw_cpu_temp% C + + diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml index 3e8c9f13f..e36d0ae76 100644 --- a/gui/devices/1920x1200/res/ui.xml +++ b/gui/devices/1920x1200/res/ui.xml @@ -252,10 +252,19 @@ %tw_time% + + + + + + + CPU: %tw_cpu_temp% C + + - + SIMULATING ACTIONS diff --git a/gui/devices/240x240/res/ui.xml b/gui/devices/240x240/res/ui.xml index 294e5951b..d157f85c1 100644 --- a/gui/devices/240x240/res/ui.xml +++ b/gui/devices/240x240/res/ui.xml @@ -211,7 +211,7 @@ - + TWRP v%tw_version% @@ -224,7 +224,7 @@ - + %tw_time% @@ -238,6 +238,15 @@ %tw_battery% + + + + + + + + %tw_cpu_temp% C +