Skip to content

Commit acdbf69

Browse files
Merge pull request #177 from x-zvf/feature-cpu-temp
Add CPU package temperature to CPU module.
2 parents 716522e + ea53833 commit acdbf69

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

DEVELOPMENT.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Here i just add things that are easy to forget.
1212
- `libffprint`: contains the printing functions, logos, format etc
1313
- `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time
1414
- [ ] Better OS output for all possible combinations of /etc/os-release variables.
15-
- [ ] Expose temperatures to CPU format string
1615
- [ ] Expose temperatures to GPU format string
1716
- [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0}
1817
- [ ] Make LocalIP module more configurable

src/fastfetch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,15 @@ static inline void printCommandHelp(const char* command)
236236
}
237237
else if(strcasecmp(command, "cpu-format") == 0)
238238
{
239-
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {14}GHz", 14,
239+
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz", 15,
240240
"CPU name",
241241
"Prettified CPU name",
242242
"CPU Vendor name (Vendor ID)",
243243
"CPU logical core count online",
244244
"CPU logical core count configured",
245245
"CPU physical core count",
246246
"Always set core count",
247+
"CPU package temperature",
247248
"frequency bios limit",
248249
"frequency scaling max",
249250
"frequency scaling min",

src/modules/cpu.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
#include "fastfetch.h"
22

33
#include <string.h>
4+
#include <errno.h>
45

56
#define FF_CPU_MODULE_NAME "CPU"
6-
#define FF_CPU_NUM_FORMAT_ARGS 14
7+
#define FF_CPU_NUM_FORMAT_ARGS 15
78

8-
static double parseHz(FFstrbuf* content)
9+
10+
static long parseLong(const FFstrbuf* content)
911
{
10-
if(content->length == 0)
11-
return 0;
12+
long value;
13+
if(sscanf(content->chars, "%li", &value) != 1)
14+
return -1;
15+
return value;
1216

17+
}
18+
19+
static double parseHz(const FFstrbuf* content)
20+
{
1321
double herz;
1422
if(sscanf(content->chars, "%lf", &herz) != 1)
1523
return 0;
@@ -104,6 +112,19 @@ void ffPrintCPU(FFinstance* instance)
104112
if(numProcs <= 1)
105113
numProcs = physicalCores;
106114

115+
116+
const FFTempsResult *temps = ffDetectTemps(&instance);
117+
double cpuTemp = 0.0/0.0;
118+
for(uint32_t i = 0; i< temps->values.length; i++)
119+
{
120+
FFTempValue *v = ffListGet(&temps->values, i);
121+
if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length
122+
&& ffStrbufCompS(&v->name, "k10temp") != 0
123+
&& ffStrbufCompS(&v->name, "coretemp") != 0)
124+
break;
125+
cpuTemp = (double) parseLong(&v->value) / 1000.0f;
126+
}
127+
107128
double ghz = biosLimit;
108129
if(ghz == 0)
109130
ghz = scalingMaxFreq;
@@ -172,6 +193,7 @@ void ffPrintCPU(FFinstance* instance)
172193
{FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable},
173194
{FF_FORMAT_ARG_TYPE_INT, &physicalCores},
174195
{FF_FORMAT_ARG_TYPE_INT, &numProcs},
196+
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuTemp},
175197
{FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit},
176198
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq},
177199
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq},

0 commit comments

Comments
 (0)