1998-12-20 16:54:03 +00:00
|
|
|
/*
|
|
|
|
sensors.h - Part of libsensors, a Linux library for reading sensor data.
|
1999-02-08 22:50:29 +00:00
|
|
|
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
2007-08-19 15:03:50 +00:00
|
|
|
Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2010-07-01 11:56:42 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2010-07-01 11:56:42 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
1998-12-20 16:54:03 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-07-01 11:56:42 +00:00
|
|
|
GNU Lesser General Public License for more details.
|
1998-12-20 16:54:03 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2008-03-26 13:37:12 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301 USA.
|
1998-12-20 16:54:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIB_SENSORS_SENSORS_H
|
|
|
|
#define LIB_SENSORS_SENSORS_H
|
|
|
|
|
1998-12-21 14:14:25 +00:00
|
|
|
#include <stdio.h>
|
2007-04-09 17:48:57 +00:00
|
|
|
#include <limits.h>
|
1998-12-21 14:14:25 +00:00
|
|
|
|
1998-12-20 16:54:03 +00:00
|
|
|
/* Publicly accessible library functions */
|
|
|
|
|
2007-10-22 09:39:15 +00:00
|
|
|
/* libsensors API version define, first digit is the major version (changed
|
|
|
|
when the API + ABI breaks), the third digit is incremented to track small
|
|
|
|
API additions like new flags / enum values. The second digit is for tracking
|
|
|
|
larger additions like new methods. */
|
2009-10-18 12:05:16 +00:00
|
|
|
#define SENSORS_API_VERSION 0x421
|
2007-10-22 09:39:15 +00:00
|
|
|
|
2008-04-14 15:29:49 +00:00
|
|
|
#define SENSORS_CHIP_NAME_PREFIX_ANY NULL
|
|
|
|
#define SENSORS_CHIP_NAME_ADDR_ANY (-1)
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2008-04-14 15:29:49 +00:00
|
|
|
#define SENSORS_BUS_TYPE_ANY (-1)
|
|
|
|
#define SENSORS_BUS_TYPE_I2C 0
|
|
|
|
#define SENSORS_BUS_TYPE_ISA 1
|
|
|
|
#define SENSORS_BUS_TYPE_PCI 2
|
|
|
|
#define SENSORS_BUS_TYPE_SPI 3
|
2008-04-14 15:27:59 +00:00
|
|
|
#define SENSORS_BUS_TYPE_VIRTUAL 4
|
2009-01-13 08:06:32 +00:00
|
|
|
#define SENSORS_BUS_TYPE_ACPI 5
|
2009-10-18 12:05:16 +00:00
|
|
|
#define SENSORS_BUS_TYPE_HID 6
|
2008-04-14 15:29:49 +00:00
|
|
|
#define SENSORS_BUS_NR_ANY (-1)
|
|
|
|
#define SENSORS_BUS_NR_IGNORE (-2)
|
2007-08-19 15:03:50 +00:00
|
|
|
|
2000-02-02 20:19:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2007-07-10 19:55:06 +00:00
|
|
|
extern const char *libsensors_version;
|
|
|
|
|
2007-08-19 15:03:50 +00:00
|
|
|
typedef struct sensors_bus_id {
|
|
|
|
short type;
|
|
|
|
short nr;
|
|
|
|
} sensors_bus_id;
|
|
|
|
|
2007-08-16 16:18:18 +00:00
|
|
|
/* A chip name is encoded in this structure */
|
1998-12-20 16:54:03 +00:00
|
|
|
typedef struct sensors_chip_name {
|
2007-08-16 16:18:18 +00:00
|
|
|
char *prefix;
|
2007-08-19 15:03:50 +00:00
|
|
|
sensors_bus_id bus;
|
2007-08-16 16:18:18 +00:00
|
|
|
int addr;
|
|
|
|
char *path;
|
1998-12-20 16:54:03 +00:00
|
|
|
} sensors_chip_name;
|
|
|
|
|
2007-08-22 17:04:12 +00:00
|
|
|
/* Load the configuration file and the detected chips list. If this
|
|
|
|
returns a value unequal to zero, you are in trouble; you can not
|
|
|
|
assume anything will be initialized properly. If you want to
|
|
|
|
reload the configuration file, call sensors_cleanup() below before
|
|
|
|
calling sensors_init() again. */
|
2007-08-16 16:18:18 +00:00
|
|
|
int sensors_init(FILE *input);
|
1998-12-20 21:57:39 +00:00
|
|
|
|
2003-11-23 21:26:37 +00:00
|
|
|
/* Clean-up function: You can't access anything after
|
1998-12-20 21:57:39 +00:00
|
|
|
this, until the next sensors_init() call! */
|
2007-08-16 16:18:18 +00:00
|
|
|
void sensors_cleanup(void);
|
1998-12-20 21:57:39 +00:00
|
|
|
|
2007-08-16 16:18:18 +00:00
|
|
|
/* Parse a chip name to the internal representation. Return 0 on success, <0
|
1998-12-20 16:54:03 +00:00
|
|
|
on error. */
|
2007-08-16 16:18:18 +00:00
|
|
|
int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res);
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2009-06-20 10:04:52 +00:00
|
|
|
/* Free memory allocated for the internal representation of a chip name. */
|
|
|
|
void sensors_free_chip_name(sensors_chip_name *chip);
|
|
|
|
|
2007-08-16 10:04:57 +00:00
|
|
|
/* Print a chip name from its internal representation. Note that chip should
|
|
|
|
not contain wildcard values! Return the number of characters printed on
|
|
|
|
success (same as snprintf), <0 on error. */
|
|
|
|
int sensors_snprintf_chip_name(char *str, size_t size,
|
|
|
|
const sensors_chip_name *chip);
|
|
|
|
|
2007-08-19 15:03:50 +00:00
|
|
|
/* This function returns the adapter name of a bus,
|
2007-08-16 16:18:18 +00:00
|
|
|
as used within the sensors_chip_name structure. If it could not be found,
|
1998-12-22 17:41:43 +00:00
|
|
|
it returns NULL */
|
2007-08-19 15:03:50 +00:00
|
|
|
const char *sensors_get_adapter_name(const sensors_bus_id *bus);
|
2006-10-13 19:55:41 +00:00
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
typedef struct sensors_feature sensors_feature;
|
|
|
|
|
2007-09-23 12:07:53 +00:00
|
|
|
/* Look up the label for a given feature. Note that chip should not
|
2007-08-22 17:05:01 +00:00
|
|
|
contain wildcard values! The returned string is newly allocated (free it
|
|
|
|
yourself). On failure, NULL is returned.
|
2007-08-18 06:58:33 +00:00
|
|
|
If no label exists for this feature, its name is returned itself. */
|
2007-09-23 12:05:16 +00:00
|
|
|
char *sensors_get_label(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature);
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2007-09-23 12:07:53 +00:00
|
|
|
/* Read the value of a subfeature of a certain chip. Note that chip should not
|
1998-12-20 16:54:03 +00:00
|
|
|
contain wildcard values! This function will return 0 on success, and <0
|
|
|
|
on failure. */
|
2007-09-23 12:07:53 +00:00
|
|
|
int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
|
2007-08-22 17:06:13 +00:00
|
|
|
double *value);
|
1998-12-20 16:54:03 +00:00
|
|
|
|
2007-09-23 12:07:53 +00:00
|
|
|
/* Set the value of a subfeature of a certain chip. Note that chip should not
|
1998-12-20 16:54:03 +00:00
|
|
|
contain wildcard values! This function will return 0 on success, and <0
|
1998-12-29 19:48:43 +00:00
|
|
|
on failure. */
|
2007-09-23 12:07:53 +00:00
|
|
|
int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
|
2007-08-22 17:06:13 +00:00
|
|
|
double value);
|
1998-12-20 16:54:03 +00:00
|
|
|
|
1998-12-29 19:48:43 +00:00
|
|
|
/* Execute all set statements for this particular chip. The chip may contain
|
|
|
|
wildcards! This function will return 0 on success, and <0 on failure. */
|
2007-08-16 16:18:18 +00:00
|
|
|
int sensors_do_chip_sets(const sensors_chip_name *name);
|
1998-12-29 19:48:43 +00:00
|
|
|
|
2007-08-26 08:26:20 +00:00
|
|
|
/* This function returns all detected chips that match a given chip name,
|
|
|
|
one by one. If no chip name is provided, all detected chips are returned.
|
|
|
|
To start at the beginning of the list, use 0 for nr; NULL is returned if
|
|
|
|
we are at the end of the list. Do not try to change these chip names, as
|
|
|
|
they point to internal structures! */
|
|
|
|
const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
|
|
|
*match, int *nr);
|
1998-12-22 02:06:51 +00:00
|
|
|
|
2007-09-23 12:02:22 +00:00
|
|
|
/* These defines are used in the flags field of sensors_subfeature */
|
2007-09-05 08:17:22 +00:00
|
|
|
#define SENSORS_MODE_R 1
|
|
|
|
#define SENSORS_MODE_W 2
|
|
|
|
#define SENSORS_COMPUTE_MAPPING 4
|
1998-12-24 18:40:58 +00:00
|
|
|
|
2007-09-23 12:16:50 +00:00
|
|
|
typedef enum sensors_feature_type {
|
|
|
|
SENSORS_FEATURE_IN = 0x00,
|
|
|
|
SENSORS_FEATURE_FAN = 0x01,
|
|
|
|
SENSORS_FEATURE_TEMP = 0x02,
|
2008-04-17 01:27:22 +00:00
|
|
|
SENSORS_FEATURE_POWER = 0x03,
|
|
|
|
SENSORS_FEATURE_ENERGY = 0x04,
|
2008-10-24 09:04:26 +00:00
|
|
|
SENSORS_FEATURE_CURR = 0x05,
|
2007-09-23 12:16:50 +00:00
|
|
|
SENSORS_FEATURE_VID = 0x10,
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_FEATURE_BEEP_ENABLE = 0x18,
|
2007-09-23 12:16:50 +00:00
|
|
|
SENSORS_FEATURE_UNKNOWN = INT_MAX,
|
|
|
|
} sensors_feature_type;
|
|
|
|
|
2007-09-23 17:42:27 +00:00
|
|
|
/* All the sensor types (in, fan, temp, vid) are a multiple of 0x100 apart,
|
|
|
|
and sensor subfeatures which have no compute mapping have bit 7 set. */
|
2007-09-23 12:12:19 +00:00
|
|
|
typedef enum sensors_subfeature_type {
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_IN_INPUT = SENSORS_FEATURE_IN << 8,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_IN_MIN,
|
|
|
|
SENSORS_SUBFEATURE_IN_MAX,
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_IN_ALARM = (SENSORS_FEATURE_IN << 8) | 0x80,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_IN_MIN_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_IN_MAX_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_IN_BEEP,
|
|
|
|
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_FAN_INPUT = SENSORS_FEATURE_FAN << 8,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_FAN_MIN,
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_FAN_ALARM = (SENSORS_FEATURE_FAN << 8) | 0x80,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_FAN_FAULT,
|
|
|
|
SENSORS_SUBFEATURE_FAN_DIV,
|
|
|
|
SENSORS_SUBFEATURE_FAN_BEEP,
|
|
|
|
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_TEMP_INPUT = SENSORS_FEATURE_TEMP << 8,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX_HYST,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MIN,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_HYST,
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_TEMP_ALARM = (SENSORS_FEATURE_TEMP << 8) | 0x80,
|
2007-09-23 12:12:19 +00:00
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MIN_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_FAULT,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_TYPE,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_OFFSET,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_BEEP,
|
|
|
|
|
2008-04-17 01:27:22 +00:00
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE = SENSORS_FEATURE_POWER << 8,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST,
|
2008-10-24 09:03:18 +00:00
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT,
|
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST,
|
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT_LOWEST,
|
2008-04-17 01:27:22 +00:00
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL = (SENSORS_FEATURE_POWER << 8) | 0x80,
|
|
|
|
|
|
|
|
SENSORS_SUBFEATURE_ENERGY_INPUT = SENSORS_FEATURE_ENERGY << 8,
|
|
|
|
|
2008-10-24 09:04:26 +00:00
|
|
|
SENSORS_SUBFEATURE_CURR_INPUT = SENSORS_FEATURE_CURR << 8,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MIN,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MAX,
|
|
|
|
SENSORS_SUBFEATURE_CURR_ALARM = (SENSORS_FEATURE_CURR << 8) | 0x80,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MIN_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MAX_ALARM,
|
|
|
|
SENSORS_SUBFEATURE_CURR_BEEP,
|
|
|
|
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8,
|
2007-09-23 12:12:19 +00:00
|
|
|
|
2007-09-23 17:42:27 +00:00
|
|
|
SENSORS_SUBFEATURE_BEEP_ENABLE = SENSORS_FEATURE_BEEP_ENABLE << 8,
|
2007-09-23 12:12:19 +00:00
|
|
|
|
|
|
|
SENSORS_SUBFEATURE_UNKNOWN = INT_MAX,
|
|
|
|
} sensors_subfeature_type;
|
2007-04-09 14:40:05 +00:00
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
/* Data about a single chip feature (or category leader) */
|
|
|
|
struct sensors_feature {
|
|
|
|
char *name;
|
2007-09-23 12:16:50 +00:00
|
|
|
int number;
|
|
|
|
sensors_feature_type type;
|
2007-09-23 17:48:57 +00:00
|
|
|
/* Members below are for libsensors internal use only */
|
2007-09-23 12:05:16 +00:00
|
|
|
int first_subfeature;
|
2007-09-23 17:48:57 +00:00
|
|
|
int padding1;
|
2007-09-23 12:05:16 +00:00
|
|
|
};
|
|
|
|
|
2007-09-23 12:02:22 +00:00
|
|
|
/* Data about a single chip subfeature:
|
|
|
|
name is the string name used to refer to this subfeature (in config files)
|
|
|
|
number is the internal subfeature number, used in many functions to refer
|
2007-09-23 12:07:53 +00:00
|
|
|
to this subfeature
|
2007-09-23 12:02:22 +00:00
|
|
|
type is the subfeature type
|
2007-09-24 11:22:24 +00:00
|
|
|
mapping is the number of a main feature this subfeature belongs to
|
|
|
|
(for example subfeatures fan1_input, fan1_min, fan1_div and fan1_alarm
|
|
|
|
are mapped to main feature fan1)
|
2007-09-23 11:59:51 +00:00
|
|
|
flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable),
|
|
|
|
SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the
|
|
|
|
computation rules of the main feature) */
|
2007-09-23 12:02:22 +00:00
|
|
|
typedef struct sensors_subfeature {
|
2007-08-16 16:18:18 +00:00
|
|
|
char *name;
|
2007-08-30 21:23:22 +00:00
|
|
|
int number;
|
2007-09-23 12:12:19 +00:00
|
|
|
sensors_subfeature_type type;
|
2007-08-16 16:18:18 +00:00
|
|
|
int mapping;
|
2007-09-05 08:13:15 +00:00
|
|
|
unsigned int flags;
|
2007-09-23 12:02:22 +00:00
|
|
|
} sensors_subfeature;
|
2007-07-19 20:46:09 +00:00
|
|
|
|
2007-09-23 12:00:59 +00:00
|
|
|
/* This returns all main features of a specific chip. nr is an internally
|
|
|
|
used variable. Set it to zero to start at the begin of the list. If no
|
|
|
|
more features are found NULL is returned.
|
2007-07-19 20:46:09 +00:00
|
|
|
Do not try to change the returned structure; you will corrupt internal
|
|
|
|
data structures. */
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *
|
2007-09-23 12:00:59 +00:00
|
|
|
sensors_get_features(const sensors_chip_name *name, int *nr);
|
|
|
|
|
2007-09-23 12:16:50 +00:00
|
|
|
/* This returns all subfeatures of a given main feature. nr is an internally
|
|
|
|
used variable. Set it to zero to start at the begin of the list. If no
|
|
|
|
more features are found NULL is returned.
|
2007-09-23 12:00:59 +00:00
|
|
|
Do not try to change the returned structure; you will corrupt internal
|
|
|
|
data structures. */
|
2007-09-23 12:02:22 +00:00
|
|
|
const sensors_subfeature *
|
2007-09-23 12:05:16 +00:00
|
|
|
sensors_get_all_subfeatures(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature, int *nr);
|
2007-04-09 17:48:57 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
/* This returns the subfeature of the given type for a given main feature,
|
|
|
|
if it exists, NULL otherwise.
|
|
|
|
Do not try to change the returned structure; you will corrupt internal
|
|
|
|
data structures. */
|
|
|
|
const sensors_subfeature *
|
|
|
|
sensors_get_subfeature(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
|
|
|
sensors_subfeature_type type);
|
|
|
|
|
2000-02-02 20:19:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1998-12-20 16:54:03 +00:00
|
|
|
#endif /* def LIB_SENSORS_ERROR_H */
|