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 --- data.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'data.cpp') 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) -- cgit v1.2.3