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
diff --git a/data.cpp b/data.cpp
index be85158..0e46b3b 100644
--- a/data.cpp
+++ b/data.cpp
@@ -72,6 +72,7 @@
 map<string, string>                     DataManager::mConstValues;
 string                                  DataManager::mBackingFile;
 int                                     DataManager::mInitialized = 0;
+
 #ifndef TW_NO_SCREEN_TIMEOUT
 extern blanktimer blankTimer;
 #endif
@@ -353,7 +354,6 @@
 	// Handle magic values
 	if (GetMagicValue(localStr, value) == 0)
 		return 0;
-
 	map<string, string>::iterator constPos;
 	constPos = mConstValues.find(localStr);
 	if (constPos != mConstValues.end())
@@ -660,6 +660,23 @@
 #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 @@
 		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)