Skip to content

Commit

Permalink
Add option to suppress display of units for temperatures
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Jun 27, 2023
1 parent 180cff1 commit 60d4bbf
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,19 @@ double readTemperature(char* key, char scale)
return temperature;
}

void readAndPrintTemperature(char* title, char* key, char scale)
void readAndPrintTemperature(char* title, bool show_title, char* key, char scale, bool show_scale)
{
double temperature = readTemperature(key, scale);
printf("%s%0.1f °%c\n", title, temperature, scale);
}

void readAndPrintCpuTemp(bool show_title, char scale)
{
char* title = "";
if (show_title) {
title = "CPU: ";
if (!show_title) {
title = "";
}
readAndPrintTemperature(title, SMC_KEY_CPU_TEMP, scale);
}

void readAndPrintGpuTemp(bool show_title, char scale)
{
char* title = "";
if (show_title) {
title = "GPU: ";
double temperature = readTemperature(key, scale);

if (show_scale) {
printf("%s%0.1f °%c\n", title, temperature, scale);
} else {
printf("%s%0.1f\n", title, temperature);
}
readAndPrintTemperature(title, SMC_KEY_GPU_TEMP, scale);
}

float SMCGetFanRPM(char* key)
Expand Down Expand Up @@ -304,17 +295,21 @@ void readAndPrintFanRPMs(void)
int main(int argc, char* argv[])
{
char scale = 'C';
bool show_scale = true;
bool cpu = false;
bool fan = false;
bool gpu = false;

int c;
while ((c = getopt(argc, argv, "CFcfgh?")) != -1) {
while ((c = getopt(argc, argv, "CFTcfgh?")) != -1) {
switch (c) {
case 'F':
case 'C':
scale = c;
break;
case 'T':
show_scale = false;
break;
case 'c':
cpu = true;
break;
Expand All @@ -330,6 +325,7 @@ int main(int argc, char* argv[])
printf("Options:\n");
printf(" -F Display temperatures in degrees Fahrenheit.\n");
printf(" -C Display temperatures in degrees Celsius (Default).\n");
printf(" -T Do not display the units for temperatures.\n");
printf(" -c Display CPU temperature (Default).\n");
printf(" -g Display GPU temperature.\n");
printf(" -f Display fan speeds.\n");
Expand All @@ -348,10 +344,10 @@ int main(int argc, char* argv[])
SMCOpen();

if (cpu) {
readAndPrintCpuTemp(show_title, scale);
readAndPrintTemperature("CPU: ", show_title, SMC_KEY_CPU_TEMP, scale, show_scale);
}
if (gpu) {
readAndPrintGpuTemp(show_title, scale);
readAndPrintTemperature("GPU: ", show_title, SMC_KEY_GPU_TEMP, scale, show_scale);
}
if (fan) {
readAndPrintFanRPMs();
Expand Down

0 comments on commit 60d4bbf

Please sign in to comment.