Skip to content

Commit

Permalink
Add Ambient temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Jun 27, 2023
1 parent 60d4bbf commit 57aadd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Outputs current CPU temperature for OSX.

## Usage
## Usage

### Compiling

Expand Down Expand Up @@ -37,20 +37,26 @@ clib install lavoiesl/osx-cpu-temp

### Options

* `-C` Output temperature in Celsius (default).
* `-F` Output temperature in Fahrenheit.
* `-f` Output fan speed.
* Output
* `-c` Display CPU temperature (Default).
* `-g` Display GPU temperature.
* `-a` Display ambient temperature.
* `-f` Display fan speeds.
* Format
* `-C` Display temperatures in degrees Celsius (Default).
* `-F` Display temperatures in degrees Fahrenheit.
* `-T` Do not display the units for temperatures.

## Maintainer
## Maintainer

Sébastien Lavoie <[email protected]>

### Source
### Source

Apple System Management Control (SMC) Tool
Apple System Management Control (SMC) Tool
Copyright (C) 2006

### Inspiration
### Inspiration

* https://www.eidac.de/smcfancontrol/
* https://github.com/hholtmann/smcFanControl/tree/master/smc-command
14 changes: 11 additions & 3 deletions smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ int main(int argc, char* argv[])
bool cpu = false;
bool fan = false;
bool gpu = false;
bool amb = false;

int c;
while ((c = getopt(argc, argv, "CFTcfgh?")) != -1) {
while ((c = getopt(argc, argv, "CFTcfgah?")) != -1) {
switch (c) {
case 'F':
case 'C':
Expand All @@ -319,6 +320,9 @@ int main(int argc, char* argv[])
case 'g':
gpu = true;
break;
case 'a':
amb = true;
break;
case 'h':
case '?':
printf("usage: osx-cpu-temp <options>\n");
Expand All @@ -328,18 +332,19 @@ int main(int argc, char* argv[])
printf(" -T Do not display the units for temperatures.\n");
printf(" -c Display CPU temperature (Default).\n");
printf(" -g Display GPU temperature.\n");
printf(" -a Display ambient temperature.\n");
printf(" -f Display fan speeds.\n");
printf(" -h Display this help.\n");
printf("\nIf more than one of -c, -f, or -g are specified, titles will be added\n");
return -1;
}
}

if (!fan && !gpu) {
if (!fan && !gpu && !amb) {
cpu = true;
}

bool show_title = fan + gpu + cpu > 1;
bool show_title = fan + gpu + cpu + amb > 1;

SMCOpen();

Expand All @@ -349,6 +354,9 @@ int main(int argc, char* argv[])
if (gpu) {
readAndPrintTemperature("GPU: ", show_title, SMC_KEY_GPU_TEMP, scale, show_scale);
}
if (amb) {
readAndPrintTemperature("Ambient: ", show_title, SMC_KEY_AMBIENT_TEMP, scale, show_scale);
}
if (fan) {
readAndPrintFanRPMs();
}
Expand Down
3 changes: 2 additions & 1 deletion smc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Apple System Management Control (SMC) Tool
* Copyright (C) 2006 devnull
* Copyright (C) 2006 devnull
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -40,6 +40,7 @@
// key values
#define SMC_KEY_CPU_TEMP "TC0P"
#define SMC_KEY_GPU_TEMP "TG0P"
#define SMC_KEY_AMBIENT_TEMP "TA0V"
#define SMC_KEY_FAN0_RPM_CUR "F0Ac"

typedef struct {
Expand Down

0 comments on commit 57aadd7

Please sign in to comment.