root/lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips.c @ 4695

Revision 4695, 3.8 KB (checked in by khali, 7 years ago)

sensors_get_value() and sensors_set_value(), respectively.
The new names better reflect what the functions do.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    chips.c - Part of sensors, a user-space program for hardware monitoring
3    Copyright (c) 1998-2003 Frodo Looijaard <frodol@dds.nl>
4                            and Mark D. Studebaker <mdsxyz123@yahoo.com>
5    Copyright (c) 2003-2006 The lm_sensors team
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <math.h>
26
27#include "chips.h"
28#include "lib/sensors.h"
29
30extern int fahrenheit;
31extern char degstr[5];
32
33static inline float deg_ctof(float cel)
34{
35   return ( cel * ( 9.0F / 5.0F ) + 32.0F );
36}
37
38/* minmax = 0 for limit/hysteresis, 1 for max/min, 2 for max only;
39   curprec and limitprec are # of digits after decimal point
40   for the current temp and the limits
41   note: symbolic constants defined in chips.h */
42void print_temp_info(float n_cur, float n_over, float n_hyst,
43                     int minmax, int curprec, int limitprec)
44{
45   /* note: deg_ctof() will preserve HUGEVAL */
46   if (fahrenheit) {
47      n_cur  = deg_ctof(n_cur);
48      n_over = deg_ctof(n_over);
49      n_hyst = deg_ctof(n_hyst);
50   }
51
52   /* use %* to pass precision as an argument */
53   if (n_cur != HUGE_VAL)
54      printf("%+6.*f%s  ", curprec, n_cur, degstr);
55   else
56      printf("   FAULT  ");
57
58   if(minmax == MINMAX)
59        printf("(low  = %+5.*f%s, high = %+5.*f%s)  ",
60            limitprec, n_hyst, degstr,
61            limitprec, n_over, degstr);
62   else if(minmax == MAXONLY)
63        printf("(high = %+5.*f%s)                  ",
64            limitprec, n_over, degstr);
65   else if(minmax == CRIT)
66        printf("(high = %+5.*f%s, crit = %+5.*f%s)  ",
67            limitprec, n_over, degstr,
68            limitprec, n_hyst, degstr);
69   else if(minmax == HYST)
70        printf("(high = %+5.*f%s, hyst = %+5.*f%s)  ",
71            limitprec, n_over, degstr,
72            limitprec, n_hyst, degstr);
73   else if(minmax == HYSTONLY)
74        printf("(hyst = %+5.*f%s)                  ",
75            limitprec, n_over, degstr);
76   else if(minmax != SINGLE)
77        printf("Unknown temperature mode!");
78}
79
80void print_label(const char *label, int space)
81{
82  int len=strlen(label)+1;
83  if (len > space)
84    printf("%s:\n%*s", label, space, "");
85  else
86    printf("%s:%*s", label, space - len, "");
87}
88
89void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size)
90{
91  char *label;
92  double vid;
93
94  if ((label = sensors_get_label(name, f_vid))
95      && !sensors_get_value(name, f_vid, &vid)) {
96    print_label(label, label_size);
97    printf("%+6.3f V\n", vid);
98  }
99  free(label);
100}
101
102void print_unknown_chip(const sensors_chip_name *name)
103{
104  int a;
105  const sensors_feature_data *data;
106  char *label;
107  double val;
108 
109  a = 0;
110  while((data=sensors_get_all_features(name, &a))) {
111    if (!(label = sensors_get_label(name, data->number))) {
112      printf("ERROR: Can't get feature `%s' data!\n",data->name);
113      continue;
114    }
115    if (data->mode & SENSORS_MODE_R) {
116      if (sensors_get_value(name, data->number, &val)) {
117        printf("ERROR: Can't get feature `%s' data!\n",data->name);
118        continue;
119      }
120      if (data->mapping != SENSORS_NO_MAPPING)
121        printf("  %s: %.2f (%s)\n",label,val,data->name);
122      else
123        printf("%s: %.2f (%s)\n",label,val,data->name);
124    } else 
125      printf("(%s)\n",label);
126    free(label);
127  }
128}
129
Note: See TracBrowser for help on using the browser.