Skip to content

Commit

Permalink
Merge pull request #6 from lavoiesl/fahr
Browse files Browse the repository at this point in the history
Added option for Fahrenheit output.
  • Loading branch information
lavoiesl committed Sep 16, 2015
2 parents e694716 + 273cb59 commit fb997ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OSX CPU Temp

Outputs current CPU temperature in °C for OSX
Outputs current CPU temperature for OSX.

## Usage

Expand Down Expand Up @@ -28,6 +28,11 @@ osx-cpu-temp
61.8°C
```

### Options

* `-C` Output temperature in Celsius (default).
* `-F` Output temperature in Fahrenheit.

## Maintainer

Sébastien Lavoie <[email protected]>
Expand Down
24 changes: 23 additions & 1 deletion smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,33 @@ double SMCGetTemperature(char *key)
return 0.0;
}

double convertToFahrenheit(double celsius) {
return (celsius * (9.0 / 5.0)) + 32.0;
}

int main(int argc, char *argv[])
{
char scale = 'C';

int c;
while ((c = getopt(argc, argv, "CF")) != -1) {
switch (c) {
case 'F':
case 'C':
scale = c;
break;
}
}

SMCOpen();
printf("%0.1f°C\n", SMCGetTemperature(SMC_KEY_CPU_TEMP));
double temperature = SMCGetTemperature(SMC_KEY_CPU_TEMP);
SMCClose();

if (scale == 'F') {
temperature = convertToFahrenheit(temperature);
}

printf("%0.1f°%c\n", temperature, scale);

return 0;
}

0 comments on commit fb997ab

Please sign in to comment.