Skip to content

Commit 78249bf

Browse files
committed
CPU: add new option --cpu-freq-ndigits
Fix #578
1 parent 4c9d9f6 commit 78249bf

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Features:
44
* Support opkg (Packages, Linux)
55
* Support GNOME Console terminal version and font detection (Terminal, Linux)
6+
* Add `--cpu-freq-ndigits` to set number of digits for CPU frequency (CPU)
67

78
Bugfixes:
89
* Fix possible crashes on Windows 7 (Disk, Windows)

doc/json_schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,13 @@
737737
"type": "boolean",
738738
"default": false
739739
},
740+
"freqNdigits": {
741+
"title": "Set the number of digits to keep after the decimal point when printing CPU frequency",
742+
"type": "integer",
743+
"minimum": 0,
744+
"maximum": 9,
745+
"default": 2
746+
},
740747
"key": {
741748
"$ref": "#/$defs/key"
742749
},

src/data/help.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ Module specific options:
138138
--display-precise-refresh-rate: <?value>:Set if decimal refresh rates should not be rounded into integers when printing. Default is true
139139
--sound-type: <value>: Set what type of sound devices should be printed. Should be either main, active or all. Default is main
140140
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
141-
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
142-
--gpu-temp <?value>: Detect and display GPU temperature if supported. Default is false
143-
--gpu-force-vulkan <?value>: Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false
141+
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
142+
--cpu-freq-ndigits <num>: Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2
143+
--gpu-temp <?value>: Detect and display GPU temperature if supported. Default is false
144+
--gpu-force-vulkan <?value>: Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false
144145
--gpu-hide-type <?value>: Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none
145-
--battery-temp <?value>: Detect and display Battery temperature if supported. Default is false
146+
--battery-temp <?value>: Detect and display Battery temperature if supported. Default is false
146147
--localip-show-ipv4 <?value>: Show IPv4 addresses in local ip module. Default is true
147148
--localip-show-ipv6 <?value>: Show IPv6 addresses in local ip module. Default is false
148149
--localip-show-mac <?value>: Show mac addresses in local ip module. Default is false

src/modules/cpu/cpu.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ffPrintCPU(FFCPUOptions* options)
4848
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);
4949

5050
if(cpu.frequencyMax > 0.0)
51-
ffStrbufAppendF(&str, " @ %.9g GHz", cpu.frequencyMax);
51+
ffStrbufAppendF(&str, " @ %.*f GHz", options->freqNdigits, cpu.frequencyMax);
5252

5353
if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET
5454
{
@@ -82,6 +82,7 @@ void ffInitCPUOptions(FFCPUOptions* options)
8282
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJson, ffPrintCPUHelpFormat);
8383
ffOptionInitModuleArg(&options->moduleArgs);
8484
options->temp = false;
85+
options->freqNdigits = 2;
8586
}
8687

8788
bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value)
@@ -97,6 +98,12 @@ bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char
9798
return true;
9899
}
99100

101+
if (ffStrEqualsIgnCase(subKey, "freq-ndigits"))
102+
{
103+
options->freqNdigits = (uint8_t) ffOptionParseUInt32(key, value);
104+
return true;
105+
}
106+
100107
return false;
101108
}
102109

@@ -124,6 +131,12 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
124131
continue;
125132
}
126133

134+
if (ffStrEqualsIgnCase(key, "freqNdigits"))
135+
{
136+
options->freqNdigits = (uint8_t) yyjson_get_uint(val);
137+
continue;
138+
}
139+
127140
ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
128141
}
129142
}

src/modules/cpu/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ typedef struct FFCPUOptions
1010
FFModuleArgs moduleArgs;
1111

1212
bool temp;
13+
uint8_t freqNdigits;
1314
} FFCPUOptions;

0 commit comments

Comments
 (0)