1998-12-23 00:25:53 +00:00
|
|
|
/*
|
|
|
|
chips.c - Part of sensors, a user-space program for hardware monitoring
|
2006-09-27 12:09:04 +00:00
|
|
|
Copyright (c) 1998-2003 Frodo Looijaard <frodol@dds.nl>
|
|
|
|
and Mark D. Studebaker <mdsxyz123@yahoo.com>
|
|
|
|
Copyright (c) 2003-2006 The lm_sensors team
|
1998-12-23 00:25:53 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-06-30 20:28:08 +00:00
|
|
|
#include <string.h>
|
2007-07-05 21:03:06 +00:00
|
|
|
#include <math.h>
|
1998-12-23 00:25:53 +00:00
|
|
|
|
|
|
|
#include "chips.h"
|
|
|
|
#include "lib/sensors.h"
|
|
|
|
|
2000-11-13 18:31:48 +00:00
|
|
|
extern int fahrenheit;
|
2004-01-31 10:17:15 +00:00
|
|
|
extern char degstr[5];
|
1998-12-23 00:25:53 +00:00
|
|
|
|
2007-06-28 09:02:12 +00:00
|
|
|
static inline float deg_ctof(float cel)
|
2000-11-13 18:31:48 +00:00
|
|
|
{
|
|
|
|
return ( cel * ( 9.0F / 5.0F ) + 32.0F );
|
|
|
|
}
|
|
|
|
|
2002-06-29 02:46:51 +00:00
|
|
|
/* minmax = 0 for limit/hysteresis, 1 for max/min, 2 for max only;
|
2001-08-18 21:17:27 +00:00
|
|
|
curprec and limitprec are # of digits after decimal point
|
2007-04-09 14:41:52 +00:00
|
|
|
for the current temp and the limits
|
|
|
|
note: symbolic constants defined in chips.h */
|
2007-05-29 16:49:06 +00:00
|
|
|
void print_temp_info(float n_cur, float n_over, float n_hyst,
|
2001-08-18 21:17:27 +00:00
|
|
|
int minmax, int curprec, int limitprec)
|
2000-11-13 18:31:48 +00:00
|
|
|
{
|
2007-07-05 21:03:06 +00:00
|
|
|
/* note: deg_ctof() will preserve HUGEVAL */
|
2001-08-18 21:17:27 +00:00
|
|
|
if (fahrenheit) {
|
|
|
|
n_cur = deg_ctof(n_cur);
|
|
|
|
n_over = deg_ctof(n_over);
|
|
|
|
n_hyst = deg_ctof(n_hyst);
|
2000-11-13 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 21:03:06 +00:00
|
|
|
/* use %* to pass precision as an argument */
|
|
|
|
if (n_cur != HUGE_VAL)
|
|
|
|
printf("%+6.*f%s ", curprec, n_cur, degstr);
|
|
|
|
else
|
|
|
|
printf("FAULT ");
|
|
|
|
|
2000-11-30 02:42:53 +00:00
|
|
|
if(minmax == MINMAX)
|
2007-07-05 21:03:06 +00:00
|
|
|
printf("(low = %+5.*f%s, high = %+5.*f%s) ",
|
2004-01-31 10:17:15 +00:00
|
|
|
limitprec, n_hyst, degstr,
|
|
|
|
limitprec, n_over, degstr);
|
2002-06-29 02:46:51 +00:00
|
|
|
else if(minmax == MAXONLY)
|
2007-07-05 21:03:06 +00:00
|
|
|
printf("(high = %+5.*f%s) ",
|
2004-01-31 10:17:15 +00:00
|
|
|
limitprec, n_over, degstr);
|
2003-08-09 21:21:32 +00:00
|
|
|
else if(minmax == CRIT)
|
2007-07-05 21:03:06 +00:00
|
|
|
printf("(high = %+5.*f%s, crit = %+5.*f%s) ",
|
2004-01-31 10:17:15 +00:00
|
|
|
limitprec, n_over, degstr,
|
|
|
|
limitprec, n_hyst, degstr);
|
2003-08-14 22:10:32 +00:00
|
|
|
else if(minmax == HYST)
|
2007-07-05 21:03:06 +00:00
|
|
|
printf("(high = %+5.*f%s, hyst = %+5.*f%s) ",
|
2004-01-31 10:17:15 +00:00
|
|
|
limitprec, n_over, degstr,
|
|
|
|
limitprec, n_hyst, degstr);
|
2003-11-03 19:29:20 +00:00
|
|
|
else if(minmax == HYSTONLY)
|
2007-07-05 21:03:06 +00:00
|
|
|
printf("(hyst = %+5.*f%s) ",
|
2004-01-31 10:17:15 +00:00
|
|
|
limitprec, n_over, degstr);
|
2007-07-05 21:03:06 +00:00
|
|
|
else if(minmax != SINGLE)
|
2003-11-03 19:29:20 +00:00
|
|
|
printf("Unknown temperature mode!");
|
2000-11-13 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
1998-12-23 00:25:53 +00:00
|
|
|
void print_label(const char *label, int space)
|
|
|
|
{
|
|
|
|
int len=strlen(label)+1;
|
|
|
|
if (len > space)
|
2004-01-31 10:45:14 +00:00
|
|
|
printf("%s:\n%*s", label, space, "");
|
1998-12-23 00:25:53 +00:00
|
|
|
else
|
2004-01-31 10:45:14 +00:00
|
|
|
printf("%s:%*s", label, space - len, "");
|
1998-12-23 00:25:53 +00:00
|
|
|
}
|
|
|
|
|
1999-12-24 22:44:41 +00:00
|
|
|
int sensors_get_label_and_valid(sensors_chip_name name, int feature, char **label,
|
|
|
|
int *valid)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
err = sensors_get_label(name,feature,label);
|
|
|
|
if (!err)
|
|
|
|
err = sensors_get_ignored(name,feature);
|
|
|
|
if (err >= 0) {
|
|
|
|
*valid = err;
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-07-03 13:22:28 +00:00
|
|
|
void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size)
|
2004-09-19 17:09:59 +00:00
|
|
|
{
|
2005-10-06 17:27:29 +00:00
|
|
|
char *label;
|
2004-09-19 17:09:59 +00:00
|
|
|
int valid;
|
2007-07-03 13:22:28 +00:00
|
|
|
double vid;
|
2004-09-19 17:09:59 +00:00
|
|
|
|
|
|
|
if (!sensors_get_label_and_valid(*name,f_vid,&label,&valid)
|
|
|
|
&& !sensors_get_feature(*name,f_vid,&vid) ) {
|
|
|
|
if (valid) {
|
2007-04-09 14:41:52 +00:00
|
|
|
print_label(label, label_size);
|
2007-07-03 13:22:28 +00:00
|
|
|
printf("%+6.3f V\n", vid);
|
2004-09-19 17:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-06 17:27:29 +00:00
|
|
|
free(label);
|
2004-09-19 17:09:59 +00:00
|
|
|
}
|
|
|
|
|
1999-05-01 15:03:14 +00:00
|
|
|
void print_unknown_chip(const sensors_chip_name *name)
|
|
|
|
{
|
1999-12-24 22:44:41 +00:00
|
|
|
int a,b,valid;
|
1999-05-01 15:03:14 +00:00
|
|
|
const sensors_feature_data *data;
|
|
|
|
char *label;
|
|
|
|
double val;
|
|
|
|
|
|
|
|
a=b=0;
|
|
|
|
while((data=sensors_get_all_features(*name,&a,&b))) {
|
1999-12-24 22:44:41 +00:00
|
|
|
if (sensors_get_label_and_valid(*name,data->number,&label,&valid)) {
|
2003-12-06 11:45:09 +00:00
|
|
|
printf("ERROR: Can't get feature `%s' data!\n",data->name);
|
1999-05-01 15:03:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
1999-12-24 22:44:41 +00:00
|
|
|
if (! valid)
|
|
|
|
continue;
|
1999-05-01 15:03:14 +00:00
|
|
|
if (data->mode & SENSORS_MODE_R) {
|
|
|
|
if(sensors_get_feature(*name,data->number,&val)) {
|
2003-12-06 11:45:09 +00:00
|
|
|
printf("ERROR: Can't get feature `%s' data!\n",data->name);
|
1999-05-01 15:03:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data->mapping != SENSORS_NO_MAPPING)
|
|
|
|
printf(" %s: %.2f (%s)\n",label,val,data->name);
|
|
|
|
else
|
|
|
|
printf("%s: %.2f (%s)\n",label,val,data->name);
|
|
|
|
} else
|
2003-12-06 11:45:09 +00:00
|
|
|
printf("(%s)\n",label);
|
2006-06-03 09:22:10 +00:00
|
|
|
free(label);
|
1999-05-01 15:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|