2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-30 13:57:41 +00:00

Display stuff as Fahrenheits; patch of Kelsey Hudson

<khudson@rohan.sdsu.edu >


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@928 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard 2000-11-13 18:31:48 +00:00
parent 62ebc84b6f
commit 4fe4b3619c
3 changed files with 110 additions and 61 deletions

View File

@ -28,6 +28,10 @@
static char *spacestr(int n);
static void print_label(const char *label, int space);
static void free_the_label(char **label);
static void print_temp_info( float, float, float );
static inline float deg_ctof( float );
extern int fahrenheit;
char *spacestr(int n)
{
@ -39,6 +43,38 @@ char *spacestr(int n)
return buf;
}
inline float deg_ctof( float cel )
{
return ( cel * ( 9.0F / 5.0F ) + 32.0F );
}
void print_temp_info( float cur, float over, float hyst )
{
char degv[5];
float n_cur,
n_over,
n_hyst;
if ( fahrenheit )
{
sprintf( degv, "%cF", 176 );
n_cur = deg_ctof( cur );
n_over = deg_ctof( over );
n_hyst = deg_ctof( hyst );
}
else
{
sprintf( degv, "%cC", 176 );
n_cur = cur;
n_over = over;
n_hyst = hyst;
}
printf( "%+3.0f%s (limit = %+3.0f%s, hysteresis = %+3.0f%s)",
n_cur, degv, n_over, degv, n_hyst, degv );
}
void print_label(const char *label, int space)
{
int len=strlen(label)+1;
@ -81,8 +117,8 @@ void print_lm75(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_LM75_TEMP_OVER,&over)) {
if (valid) {
print_label(label,10);
printf("%6.1f C (limit: %6.1f C, hysteresis: %6.1f C)\n",
cur,over,hyst);
print_temp_info( cur, over, hyst );
printf( "\n" );
}
} else
printf("ERROR: Can't get temperature data!\n");
@ -108,8 +144,7 @@ void print_adm1021(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_ADM1021_TEMP_OVER,&over)) {
if (valid) {
print_label(label,10);
printf("%4.0f C (limit: %4.0f C, hysteresis: %4.0f C) ",
cur,over,hyst);
print_temp_info( cur, over, hyst );
if (alarms & (ADM1021_ALARM_TEMP_HIGH | ADM1021_ALARM_TEMP_LOW)) {
printf("ALARM (");
i = 0;
@ -134,8 +169,7 @@ void print_adm1021(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_ADM1021_REMOTE_TEMP_OVER,&over)) {
if (valid) {
print_label(label,10);
printf("%4.0f C (limit: %4.0f C, hysteresis: %4.0f C) ",
cur,over,hyst);
print_temp_info( cur, over, hyst );
if (alarms & (ADM1021_ALARM_RTEMP_HIGH | ADM1021_ALARM_RTEMP_LOW |
ADM1021_ALARM_RTEMP_NA)) {
printf("ALARM (");
@ -289,8 +323,8 @@ void print_adm9240(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_ADM9240_TEMP_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&ADM9240_ALARM_TEMP?"ALARM":"");
print_temp_info( cur, min, max );
printf( " %s\n", alarms & ADM9240_ALARM_TEMP ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP data!\n");
@ -408,8 +442,8 @@ void print_sis5595(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_SIS5595_TEMP_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&SIS5595_ALARM_TEMP?"ALARM":"");
print_temp_info( cur, min, max );
printf( " %s\n", alarms & SIS5595_ALARM_TEMP ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP data!\n");
@ -530,8 +564,8 @@ void print_via686a(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_VIA686A_TEMP_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.1f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&VIA686A_ALARM_TEMP?"ALARM":"");
print_temp_info( cur, min, max );
printf(" %s\n", alarms & VIA686A_ALARM_TEMP ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP data!\n");
@ -542,8 +576,8 @@ void print_via686a(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_VIA686A_TEMP2_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.1f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&VIA686A_ALARM_TEMP2?"ALARM":"");
print_temp_info( cur, min, max );
printf(" %s\n", alarms & VIA686A_ALARM_TEMP2 ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP2 data!\n");
@ -554,8 +588,8 @@ void print_via686a(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_VIA686A_TEMP3_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.1f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&VIA686A_ALARM_TEMP3?"ALARM":"");
print_temp_info( cur, min, max );
printf(" %s\n", alarms & VIA686A_ALARM_TEMP3 ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP3 data!\n");
@ -705,8 +739,8 @@ void print_lm78(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_LM78_TEMP_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&LM78_ALARM_TEMP?"ALARM":"");
print_temp_info( cur, max, min );
printf( " %s\n", alarms & LM78_ALARM_TEMP ? "ALARM" : "" );
}
} else
printf("ERROR: Can't get TEMP data!\n");
@ -898,8 +932,8 @@ void print_gl518(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_GL518_TEMP_HYST,&min)) {
if (valid) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s %s\n",
cur,max,min, alarms&GL518_ALARM_TEMP?"ALARM":" ",
print_temp_info( cur, max, min );
printf("%s %s\n", alarms&GL518_ALARM_TEMP?"ALARM":" ",
beeps&GL518_ALARM_TEMP?"(beep)":"");
}
} else
@ -1012,8 +1046,8 @@ void print_adm1025(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_ADM1025_TEMP1_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&ADM1025_ALARM_TEMP?"ALARM":"");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&ADM1025_ALARM_TEMP?"ALARM":"");
}
} else
printf("ERROR: Can't get TEMP data!\n");
@ -1152,11 +1186,22 @@ void print_lm80(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_LM80_TEMP_OS_MAX,&max2)) {
if (valid) {
print_label(label,10);
printf("%+3.2f C (hot:limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
if ( fahrenheit )
{
printf("%+3.2f°C (hot:limit = %+3.0f°F, hysteresis = %+3.0f°F) %s\n",
deg_ctof(cur),deg_ctof(max),deg_ctof(min), alarms&LM80_ALARM_TEMP_HOT?"ALARM":"");
printf(" (os: limit = %+3.0f°F, hysteresis = %+3.0f°F) %s\n",
deg_ctof(max2),deg_ctof(min2), alarms&LM80_ALARM_TEMP_HOT?"ALARM":"");
}
else
{
printf("%+3.2f °C (hot:limit = %+3.0f°C, hysteresis = %+3.0f°C) %s\n",
cur,max,min, alarms&LM80_ALARM_TEMP_HOT?"ALARM":"");
printf(" (os: limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
printf(" (os: limit = %+3.0f°C, hysteresis = %+3.0f°C) %s\n",
max2,min2, alarms&LM80_ALARM_TEMP_HOT?"ALARM":"");
}
}
} else
printf("ERROR: Can't get TEMP data!\n");
free_the_label(&label);
@ -1317,8 +1362,8 @@ void print_mtp008(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_MTP008_TEMP1_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+6.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&MTP008_ALARM_TEMP1?"ALARM":"");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MTP008_ALARM_TEMP1?"ALARM":"");
}
} else
printf("ERROR: Can't get TEMP1 data!\n");
@ -1330,8 +1375,8 @@ void print_mtp008(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_MTP008_TEMP2_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+6.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&MTP008_ALARM_TEMP2?"ALARM":"");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MTP008_ALARM_TEMP2?"ALARM":"");
}
} else
printf("ERROR: Can't get TEMP2 data!\n");
@ -1343,8 +1388,8 @@ void print_mtp008(const sensors_chip_name *name)
!sensors_get_feature(*name,SENSORS_MTP008_TEMP3_OVER,&max)) {
if (valid) {
print_label(label,10);
printf("%+6.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s\n",
cur,max,min, alarms&MTP008_ALARM_TEMP3?"ALARM":"");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MTP008_ALARM_TEMP3?"ALARM":"");
}
} else
printf("ERROR: Can't get TEMP3 data!\n");
@ -1507,7 +1552,7 @@ void print_w83781d(const sensors_chip_name *name)
beeps&W83782D_ALARM_IN8?"(beep)":"");
}
} else
printf("ERROR: Can't get IN6 data!\n");
printf("ERROR: Can't get IN8 data!\n");
free_the_label(&label);
}
@ -1558,15 +1603,14 @@ void print_w83781d(const sensors_chip_name *name)
if (valid) {
if((!is82d) && (!is83s)) {
print_label(label,10);
printf("%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C) %s %s\n",
cur,max,min, alarms&W83781D_ALARM_TEMP1 ?"ALARM":" ",
print_temp_info( cur, max, min );
printf(" %s %s\n", alarms&W83781D_ALARM_TEMP1 ?"ALARM":" ",
beeps&W83781D_ALARM_TEMP1?"(beep)":"");
} else {
if(!sensors_get_feature(*name,SENSORS_W83781D_SENS1,&sens)) {
print_label(label,10);
printf(
"%+3.0f C (limit = %+3.0f C, hysteresis = %+3.0f C, sensor = %s) %s %s\n",
cur,max,min,
print_temp_info( cur, max, min );
printf( " sensor = %s %s %s\n",
(((int)sens)==1)?"PII/Celeron diode":(((int)sens)==2)?
"3904 transistor":"thermistor",
alarms&W83781D_ALARM_TEMP1?"ALARM":" ",
@ -1587,15 +1631,14 @@ void print_w83781d(const sensors_chip_name *name)
if (valid) {
if((!is82d) && (!is83s)) {
print_label(label,10);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C) %s %s\n",
cur,max,min, alarms&W83781D_ALARM_TEMP23 ?"ALARM":" ",
beeps&W83781D_ALARM_TEMP23?"(beep)":"");
print_temp_info( cur, max, min );
printf(" %s %s\n", alarms&W83781D_ALARM_TEMP2 ?"ALARM":" ",
beeps&W83781D_ALARM_TEMP2?"(beep)":"");
} else {
if(!sensors_get_feature(*name,SENSORS_W83781D_SENS2,&sens)) {
print_label(label,10);
printf(
"%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C, sensor = %s) %s %s\n",
cur,max,min,
print_temp_info( cur, max, min );
printf( " sensor = %s %s %s\n",
(((int)sens)==1)?"PII/Celeron diode":(((int)sens)==2)?
"3904 transistor":"thermistor",
alarms&W83781D_ALARM_TEMP2?"ALARM":" ",
@ -1617,15 +1660,14 @@ void print_w83781d(const sensors_chip_name *name)
if (valid) {
if(!is82d) {
print_label(label,10);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C) %s %s\n",
cur,max,min, alarms&W83781D_ALARM_TEMP23 ?"ALARM":" ",
beeps&W83781D_ALARM_TEMP23?"(beep)":"");
print_temp_info( cur, max, min );
printf(" %s %s\n", alarms&W83781D_ALARM_TEMP2 ?"ALARM":" ",
beeps&W83781D_ALARM_TEMP3?"(beep)":"");
} else {
if(!sensors_get_feature(*name,SENSORS_W83781D_SENS3,&sens)) {
print_label(label,10);
printf(
"%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C, sensor = %s) %s %s\n",
cur,max,min,
print_temp_info( cur, max, min );
printf( " sensor = %s %s %s\n",
(((int)sens)==1)?"PII/Celeron diode":(((int)sens)==2)?
"3904 transistor":"thermistor",
alarms&W83781D_ALARM_TEMP3?"ALARM":" ",
@ -1691,8 +1733,8 @@ void print_maxilife(const sensors_chip_name *name)
!sensors_get_feature(*name, SENSORS_MAXI_CG_TEMP1_HYST, &min)) {
if (valid && (cur || max || min)) {
print_label(label, 12);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C)\n",
cur, max, min);
print_temp_info( cur, max, min );
printf("\n");
}
} else
printf("ERROR: Can't get TEMP1 data!\n");
@ -1704,8 +1746,8 @@ void print_maxilife(const sensors_chip_name *name)
!sensors_get_feature(*name, SENSORS_MAXI_CG_TEMP2_HYST, &min)) {
if (valid && (cur || max || min)) {
print_label(label, 12);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C) %s\n",
cur, max, min, alarms&MAXI_ALARM_TEMP2 ? "ALARM" : "");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MAXI_ALARM_TEMP2 ? "ALARM" : "");
}
} else
printf("ERROR: Can't get TEMP2 data!\n");
@ -1717,8 +1759,8 @@ void print_maxilife(const sensors_chip_name *name)
!sensors_get_feature(*name, SENSORS_MAXI_CG_TEMP3_HYST, &min)) {
if (valid && (cur || max || min)) {
print_label(label, 12);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C)\n",
cur, max, min);
print_temp_info( cur, max, min );
printf("\n");
}
} else
printf("ERROR: Can't get TEMP3 data!\n");
@ -1730,8 +1772,8 @@ void print_maxilife(const sensors_chip_name *name)
!sensors_get_feature(*name, SENSORS_MAXI_CG_TEMP4_HYST, &min)) {
if (valid && (cur || max || min)) {
print_label(label, 12);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C) %s\n",
cur, max, min, alarms&MAXI_ALARM_TEMP4 ? "ALARM" : "");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MAXI_ALARM_TEMP4 ? "ALARM" : "");
}
} else
printf("ERROR: Can't get TEMP4 data!\n");
@ -1743,8 +1785,8 @@ void print_maxilife(const sensors_chip_name *name)
!sensors_get_feature(*name, SENSORS_MAXI_CG_TEMP5_HYST, &min)) {
if (valid && (cur || max || min)) {
print_label(label, 12);
printf("%+3.1f C (limit = %+3.1f C, hysteresis = %+3.1f C) %s\n",
cur, max, min, alarms&MAXI_ALARM_TEMP5 ? "ALARM" : "");
print_temp_info( cur, max, min );
printf(" %s\n", alarms&MAXI_ALARM_TEMP5 ? "ALARM" : "");
}
} else
printf("ERROR: Can't get TEMP5 data!\n");

