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
|
|
|
{
|
2007-08-26 10:57:16 +00:00
|
|
|
return cel * (9.0F / 5.0F) + 32.0F;
|
2000-11-13 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2007-08-26 10:57:16 +00:00
|
|
|
int minmax, int curprec, int limitprec)
|
2000-11-13 18:31:48 +00:00
|
|
|
{
|
2007-08-26 10:57:16 +00:00
|
|
|
/* note: deg_ctof() will preserve HUGEVAL */
|
|
|
|
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-08-26 10:57:16 +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 ");
|
2007-07-05 21:03:06 +00:00
|
|
|
|
2007-08-26 10:57:16 +00:00
|
|
|
if (minmax == MINMAX)
|
|
|
|
printf("(low = %+5.*f%s, high = %+5.*f%s) ",
|
|
|
|
limitprec, n_hyst, degstr,
|
|
|
|
limitprec, n_over, degstr);
|
|
|
|
else if (minmax == MAXONLY)
|
|
|
|
printf("(high = %+5.*f%s) ",
|
|
|
|
limitprec, n_over, degstr);
|
|
|
|
else if (minmax == CRIT)
|
|
|
|
printf("(high = %+5.*f%s, crit = %+5.*f%s) ",
|
|
|
|
limitprec, n_over, degstr,
|
|
|
|
limitprec, n_hyst, degstr);
|
|
|
|
else if (minmax == HYST)
|
|
|
|
printf("(high = %+5.*f%s, hyst = %+5.*f%s) ",
|
|
|
|
limitprec, n_over, degstr,
|
|
|
|
limitprec, n_hyst, degstr);
|
|
|
|
else if (minmax == HYSTONLY)
|
|
|
|
printf("(hyst = %+5.*f%s) ",
|
|
|
|
limitprec, n_over, degstr);
|
|
|
|
else if (minmax != SINGLE)
|
|
|
|
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)
|
|
|
|
{
|
2007-08-26 10:57:16 +00:00
|
|
|
int len = strlen(label)+1;
|
|
|
|
if (len > space)
|
|
|
|
printf("%s:\n%*s", label, space, "");
|
|
|
|
else
|
|
|
|
printf("%s:%*s", label, space - len, "");
|
1998-12-23 00:25:53 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-08-26 10:57:16 +00:00
|
|
|
char *label;
|
|
|
|
double vid;
|
2004-09-19 17:09:59 +00:00
|
|
|
|
2007-08-26 10:57:16 +00:00
|
|
|
if ((label = sensors_get_label(name, f_vid))
|
|
|
|
&& !sensors_get_value(name, f_vid, &vid)) {
|
|
|
|
print_label(label, label_size);
|
|
|
|
printf("%+6.3f V\n", vid);
|
|
|
|
}
|
|
|
|
free(label);
|
2004-09-19 17:09:59 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 07:45:58 +00:00
|
|
|
void print_chip_raw(const sensors_chip_name *name)
|
1999-05-01 15:03:14 +00:00
|
|
|
{
|
2007-08-26 10:57:16 +00:00
|
|
|
int a;
|
|
|
|
const sensors_feature_data *data;
|
|
|
|
char *label;
|
|
|
|
double val;
|
1999-05-01 15:03:14 +00:00
|
|
|
|
2007-08-26 10:57:16 +00:00
|
|
|
a = 0;
|
|
|
|
while ((data = sensors_get_all_features(name, &a))) {
|
|
|
|
if (!(label = sensors_get_label(name, data->number))) {
|
|
|
|
printf("ERROR: Can't get feature `%s' data!\n",
|
|
|
|
data->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data->mode & SENSORS_MODE_R) {
|
|
|
|
if (sensors_get_value(name, data->number, &val)) {
|
|
|
|
printf("ERROR: Can't get feature `%s' data!\n",
|
|
|
|
data->name);
|
|
|
|
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
|
|
|
|
printf("(%s)\n", label);
|
|
|
|
free(label);
|
|
|
|
}
|
|
|
|
}
|