Display battery temperature near battery percent
Closed this issue · 0 comments
iusmac commented
Goal: 88% | 28 °С
<string name="cpu_temp">CPU: %tw_cpu_temp% °C</string>
Where:
gui/battery.cpp:140
mBatteryPercentStr = mBatteryIcon == 0 ? DataManager::GetStrValue("tw_battery_charge") :
DataManager::GetStrValue("tw_battery") + "%" ;
Get battery temp:
rolex:/# cat /sys/class/power_supply/battery/temp
293 # 293 / 10 = 29.3 °С
Try to bind to 'Show CPU temperature'
if (varName == "tw_cpu_temp")
{
int tw_no_cpu_temp;
GetValue("tw_no_cpu_temp", tw_no_cpu_temp);
if (tw_no_cpu_temp == 1)
return -1;
string cpu_temp_file;
static unsigned long convert_temp = 0;
static time_t cpuSecCheck = 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);
if (convert_temp >= 150)
convert_temp = strtoul(results.c_str(), NULL, 0) / 10;
cpuSecCheck = curTime.tv_sec + 5;
}
value = TWFunc::to_string(convert_temp);
return 0;
}