forked from mklein-de/htop-osx
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/stormerider/htop-osx
- Loading branch information
Showing
19 changed files
with
823 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
htop | ||
(C) 2004-2006 Hisham H. Muhammad | ||
(c) 2013 Morgan Blackthorne | ||
Released under the GNU GPL, see the COPYING file | ||
in the source distribution for its full text. | ||
*/ | ||
|
||
#include "CPUTemperatureMeter.h" | ||
#include "Meter.h" | ||
|
||
#include <time.h> | ||
|
||
#include "debug.h" | ||
#include "smc.h" | ||
|
||
#define KELVIN 0 | ||
#define CELSIUS 1 | ||
#define FAHRENHEIT 2 | ||
|
||
int CPUTemperatureMeter_attributes[] = { | ||
CPU_TEMP | ||
}; | ||
|
||
static void CPUTemperatureMeter_setValues(Meter* this, char* buffer, int size) { | ||
double temp[5]; | ||
|
||
temp[0] = SMCGetTemperature("TCAH"); // Some Mac Pros have two sensors, since they are SMP | ||
temp[1] = SMCGetTemperature("TCBH"); // Second CPU sensor for Mac Pro | ||
temp[2] = SMCGetTemperature("TC0D"); // Older MBPs | ||
temp[3] = SMCGetTemperature("TC0F"); // Newer MBPs | ||
temp[4] = SMCGetTemperature("TC0H"); // Some iMacs | ||
|
||
if (temp[0] != 0 && temp[1] != 0) { | ||
this->values[0] = temp[0]; | ||
this->values[1] = temp[1]; | ||
} else if (temp[2] != 0) { | ||
this->values[0] = temp[2]; | ||
this->values[1] = 0; | ||
} else if (temp[3] != 0) { | ||
this->values[0] = temp[3]; | ||
this->values[1] = 0; | ||
} else if (temp[4] != 0) { | ||
this->values[0] = temp[4]; | ||
this->values[1] = 0; | ||
} else { | ||
// Couldn't retrieve sensor information... | ||
this->values[0] = 0; | ||
this->values[1] = 0; | ||
} | ||
} | ||
|
||
static const char * scale_markers = "KCF"; | ||
|
||
static const double scales[][2] = { | ||
{1.0, 273.15}, /* K */ | ||
{1.0, 0.0}, /* C */ | ||
{1.8, 32.0} /* F */ | ||
}; | ||
|
||
double celcius_to_scale(double temp, int scale) { | ||
return temp * scales[scale][0] + scales[scale][1]; | ||
} | ||
|
||
static void CPUTemperatureMeter_display(Object* cast, RichString* out) { | ||
Meter* this = (Meter*)cast; | ||
char buffer[20]; | ||
int scale = CELSIUS; /* change this to your favourite scale */ | ||
double hot_threshold = 70.0; /* *C */ | ||
double warm_threshold = 59.0; /* *C */ | ||
double raw_temp, converted_temp; | ||
double raw_temp_2, converted_temp_2; | ||
|
||
RichString_init(out); | ||
|
||
raw_temp = this->values[0]; | ||
raw_temp_2 = this->values[1]; | ||
|
||
if (raw_temp > 0 && raw_temp < 900) { | ||
converted_temp = celcius_to_scale(raw_temp, scale); | ||
snprintf(buffer, 20, "%.1f %c", converted_temp, scale_markers[scale]); | ||
if (raw_temp > hot_threshold) { | ||
RichString_append(out, CRT_colors[CPU_TEMP_HOT], buffer); | ||
} else if (raw_temp > warm_threshold) { | ||
RichString_append(out, CRT_colors[CPU_TEMP_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[CPU_TEMP_NORMAL], buffer); | ||
} | ||
} else { | ||
snprintf(buffer, 20, "-.- %c", scale_markers[scale]); | ||
RichString_append(out, CRT_colors[CPU_TEMP_NORMAL], buffer); | ||
} | ||
|
||
if (raw_temp_2 > 0 && raw_temp_2 < 900) { | ||
converted_temp_2 = celcius_to_scale(raw_temp_2, scale); | ||
snprintf(buffer, 20, ", %.1f %c", converted_temp_2, scale_markers[scale]); | ||
if (raw_temp_2 > hot_threshold) { | ||
RichString_append(out, CRT_colors[CPU_TEMP_HOT], buffer); | ||
} else if (raw_temp_2 > warm_threshold) { | ||
RichString_append(out, CRT_colors[CPU_TEMP_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[CPU_TEMP_NORMAL], buffer); | ||
} | ||
} | ||
} | ||
|
||
MeterType CPUTemperatureMeter = { | ||
.setValues = CPUTemperatureMeter_setValues, | ||
.display = CPUTemperatureMeter_display, | ||
.mode = TEXT_METERMODE, | ||
.total = 100.0, | ||
.items = 2, | ||
.attributes = CPUTemperatureMeter_attributes, | ||
.name = "CPUTemp", | ||
.uiName = "CPU Temp", | ||
.caption = "CPU Temp: ", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Do not edit this file. It was automatically generated. */ | ||
|
||
#ifndef HEADER_CPUTemperatureMeter | ||
#define HEADER_CPUTemperatureMeter | ||
/* | ||
htop | ||
(C) 2004-2006 Hisham H. Muhammad | ||
Released under the GNU GPL, see the COPYING file | ||
in the source distribution for its full text. | ||
*/ | ||
|
||
#include "Meter.h" | ||
|
||
#include <time.h> | ||
|
||
#include "debug.h" | ||
|
||
extern int CPUTemperatureMeter_attributes[]; | ||
|
||
extern MeterType CPUTemperatureMeter; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
htop | ||
(c) 2013 Morgan Blackthorne | ||
Released under the GNU GPL, see the COPYING file | ||
in the source distribution for its full text. | ||
*/ | ||
|
||
#include "FanRPMMeter.h" | ||
#include "Meter.h" | ||
|
||
#include <time.h> | ||
|
||
#include "debug.h" | ||
#include "smc.h" | ||
|
||
int FanRPMMeter_attributes[] = { | ||
FAN_RPM | ||
}; | ||
|
||
static void FanRPMMeter_setValues(Meter* this, char* buffer, int size) { | ||
float rpm[8]; | ||
|
||
rpm[0] = SMCGetFanRPM("F0Ac"); | ||
rpm[1] = SMCGetFanRPM("F0Mx"); | ||
rpm[2] = SMCGetFanRPM("F1Ac"); | ||
rpm[3] = SMCGetFanRPM("F1Mx"); | ||
rpm[4] = SMCGetFanRPM("F2Ac"); | ||
rpm[5] = SMCGetFanRPM("F2Mx"); | ||
rpm[6] = SMCGetFanRPM("F3Ac"); | ||
rpm[7] = SMCGetFanRPM("F3Mx"); | ||
|
||
//printf("0 = %.0f, 2 = %.0f, 4 = %.0f\n", rpm[0], rpm[2], rpm[4]); | ||
//printf("1 = %.0f, 3 = %.0f, 5 = %.0f\n", rpm[1], rpm[3], rpm[5]); | ||
|
||
this->values[0] = rpm[0]; | ||
this->values[1] = rpm[1]; | ||
this->values[2] = rpm[2]; | ||
this->values[3] = rpm[3]; | ||
this->values[4] = rpm[4]; | ||
this->values[5] = rpm[5]; | ||
this->values[6] = rpm[6]; | ||
this->values[7] = rpm[7]; | ||
} | ||
|
||
static void FanRPMMeter_display(Object* cast, RichString* out) { | ||
Meter* this = (Meter*)cast; | ||
char buffer[20]; | ||
double hot_threshold = 4000.0; /* RPM */ | ||
double warm_threshold = 3000.0; /* RPM */ | ||
double cold_threshold = 1000.0; /* RPM */ | ||
double raw_rpm_1, raw_rpm_2, raw_rpm_3, raw_rpm_4; | ||
double max_rpm_1, max_rpm_2, max_rpm_3, max_rpm_4; | ||
|
||
RichString_init(out); | ||
|
||
raw_rpm_1 = this->values[0]; max_rpm_1 = this->values[1]; | ||
raw_rpm_2 = this->values[2]; max_rpm_2 = this->values[3]; | ||
raw_rpm_3 = this->values[4]; max_rpm_3 = this->values[5]; | ||
raw_rpm_4 = this->values[6]; max_rpm_4 = this->values[7]; | ||
|
||
if (raw_rpm_1 > 0) { | ||
snprintf(buffer, 20, "%.0f RPM", raw_rpm_1); | ||
if (raw_rpm_1 > hot_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_HOT], buffer); | ||
} else if (raw_rpm_1 > warm_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[FAN_RPM_NORMAL], buffer); | ||
} | ||
} else { | ||
snprintf(buffer, 20, "-.- RPM"); | ||
RichString_append(out, CRT_colors[FAN_RPM_NORMAL], buffer); | ||
} | ||
|
||
if (raw_rpm_2 > 0) { | ||
snprintf(buffer, 20, ", %.0f RPM", raw_rpm_2); | ||
if (raw_rpm_2 > hot_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_HOT], buffer); | ||
} else if (raw_rpm_2 > warm_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[FAN_RPM_NORMAL], buffer); | ||
} | ||
} | ||
|
||
if (raw_rpm_3 > 0) { | ||
snprintf(buffer, 20, ", %.0f RPM", raw_rpm_3); | ||
if (raw_rpm_3 > hot_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_HOT], buffer); | ||
} else if (raw_rpm_3 > warm_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[FAN_RPM_NORMAL], buffer); | ||
} | ||
} | ||
|
||
if (raw_rpm_4 > 0) { | ||
snprintf(buffer, 20, ", %.0f RPM", raw_rpm_4); | ||
if (raw_rpm_4 > hot_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_HOT], buffer); | ||
} else if (raw_rpm_4 > warm_threshold) { | ||
RichString_append(out, CRT_colors[FAN_RPM_WARM], buffer); | ||
} else { | ||
RichString_append(out, CRT_colors[FAN_RPM_NORMAL], buffer); | ||
} | ||
} | ||
} | ||
|
||
MeterType FanRPMMeter = { | ||
.setValues = FanRPMMeter_setValues, | ||
.display = FanRPMMeter_display, | ||
.mode = TEXT_METERMODE, | ||
.total = 100.0, | ||
.items = 8, | ||
.attributes = FanRPMMeter_attributes, | ||
.name = "FanRPM", | ||
.uiName = "Fan RPM", | ||
.caption = "Fan RPM: ", | ||
}; |
Oops, something went wrong.