View File

@ -51,7 +51,7 @@ static const char *sprintf_chip_name(sensors_chip_name name);
#define CHIPS_MAX 20
sensors_chip_name chips[CHIPS_MAX];
int chips_count=0;
int do_sets, do_unknown;
int do_sets, do_unknown, fahrenheit;
void print_short_help(void)
{
@ -64,6 +64,7 @@ void print_long_help(void)
printf(" -c, --config-file Specify a config file\n");
printf(" -h, --help Display this help text\n");
printf(" -s, --set Execute `set' statements too (root only)\n");
printf(" -f, --fahrenheit Show temperatures in degrees fahrenheit\n" );
printf(" -u, --unknown Treat chips as unknown ones (testing only)\n");
printf(" -v, --version Display the program version\n");
printf("\n");
@ -136,6 +137,7 @@ int main (int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{ "set", no_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v'},
{ "fahrenheit", no_argument, NULL, 'f' },
{ "config-file", required_argument, NULL, 'c' },
{ "unknown", required_argument, NULL, 'u' },
{ 0,0,0,0 }
@ -144,7 +146,7 @@ int main (int argc, char *argv[])
do_unknown = 0;
do_sets = 0;
while (1) {
c = getopt_long(argc,argv,"hvusc:",long_opts,NULL);
c = getopt_long(argc,argv,"hvufsc:",long_opts,NULL);
if (c == EOF)
break;
switch(c) {
@ -164,6 +166,9 @@ int main (int argc, char *argv[])
case 's':
do_sets = 1;
break;
case 'f':
fahrenheit = 1;
break;
case 'u':
do_unknown = 1;
break;

View File

@ -64,6 +64,8 @@ Treats all chips as unknown ones. Output will be of much lower quality;
this option is only added for testing purposes.
.IP -v
Returns the program version.
.IP -f
Prints the temperatures in degrees Fahrenheit instead of Celsius.
.SH FILES
.I /etc/sensors.conf
.RS