| 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 Jean Delvare <khali@linux-fr.org> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef LIB_SENSORS_SENSORS_H |
|---|
| 22 | #define LIB_SENSORS_SENSORS_H |
|---|
| 23 | |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <limits.h> |
|---|
| 26 | |
|---|
| 27 | /* Publicly accessible library functions */ |
|---|
| 28 | |
|---|
| 29 | #define SENSORS_CHIP_NAME_PREFIX_ANY NULL |
|---|
| 30 | #define SENSORS_CHIP_NAME_ADDR_ANY -1 |
|---|
| 31 | |
|---|
| 32 | #define SENSORS_BUS_TYPE_ANY (-1) |
|---|
| 33 | #define SENSORS_BUS_TYPE_I2C 0 |
|---|
| 34 | #define SENSORS_BUS_TYPE_ISA 1 |
|---|
| 35 | #define SENSORS_BUS_TYPE_PCI 2 |
|---|
| 36 | #define SENSORS_BUS_TYPE_SPI 3 |
|---|
| 37 | #define SENSORS_BUS_NR_ANY (-1) |
|---|
| 38 | #define SENSORS_BUS_NR_IGNORE (-2) |
|---|
| 39 | |
|---|
| 40 | #ifdef __cplusplus |
|---|
| 41 | extern "C" { |
|---|
| 42 | #endif /* __cplusplus */ |
|---|
| 43 | |
|---|
| 44 | extern const char *libsensors_version; |
|---|
| 45 | |
|---|
| 46 | typedef struct sensors_bus_id { |
|---|
| 47 | short type; |
|---|
| 48 | short nr; |
|---|
| 49 | } sensors_bus_id; |
|---|
| 50 | |
|---|
| 51 | /* A chip name is encoded in this structure */ |
|---|
| 52 | typedef struct sensors_chip_name { |
|---|
| 53 | char *prefix; |
|---|
| 54 | sensors_bus_id bus; |
|---|
| 55 | int addr; |
|---|
| 56 | char *path; |
|---|
| 57 | } sensors_chip_name; |
|---|
| 58 | |
|---|
| 59 | /* Load the configuration file and the detected chips list. If this |
|---|
| 60 | returns a value unequal to zero, you are in trouble; you can not |
|---|
| 61 | assume anything will be initialized properly. If you want to |
|---|
| 62 | reload the configuration file, call sensors_cleanup() below before |
|---|
| 63 | calling sensors_init() again. */ |
|---|
| 64 | int sensors_init(FILE *input); |
|---|
| 65 | |
|---|
| 66 | /* Clean-up function: You can't access anything after |
|---|
| 67 | this, until the next sensors_init() call! */ |
|---|
| 68 | void sensors_cleanup(void); |
|---|
| 69 | |
|---|
| 70 | /* Parse a chip name to the internal representation. Return 0 on success, <0 |
|---|
| 71 | on error. */ |
|---|
| 72 | int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res); |
|---|
| 73 | |
|---|
| 74 | /* Print a chip name from its internal representation. Note that chip should |
|---|
| 75 | not contain wildcard values! Return the number of characters printed on |
|---|
| 76 | success (same as snprintf), <0 on error. */ |
|---|
| 77 | int sensors_snprintf_chip_name(char *str, size_t size, |
|---|
| 78 | const sensors_chip_name *chip); |
|---|
| 79 | |
|---|
| 80 | /* This function returns the adapter name of a bus, |
|---|
| 81 | as used within the sensors_chip_name structure. If it could not be found, |
|---|
| 82 | it returns NULL */ |
|---|
| 83 | const char *sensors_get_adapter_name(const sensors_bus_id *bus); |
|---|
| 84 | |
|---|
| 85 | typedef struct sensors_feature sensors_feature; |
|---|
| 86 | |
|---|
| 87 | /* Look up the label for a given feature. Note that chip should not |
|---|
| 88 | contain wildcard values! The returned string is newly allocated (free it |
|---|
| 89 | yourself). On failure, NULL is returned. |
|---|
| 90 | If no label exists for this feature, its name is returned itself. */ |
|---|
| 91 | char *sensors_get_label(const sensors_chip_name *name, |
|---|
| 92 | const sensors_feature *feature); |
|---|
| 93 | |
|---|
| 94 | /* Read the value of a subfeature of a certain chip. Note that chip should not |
|---|
| 95 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 96 | on failure. */ |
|---|
| 97 | int sensors_get_value(const sensors_chip_name *name, int subfeat_nr, |
|---|
| 98 | double *value); |
|---|
| 99 | |
|---|
| 100 | /* Set the value of a subfeature of a certain chip. Note that chip should not |
|---|
| 101 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 102 | on failure. */ |
|---|
| 103 | int sensors_set_value(const sensors_chip_name *name, int subfeat_nr, |
|---|
| 104 | double value); |
|---|
| 105 | |
|---|
| 106 | /* Execute all set statements for this particular chip. The chip may contain |
|---|
| 107 | wildcards! This function will return 0 on success, and <0 on failure. */ |
|---|
| 108 | int sensors_do_chip_sets(const sensors_chip_name *name); |
|---|
| 109 | |
|---|
| 110 | /* This function returns all detected chips that match a given chip name, |
|---|
| 111 | one by one. If no chip name is provided, all detected chips are returned. |
|---|
| 112 | To start at the beginning of the list, use 0 for nr; NULL is returned if |
|---|
| 113 | we are at the end of the list. Do not try to change these chip names, as |
|---|
| 114 | they point to internal structures! */ |
|---|
| 115 | const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name |
|---|
| 116 | *match, int *nr); |
|---|
| 117 | |
|---|
| 118 | /* These defines are used in the flags field of sensors_subfeature */ |
|---|
| 119 | #define SENSORS_MODE_R 1 |
|---|
| 120 | #define SENSORS_MODE_W 2 |
|---|
| 121 | #define SENSORS_COMPUTE_MAPPING 4 |
|---|
| 122 | |
|---|
| 123 | /* This define is used in the mapping field of sensors_subfeature if no |
|---|
| 124 | mapping is available */ |
|---|
| 125 | #define SENSORS_NO_MAPPING -1 |
|---|
| 126 | |
|---|
| 127 | typedef enum sensors_feature_type { |
|---|
| 128 | SENSORS_FEATURE_IN = 0x00, |
|---|
| 129 | SENSORS_FEATURE_FAN = 0x01, |
|---|
| 130 | SENSORS_FEATURE_TEMP = 0x02, |
|---|
| 131 | SENSORS_FEATURE_VID = 0x10, |
|---|
| 132 | SENSORS_FEATURE_BEEP_ENABLE = 0x18, |
|---|
| 133 | SENSORS_FEATURE_UNKNOWN = INT_MAX, |
|---|
| 134 | } sensors_feature_type; |
|---|
| 135 | |
|---|
| 136 | /* All the sensor types (in, fan, temp, vid) are a multiple of 0x100 apart, |
|---|
| 137 | and sensor subfeatures which have no compute mapping have bit 7 set. */ |
|---|
| 138 | typedef enum sensors_subfeature_type { |
|---|
| 139 | SENSORS_SUBFEATURE_IN_INPUT = SENSORS_FEATURE_IN << 8, |
|---|
| 140 | SENSORS_SUBFEATURE_IN_MIN, |
|---|
| 141 | SENSORS_SUBFEATURE_IN_MAX, |
|---|
| 142 | SENSORS_SUBFEATURE_IN_ALARM = (SENSORS_FEATURE_IN << 8) | 0x80, |
|---|
| 143 | SENSORS_SUBFEATURE_IN_MIN_ALARM, |
|---|
| 144 | SENSORS_SUBFEATURE_IN_MAX_ALARM, |
|---|
| 145 | SENSORS_SUBFEATURE_IN_BEEP, |
|---|
| 146 | |
|---|
| 147 | SENSORS_SUBFEATURE_FAN_INPUT = SENSORS_FEATURE_FAN << 8, |
|---|
| 148 | SENSORS_SUBFEATURE_FAN_MIN, |
|---|
| 149 | SENSORS_SUBFEATURE_FAN_ALARM = (SENSORS_FEATURE_FAN << 8) | 0x80, |
|---|
| 150 | SENSORS_SUBFEATURE_FAN_FAULT, |
|---|
| 151 | SENSORS_SUBFEATURE_FAN_DIV, |
|---|
| 152 | SENSORS_SUBFEATURE_FAN_BEEP, |
|---|
| 153 | |
|---|
| 154 | SENSORS_SUBFEATURE_TEMP_INPUT = SENSORS_FEATURE_TEMP << 8, |
|---|
| 155 | SENSORS_SUBFEATURE_TEMP_MAX, |
|---|
| 156 | SENSORS_SUBFEATURE_TEMP_MAX_HYST, |
|---|
| 157 | SENSORS_SUBFEATURE_TEMP_MIN, |
|---|
| 158 | SENSORS_SUBFEATURE_TEMP_CRIT, |
|---|
| 159 | SENSORS_SUBFEATURE_TEMP_CRIT_HYST, |
|---|
| 160 | SENSORS_SUBFEATURE_TEMP_ALARM = (SENSORS_FEATURE_TEMP << 8) | 0x80, |
|---|
| 161 | SENSORS_SUBFEATURE_TEMP_MAX_ALARM, |
|---|
| 162 | SENSORS_SUBFEATURE_TEMP_MIN_ALARM, |
|---|
| 163 | SENSORS_SUBFEATURE_TEMP_CRIT_ALARM, |
|---|
| 164 | SENSORS_SUBFEATURE_TEMP_FAULT, |
|---|
| 165 | SENSORS_SUBFEATURE_TEMP_TYPE, |
|---|
| 166 | SENSORS_SUBFEATURE_TEMP_OFFSET, |
|---|
| 167 | SENSORS_SUBFEATURE_TEMP_BEEP, |
|---|
| 168 | |
|---|
| 169 | SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8, |
|---|
| 170 | |
|---|
| 171 | SENSORS_SUBFEATURE_BEEP_ENABLE = SENSORS_FEATURE_BEEP_ENABLE << 8, |
|---|
| 172 | |
|---|
| 173 | SENSORS_SUBFEATURE_UNKNOWN = INT_MAX, |
|---|
| 174 | } sensors_subfeature_type; |
|---|
| 175 | |
|---|
| 176 | /* Data about a single chip feature (or category leader) */ |
|---|
| 177 | struct sensors_feature { |
|---|
| 178 | char *name; |
|---|
| 179 | int number; |
|---|
| 180 | sensors_feature_type type; |
|---|
| 181 | /* Members below are for libsensors internal use only */ |
|---|
| 182 | int first_subfeature; |
|---|
| 183 | int padding1; |
|---|
| 184 | }; |
|---|
| 185 | |
|---|
| 186 | /* Data about a single chip subfeature: |
|---|
| 187 | name is the string name used to refer to this subfeature (in config files) |
|---|
| 188 | number is the internal subfeature number, used in many functions to refer |
|---|
| 189 | to this subfeature |
|---|
| 190 | type is the subfeature type |
|---|
| 191 | mapping is either SENSORS_NO_MAPPING if this subfeature is the |
|---|
| 192 | main element of category; or it is the number of a subfeature with which |
|---|
| 193 | this subfeature is logically grouped (a group could be fan, fan_min |
|---|
| 194 | and fan_div) |
|---|
| 195 | flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable), |
|---|
| 196 | SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the |
|---|
| 197 | computation rules of the main feature) */ |
|---|
| 198 | typedef struct sensors_subfeature { |
|---|
| 199 | char *name; |
|---|
| 200 | int number; |
|---|
| 201 | sensors_subfeature_type type; |
|---|
| 202 | int mapping; |
|---|
| 203 | unsigned int flags; |
|---|
| 204 | } sensors_subfeature; |
|---|
| 205 | |
|---|
| 206 | /* This returns all main features of a specific chip. nr is an internally |
|---|
| 207 | used variable. Set it to zero to start at the begin of the list. If no |
|---|
| 208 | more features are found NULL is returned. |
|---|
| 209 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 210 | data structures. */ |
|---|
| 211 | const sensors_feature * |
|---|
| 212 | sensors_get_features(const sensors_chip_name *name, int *nr); |
|---|
| 213 | |
|---|
| 214 | /* This returns all subfeatures of a given main feature. nr is an internally |
|---|
| 215 | used variable. Set it to zero to start at the begin of the list. If no |
|---|
| 216 | more features are found NULL is returned. |
|---|
| 217 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 218 | data structures. */ |
|---|
| 219 | const sensors_subfeature * |
|---|
| 220 | sensors_get_all_subfeatures(const sensors_chip_name *name, |
|---|
| 221 | const sensors_feature *feature, int *nr); |
|---|
| 222 | |
|---|
| 223 | /* This returns the subfeature of the given type for a given main feature, |
|---|
| 224 | if it exists, NULL otherwise. |
|---|
| 225 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 226 | data structures. */ |
|---|
| 227 | const sensors_subfeature * |
|---|
| 228 | sensors_get_subfeature(const sensors_chip_name *name, |
|---|
| 229 | const sensors_feature *feature, |
|---|
| 230 | sensors_subfeature_type type); |
|---|
| 231 | |
|---|
| 232 | #ifdef __cplusplus |
|---|
| 233 | } |
|---|
| 234 | #endif /* __cplusplus */ |
|---|
| 235 | |
|---|
| 236 | #endif /* def LIB_SENSORS_ERROR_H */ |
|---|