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
This commit is contained in:
Jenkins
2014-10-14 15:08:11 +02:00
committed by Dees Troy
parent 76ee903d84
commit 1710bf2547
23 changed files with 255 additions and 23 deletions
+9
View File
@@ -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
+47 -2
View File
@@ -72,6 +72,7 @@ map<string, DataManager::TStrIntPair> DataManager::mValues;
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 @@ int DataManager::GetValue(const string varName, string& value)
// 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 @@ 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)
+13 -4
View File
@@ -231,13 +231,13 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="5" />
<placement x="200" y="5" />
<text>Team Win Recovery Project v%tw_version%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="30" />
<placement x="200" y="30" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -248,14 +248,23 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="450" y="30" />
<placement x="400" y="30" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="700" y="30" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="550" y="30" />
<placement x="475" y="30" />
<text>SIMULATING ACTIONS</text>
</object>
+13 -4
View File
@@ -231,13 +231,13 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="5" />
<placement x="200" y="5" />
<text>Team Win Recovery Project v%tw_version%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="30" />
<placement x="200" y="30" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -248,14 +248,23 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="450" y="30" />
<placement x="400" y="30" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="700" y="30" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="550" y="30" />
<placement x="475" y="30" />
<text>SIMULATING ACTIONS</text>
</object>
+9
View File
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="760" y="114" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
+9
View File
@@ -249,6 +249,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="730" y="114" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
+9
View File
@@ -252,6 +252,15 @@
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="850" y="30" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
+12 -3
View File
@@ -9,9 +9,9 @@
<preview>preview.jpg</preview>
</details>
<include>
<xmlfile name="portrait.xml" />
</include>
<include>
<xmlfile name="portrait.xml" />
</include>
<resources>
<resource name="font" type="font" filename="RobotoCondensed-Regular.ttf" size="50" fallback="Roboto-Condensed-50" />
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="839" y="132" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
+9
View File
@@ -249,6 +249,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="739" y="132" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
+10 -1
View File
@@ -252,10 +252,19 @@
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="1150" y="40" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="850" y="40" />
<placement x="750" y="40" />
<text>SIMULATING ACTIONS</text>
</object>
+11 -2
View File
@@ -211,7 +211,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="3" y="3" />
<placement x="1" y="3" />
<text>TWRP v%tw_version%</text>
</object>
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="100" y="3" />
<placement x="89" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="145" y="3" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>%tw_cpu_temp% C</text>
</object>
</template>
<template name="header">
+9
View File
@@ -252,6 +252,15 @@
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="1650" y="55" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
+10 -1
View File
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="165" y="3" />
<placement x="95" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="160" y="3" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
</template>
<template name="header">
+10 -1
View File
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="200" y="3" />
<placement x="110" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="190" y="3" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
</template>
<template name="header">
+10 -1
View File
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="165" y="39" />
<placement x="135" y="39" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="265" y="39" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>%tw_cpu_temp% C</text>
</object>
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
+10 -1
View File
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="70" />
<placement x="190" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="350" y="70" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
+10 -1
View File
@@ -231,7 +231,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="70" />
<placement x="190" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -240,6 +240,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="350" y="70" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
+10 -1
View File
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="250" y="70" />
<placement x="200" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="400" y="70" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
+9
View File
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="500" y="76" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
+9
View File
@@ -243,6 +243,15 @@
<text>Battery: %tw_battery%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="420" y="76" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
+10 -1
View File
@@ -248,10 +248,19 @@
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="450" y="37" />
<placement x="425" y="37" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
<placement x="500" y="37" />
<conditions>
<condition var1="tw_no_cpu_temp" var2="0" />
</conditions>
<text>CPU: %tw_cpu_temp% C</text>
</object>
<object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
+6
View File
@@ -1289,4 +1289,10 @@ void TWFunc::SetPerformanceMode(bool mode) {
usleep(500000);
}
std::string TWFunc::to_string(unsigned long value) {
std::ostringstream os;
os << value;
return os.str();
}
#endif // ndef BUILD_TWRPTAR_MAIN
+1
View File
@@ -86,6 +86,7 @@ public:
static bool Create_Dir_Recursive(const std::string& path, mode_t mode = 0755, uid_t uid = -1, gid_t gid = -1); // Create directory and it's parents, if they don't exist. mode, uid and gid are set to all _newly_ created folders. If whole path exists, do nothing.
static int Set_Brightness(std::string brightness_value); // Well, you can read, it does what it says, passing return int from TWFunc::Write_File ;)
static bool Toggle_MTP(bool enable); // Disables MTP if enable is false and re-enables MTP if enable is true and it was enabled the last time it was toggled off
static std::string to_string(unsigned long value); //convert ul to string
static void SetPerformanceMode(bool mode); // support recovery.perf.mode