Skip to content

Commit

Permalink
Changed -f option to -F, added -C for Celsius, and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Sep 16, 2015
1 parent 7e80ce9 commit 273cb59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 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 <sebastien@lavoie.sl>
Expand Down
16 changes: 8 additions & 8 deletions smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ double convertToFahrenheit(double celsius) {

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

int c;
while ((c = getopt(argc, argv, "f")) != -1) {
switch(c) {
case 'f':
fahrenheit = true;
while ((c = getopt(argc, argv, "CF")) != -1) {
switch (c) {
case 'F':
case 'C':
scale = c;
break;
}
}
Expand All @@ -184,10 +186,8 @@ int main(int argc, char *argv[])
double temperature = SMCGetTemperature(SMC_KEY_CPU_TEMP);
SMCClose();

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

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

0 comments on commit 273cb59

Please sign in to comment.