-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcputemp.c
53 lines (47 loc) · 1.01 KB
/
cputemp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "cputemp.h"
#define TEMP "/sys/class/thermal/thermal_zone0/temp"
static float currtemp(int core)
{
float tc = 0.0;
uint32_t val = 0;
FILE *fd = fopen(TEMP, "r");
if (!fd)
fd = fopen(TEMP, "r");
if (!fd)
return tc;
if (fscanf(fd, "%d", &val))
tc = val / 1000.0;
fclose(fd);
return tc;
}
float cpu_temp(int core)
{
return currtemp(core);
}
static char const span[] = "\
"PROG": "PROG_VER" by " OWNER"\n\
created on "DATE"\n\
\n\
"BGREEN" " " "N" Normal [0-38]\n\
"BYELLOW" " " "N" High [38-50]\n\
"BRED" " " "N" Critical [50+]\n\
\n\
";
int main()
{
float temp = cpu_temp(0);
float tc = 0.0;
if (temp < 38) {
printf(span);
printf("Current Temperature:" LGREEN " %.2f°C\n" N, temp);
} else if (temp < 50) {
printf(span);
printf("Current Temperature:" LYELLOW " %.2f°C\n" N, temp);
} else {
if (temp < 100) {
printf(span);
printf("Current Temperature:" LRED " %.2f°C\n" N, temp);
}
}
exit(0);
}