root/lm-sensors/trunk/lib/sensors.h @ 6035

Revision 6035, 11.1 KB (checked in by khali, 2 years ago)

Prepare for release.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    sensors.h - Part of libsensors, a Linux library for reading sensor data.
3    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
4    Copyright (C) 2007, 2010  Jean Delvare <khali@linux-fr.org>
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU Lesser General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19    MA 02110-1301 USA.
20*/
21
22#ifndef LIB_SENSORS_SENSORS_H
23#define LIB_SENSORS_SENSORS_H
24
25#include <stdio.h>
26#include <limits.h>
27
28/* Publicly accessible library functions */
29
30/* libsensors API version define, first digit is the major version (changed
31   when the API + ABI breaks), the third digit is incremented to track small
32   API additions like new flags / enum values. The second digit is for tracking
33   larger additions like new methods. */
34#define SENSORS_API_VERSION             0x432
35
36#define SENSORS_CHIP_NAME_PREFIX_ANY    NULL
37#define SENSORS_CHIP_NAME_ADDR_ANY      (-1)
38
39#define SENSORS_BUS_TYPE_ANY            (-1)
40#define SENSORS_BUS_TYPE_I2C            0
41#define SENSORS_BUS_TYPE_ISA            1
42#define SENSORS_BUS_TYPE_PCI            2
43#define SENSORS_BUS_TYPE_SPI            3
44#define SENSORS_BUS_TYPE_VIRTUAL        4
45#define SENSORS_BUS_TYPE_ACPI           5
46#define SENSORS_BUS_TYPE_HID            6
47#define SENSORS_BUS_NR_ANY              (-1)
48#define SENSORS_BUS_NR_IGNORE           (-2)
49
50#ifdef __cplusplus
51extern "C" {
52#endif /* __cplusplus */
53
54extern const char *libsensors_version;
55
56typedef struct sensors_bus_id {
57        short type;
58        short nr;
59} sensors_bus_id;
60
61/* A chip name is encoded in this structure */
62typedef struct sensors_chip_name {
63        char *prefix;
64        sensors_bus_id bus;
65        int addr;
66        char *path;
67} sensors_chip_name;
68
69/* Load the configuration file and the detected chips list. If this
70   returns a value unequal to zero, you are in trouble; you can not
71   assume anything will be initialized properly. If you want to
72   reload the configuration file, call sensors_cleanup() below before
73   calling sensors_init() again. */
74int sensors_init(FILE *input);
75
76/* Clean-up function: You can't access anything after
77   this, until the next sensors_init() call! */
78void sensors_cleanup(void);
79
80/* Parse a chip name to the internal representation. Return 0 on success, <0
81   on error. */
82int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res);
83
84/* Free memory allocated for the internal representation of a chip name. */
85void sensors_free_chip_name(sensors_chip_name *chip);
86
87/* Print a chip name from its internal representation. Note that chip should
88   not contain wildcard values! Return the number of characters printed on
89   success (same as snprintf), <0 on error. */
90int sensors_snprintf_chip_name(char *str, size_t size,
91                               const sensors_chip_name *chip);
92
93/* This function returns the adapter name of a bus,
94   as used within the sensors_chip_name structure. If it could not be found,
95   it returns NULL */
96const char *sensors_get_adapter_name(const sensors_bus_id *bus);
97
98typedef struct sensors_feature sensors_feature;
99
100/* Look up the label for a given feature. Note that chip should not
101   contain wildcard values! The returned string is newly allocated (free it
102   yourself). On failure, NULL is returned.
103   If no label exists for this feature, its name is returned itself. */
104char *sensors_get_label(const sensors_chip_name *name,
105                        const sensors_feature *feature);
106
107/* Read the value of a subfeature of a certain chip. Note that chip should not
108   contain wildcard values! This function will return 0 on success, and <0
109   on failure.  */
110int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
111                      double *value);
112
113/* Set the value of a subfeature of a certain chip. Note that chip should not
114   contain wildcard values! This function will return 0 on success, and <0
115   on failure. */
116int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
117                      double value);
118
119/* Execute all set statements for this particular chip. The chip may contain
120   wildcards!  This function will return 0 on success, and <0 on failure. */
121int sensors_do_chip_sets(const sensors_chip_name *name);
122
123/* This function returns all detected chips that match a given chip name,
124   one by one. If no chip name is provided, all detected chips are returned.
125   To start at the beginning of the list, use 0 for nr; NULL is returned if
126   we are at the end of the list. Do not try to change these chip names, as
127   they point to internal structures! */
128const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
129                                                    *match, int *nr);
130
131/* These defines are used in the flags field of sensors_subfeature */
132#define SENSORS_MODE_R                  1
133#define SENSORS_MODE_W                  2
134#define SENSORS_COMPUTE_MAPPING         4
135
136typedef enum sensors_feature_type {
137        SENSORS_FEATURE_IN              = 0x00,
138        SENSORS_FEATURE_FAN             = 0x01,
139        SENSORS_FEATURE_TEMP            = 0x02,
140        SENSORS_FEATURE_POWER           = 0x03,
141        SENSORS_FEATURE_ENERGY          = 0x04,
142        SENSORS_FEATURE_CURR            = 0x05,
143        SENSORS_FEATURE_HUMIDITY        = 0x06,
144        SENSORS_FEATURE_MAX_MAIN,
145        SENSORS_FEATURE_VID             = 0x10,
146        SENSORS_FEATURE_INTRUSION       = 0x11,
147        SENSORS_FEATURE_MAX_OTHER,
148        SENSORS_FEATURE_BEEP_ENABLE     = 0x18,
149        SENSORS_FEATURE_UNKNOWN         = INT_MAX,
150} sensors_feature_type;
151
152/* All the sensor types (in, fan, temp, vid) are a multiple of 0x100 apart,
153   and sensor subfeatures which have no compute mapping have bit 7 set. */
154typedef enum sensors_subfeature_type {
155        SENSORS_SUBFEATURE_IN_INPUT = SENSORS_FEATURE_IN << 8,
156        SENSORS_SUBFEATURE_IN_MIN,
157        SENSORS_SUBFEATURE_IN_MAX,
158        SENSORS_SUBFEATURE_IN_LCRIT,
159        SENSORS_SUBFEATURE_IN_CRIT,
160        SENSORS_SUBFEATURE_IN_AVERAGE,
161        SENSORS_SUBFEATURE_IN_LOWEST,
162        SENSORS_SUBFEATURE_IN_HIGHEST,
163        SENSORS_SUBFEATURE_IN_ALARM = (SENSORS_FEATURE_IN << 8) | 0x80,
164        SENSORS_SUBFEATURE_IN_MIN_ALARM,
165        SENSORS_SUBFEATURE_IN_MAX_ALARM,
166        SENSORS_SUBFEATURE_IN_BEEP,
167        SENSORS_SUBFEATURE_IN_LCRIT_ALARM,
168        SENSORS_SUBFEATURE_IN_CRIT_ALARM,
169
170        SENSORS_SUBFEATURE_FAN_INPUT = SENSORS_FEATURE_FAN << 8,
171        SENSORS_SUBFEATURE_FAN_MIN,
172        SENSORS_SUBFEATURE_FAN_MAX,
173        SENSORS_SUBFEATURE_FAN_ALARM = (SENSORS_FEATURE_FAN << 8) | 0x80,
174        SENSORS_SUBFEATURE_FAN_FAULT,
175        SENSORS_SUBFEATURE_FAN_DIV,
176        SENSORS_SUBFEATURE_FAN_BEEP,
177        SENSORS_SUBFEATURE_FAN_PULSES,
178        SENSORS_SUBFEATURE_FAN_MIN_ALARM,
179        SENSORS_SUBFEATURE_FAN_MAX_ALARM,
180
181        SENSORS_SUBFEATURE_TEMP_INPUT = SENSORS_FEATURE_TEMP << 8,
182        SENSORS_SUBFEATURE_TEMP_MAX,
183        SENSORS_SUBFEATURE_TEMP_MAX_HYST,
184        SENSORS_SUBFEATURE_TEMP_MIN,
185        SENSORS_SUBFEATURE_TEMP_CRIT,
186        SENSORS_SUBFEATURE_TEMP_CRIT_HYST,
187        SENSORS_SUBFEATURE_TEMP_LCRIT,
188        SENSORS_SUBFEATURE_TEMP_EMERGENCY,
189        SENSORS_SUBFEATURE_TEMP_EMERGENCY_HYST,
190        SENSORS_SUBFEATURE_TEMP_LOWEST,
191        SENSORS_SUBFEATURE_TEMP_HIGHEST,
192        SENSORS_SUBFEATURE_TEMP_ALARM = (SENSORS_FEATURE_TEMP << 8) | 0x80,
193        SENSORS_SUBFEATURE_TEMP_MAX_ALARM,
194        SENSORS_SUBFEATURE_TEMP_MIN_ALARM,
195        SENSORS_SUBFEATURE_TEMP_CRIT_ALARM,
196        SENSORS_SUBFEATURE_TEMP_FAULT,
197        SENSORS_SUBFEATURE_TEMP_TYPE,
198        SENSORS_SUBFEATURE_TEMP_OFFSET,
199        SENSORS_SUBFEATURE_TEMP_BEEP,
200        SENSORS_SUBFEATURE_TEMP_EMERGENCY_ALARM,
201        SENSORS_SUBFEATURE_TEMP_LCRIT_ALARM,
202
203        SENSORS_SUBFEATURE_POWER_AVERAGE = SENSORS_FEATURE_POWER << 8,
204        SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST,
205        SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST,
206        SENSORS_SUBFEATURE_POWER_INPUT,
207        SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST,
208        SENSORS_SUBFEATURE_POWER_INPUT_LOWEST,
209        SENSORS_SUBFEATURE_POWER_CAP,
210        SENSORS_SUBFEATURE_POWER_CAP_HYST,
211        SENSORS_SUBFEATURE_POWER_MAX,
212        SENSORS_SUBFEATURE_POWER_CRIT,
213        SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL = (SENSORS_FEATURE_POWER << 8) | 0x80,
214        SENSORS_SUBFEATURE_POWER_ALARM,
215        SENSORS_SUBFEATURE_POWER_CAP_ALARM,
216        SENSORS_SUBFEATURE_POWER_MAX_ALARM,
217        SENSORS_SUBFEATURE_POWER_CRIT_ALARM,
218
219        SENSORS_SUBFEATURE_ENERGY_INPUT = SENSORS_FEATURE_ENERGY << 8,
220
221        SENSORS_SUBFEATURE_CURR_INPUT = SENSORS_FEATURE_CURR << 8,
222        SENSORS_SUBFEATURE_CURR_MIN,
223        SENSORS_SUBFEATURE_CURR_MAX,
224        SENSORS_SUBFEATURE_CURR_LCRIT,
225        SENSORS_SUBFEATURE_CURR_CRIT,
226        SENSORS_SUBFEATURE_CURR_AVERAGE,
227        SENSORS_SUBFEATURE_CURR_LOWEST,
228        SENSORS_SUBFEATURE_CURR_HIGHEST,
229        SENSORS_SUBFEATURE_CURR_ALARM = (SENSORS_FEATURE_CURR << 8) | 0x80,
230        SENSORS_SUBFEATURE_CURR_MIN_ALARM,
231        SENSORS_SUBFEATURE_CURR_MAX_ALARM,
232        SENSORS_SUBFEATURE_CURR_BEEP,
233        SENSORS_SUBFEATURE_CURR_LCRIT_ALARM,
234        SENSORS_SUBFEATURE_CURR_CRIT_ALARM,
235
236        SENSORS_SUBFEATURE_HUMIDITY_INPUT = SENSORS_FEATURE_HUMIDITY << 8,
237
238        SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8,
239
240        SENSORS_SUBFEATURE_INTRUSION_ALARM = SENSORS_FEATURE_INTRUSION << 8,
241        SENSORS_SUBFEATURE_INTRUSION_BEEP,
242
243        SENSORS_SUBFEATURE_BEEP_ENABLE = SENSORS_FEATURE_BEEP_ENABLE << 8,
244
245        SENSORS_SUBFEATURE_UNKNOWN = INT_MAX,
246} sensors_subfeature_type;
247
248/* Data about a single chip feature (or category leader) */
249struct sensors_feature {
250        char *name;
251        int number;
252        sensors_feature_type type;
253        /* Members below are for libsensors internal use only */
254        int first_subfeature;
255        int padding1;
256};
257
258/* Data about a single chip subfeature:
259   name is the string name used to refer to this subfeature (in config files)
260   number is the internal subfeature number, used in many functions to refer
261     to this subfeature
262   type is the subfeature type
263   mapping is the number of a main feature this subfeature belongs to
264     (for example subfeatures fan1_input, fan1_min, fan1_div and fan1_alarm
265      are mapped to main feature fan1)
266   flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable),
267     SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the
268     computation rules of the main feature) */
269typedef struct sensors_subfeature {
270        char *name;
271        int number;
272        sensors_subfeature_type type;
273        int mapping;
274        unsigned int flags;
275} sensors_subfeature;
276
277/* This returns all main features of a specific chip. nr is an internally
278   used variable. Set it to zero to start at the begin of the list. If no
279   more features are found NULL is returned.
280   Do not try to change the returned structure; you will corrupt internal
281   data structures. */
282const sensors_feature *
283sensors_get_features(const sensors_chip_name *name, int *nr);
284
285/* This returns all subfeatures of a given main feature. nr is an internally
286   used variable. Set it to zero to start at the begin of the list. If no
287   more features are found NULL is returned.
288   Do not try to change the returned structure; you will corrupt internal
289   data structures. */
290const sensors_subfeature *
291sensors_get_all_subfeatures(const sensors_chip_name *name,
292                            const sensors_feature *feature, int *nr);
293
294/* This returns the subfeature of the given type for a given main feature,
295   if it exists, NULL otherwise.
296   Do not try to change the returned structure; you will corrupt internal
297   data structures. */
298const sensors_subfeature *
299sensors_get_subfeature(const sensors_chip_name *name,
300                       const sensors_feature *feature,
301                       sensors_subfeature_type type);
302
303#ifdef __cplusplus
304}
305#endif /* __cplusplus */
306
307#endif /* def LIB_SENSORS_ERROR_H */
Note: See TracBrowser for help on using the browser.