| 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 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #ifndef LIB_SENSORS_SENSORS_H |
|---|
| 21 | #define LIB_SENSORS_SENSORS_H |
|---|
| 22 | |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <limits.h> |
|---|
| 25 | |
|---|
| 26 | /* Publicly accessible library functions */ |
|---|
| 27 | |
|---|
| 28 | #define SENSORS_CHIP_NAME_PREFIX_ANY NULL |
|---|
| 29 | #define SENSORS_CHIP_NAME_BUS_ISA -1 |
|---|
| 30 | #define SENSORS_CHIP_NAME_BUS_ANY -2 |
|---|
| 31 | #define SENSORS_CHIP_NAME_BUS_ANY_I2C -3 |
|---|
| 32 | #define SENSORS_CHIP_NAME_BUS_DUMMY -4 |
|---|
| 33 | #define SENSORS_CHIP_NAME_BUS_PCI -5 |
|---|
| 34 | #define SENSORS_CHIP_NAME_ADDR_ANY -1 |
|---|
| 35 | |
|---|
| 36 | #ifdef __cplusplus |
|---|
| 37 | extern "C" { |
|---|
| 38 | #endif /* __cplusplus */ |
|---|
| 39 | |
|---|
| 40 | extern const char *libsensors_version; |
|---|
| 41 | |
|---|
| 42 | /* A chip name is encoded is in this structure */ |
|---|
| 43 | typedef struct sensors_chip_name { |
|---|
| 44 | char *prefix; |
|---|
| 45 | int bus; |
|---|
| 46 | int addr; |
|---|
| 47 | char *busname; /* if dummy */ |
|---|
| 48 | } sensors_chip_name; |
|---|
| 49 | |
|---|
| 50 | /* (Re)load the configuration file and the detected chips list. If this |
|---|
| 51 | returns a value unequal to zero, you are in trouble; you can not |
|---|
| 52 | assume anything will be initialized properly. */ |
|---|
| 53 | extern int sensors_init(FILE *input); |
|---|
| 54 | |
|---|
| 55 | /* Clean-up function: You can't access anything after |
|---|
| 56 | this, until the next sensors_init() call! */ |
|---|
| 57 | extern void sensors_cleanup(void); |
|---|
| 58 | |
|---|
| 59 | /* Parse a chip name to the internal representation. Return 0 on succes, <0 |
|---|
| 60 | on error. */ |
|---|
| 61 | extern int sensors_parse_chip_name(const char *orig_name, |
|---|
| 62 | sensors_chip_name *res); |
|---|
| 63 | |
|---|
| 64 | /* Compare two chips name descriptions, to see whether they could match. |
|---|
| 65 | Return 0 if it does not match, return 1 if it does match. */ |
|---|
| 66 | extern int sensors_match_chip(const sensors_chip_name *chip1, |
|---|
| 67 | const sensors_chip_name *chip2); |
|---|
| 68 | |
|---|
| 69 | /* This function returns the adapter name of a bus number, |
|---|
| 70 | as used within the sensors_chip_name structure. If it could not be found, |
|---|
| 71 | it returns NULL */ |
|---|
| 72 | extern const char *sensors_get_adapter_name(int bus_nr); |
|---|
| 73 | |
|---|
| 74 | /* Look up the label which belongs to this chip. Note that chip should not |
|---|
| 75 | contain wildcard values! *result is newly allocated (free it yourself). |
|---|
| 76 | This function will return 0 on success, and <0 on failure. This |
|---|
| 77 | function takes logical mappings into account. */ |
|---|
| 78 | extern int sensors_get_label(const sensors_chip_name *name, int feature, |
|---|
| 79 | char **result); |
|---|
| 80 | |
|---|
| 81 | /* Read the value of a feature of a certain chip. Note that chip should not |
|---|
| 82 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 83 | on failure. */ |
|---|
| 84 | extern int sensors_get_feature(const sensors_chip_name *name, int feature, |
|---|
| 85 | double *result); |
|---|
| 86 | |
|---|
| 87 | /* Set the value of a feature of a certain chip. Note that chip should not |
|---|
| 88 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 89 | on failure. */ |
|---|
| 90 | extern int sensors_set_feature(const sensors_chip_name *name, int feature, |
|---|
| 91 | double value); |
|---|
| 92 | |
|---|
| 93 | /* Execute all set statements for this particular chip. The chip may contain |
|---|
| 94 | wildcards! This function will return 0 on success, and <0 on failure. */ |
|---|
| 95 | extern int sensors_do_chip_sets(const sensors_chip_name *name); |
|---|
| 96 | |
|---|
| 97 | /* This function returns all detected chips, one by one. To start at the |
|---|
| 98 | beginning of the list, use 0 for nr; NULL is returned if we are |
|---|
| 99 | at the end of the list. Do not try to change these chip names, as |
|---|
| 100 | they point to internal structures! Do not use nr for anything else. */ |
|---|
| 101 | extern const sensors_chip_name *sensors_get_detected_chips(int *nr); |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* These defines are used in the mode field of sensors_feature_data */ |
|---|
| 105 | #define SENSORS_MODE_NO_RW 0 |
|---|
| 106 | #define SENSORS_MODE_R 1 |
|---|
| 107 | #define SENSORS_MODE_W 2 |
|---|
| 108 | #define SENSORS_MODE_RW 3 |
|---|
| 109 | |
|---|
| 110 | /* This define is used in the mapping field of sensors_feature_data if no |
|---|
| 111 | mapping is available */ |
|---|
| 112 | #define SENSORS_NO_MAPPING -1 |
|---|
| 113 | |
|---|
| 114 | /* This enum contains some "magic" used by sensors_read_dynamic_chip() from |
|---|
| 115 | lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of |
|---|
| 116 | 0x100 apart, and sensor features which should not have a compute_mapping to |
|---|
| 117 | the _input feature start at 0x?10. */ |
|---|
| 118 | typedef enum sensors_feature_type { |
|---|
| 119 | SENSORS_FEATURE_IN = 0x000, |
|---|
| 120 | SENSORS_FEATURE_IN_MIN, |
|---|
| 121 | SENSORS_FEATURE_IN_MAX, |
|---|
| 122 | SENSORS_FEATURE_IN_ALARM = 0x010, |
|---|
| 123 | SENSORS_FEATURE_IN_MIN_ALARM, |
|---|
| 124 | SENSORS_FEATURE_IN_MAX_ALARM, |
|---|
| 125 | |
|---|
| 126 | SENSORS_FEATURE_FAN = 0x100, |
|---|
| 127 | SENSORS_FEATURE_FAN_MIN, |
|---|
| 128 | SENSORS_FEATURE_FAN_ALARM = 0x110, |
|---|
| 129 | SENSORS_FEATURE_FAN_FAULT, |
|---|
| 130 | SENSORS_FEATURE_FAN_DIV, |
|---|
| 131 | |
|---|
| 132 | SENSORS_FEATURE_TEMP = 0x200, |
|---|
| 133 | SENSORS_FEATURE_TEMP_MAX, |
|---|
| 134 | SENSORS_FEATURE_TEMP_MAX_HYST, |
|---|
| 135 | SENSORS_FEATURE_TEMP_MIN, |
|---|
| 136 | SENSORS_FEATURE_TEMP_CRIT, |
|---|
| 137 | SENSORS_FEATURE_TEMP_CRIT_HYST, |
|---|
| 138 | SENSORS_FEATURE_TEMP_ALARM = 0x210, |
|---|
| 139 | SENSORS_FEATURE_TEMP_MAX_ALARM, |
|---|
| 140 | SENSORS_FEATURE_TEMP_MIN_ALARM, |
|---|
| 141 | SENSORS_FEATURE_TEMP_CRIT_ALARM, |
|---|
| 142 | SENSORS_FEATURE_TEMP_FAULT, |
|---|
| 143 | SENSORS_FEATURE_TEMP_SENS, |
|---|
| 144 | |
|---|
| 145 | SENSORS_FEATURE_VID = 0x300, |
|---|
| 146 | |
|---|
| 147 | SENSORS_FEATURE_UNKNOWN = INT_MAX, |
|---|
| 148 | |
|---|
| 149 | /* special the largest number of subfeatures used, iow the |
|---|
| 150 | highest ## from all the 0x?## above + 1*/ |
|---|
| 151 | SENSORS_FEATURE_MAX_SUB_FEATURES = 22 |
|---|
| 152 | } sensors_feature_type; |
|---|
| 153 | |
|---|
| 154 | /* This structure is used when you want to get all features of a specific |
|---|
| 155 | chip. */ |
|---|
| 156 | typedef struct sensors_feature_data { |
|---|
| 157 | int number; |
|---|
| 158 | char *name; |
|---|
| 159 | sensors_feature_type type; |
|---|
| 160 | int mapping; |
|---|
| 161 | int compute_mapping; |
|---|
| 162 | int mode; |
|---|
| 163 | } sensors_feature_data; |
|---|
| 164 | |
|---|
| 165 | /* This returns all features of a specific chip. They are returned in |
|---|
| 166 | bunches: everything with the same mapping is returned just after each |
|---|
| 167 | other, with the master feature in front (that feature does not map to |
|---|
| 168 | itself, but has SENSORS_NO_MAPPING as mapping field). nr is |
|---|
| 169 | an internally used variable. Set it to zero to start again at the |
|---|
| 170 | begin of the list. If no more features are found NULL is returned. |
|---|
| 171 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 172 | data structures. */ |
|---|
| 173 | extern const sensors_feature_data *sensors_get_all_features |
|---|
| 174 | (const sensors_chip_name *name, int *nr); |
|---|
| 175 | |
|---|
| 176 | #ifdef __cplusplus |
|---|
| 177 | } |
|---|
| 178 | #endif /* __cplusplus */ |
|---|
| 179 | |
|---|
| 180 | #endif /* def LIB_SENSORS_ERROR_H */ |
|---|