| [95] | 1 | /* |
|---|
| 2 | sensors.h - Part of libsensors, a Linux library for reading sensor data. |
|---|
| [207] | 3 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| [4686] | 4 | Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> |
|---|
| [95] | 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 | |
|---|
| [98] | 24 | #include <stdio.h> |
|---|
| [4366] | 25 | #include <limits.h> |
|---|
| [98] | 26 | |
|---|
| [95] | 27 | /* Publicly accessible library functions */ |
|---|
| 28 | |
|---|
| 29 | #define SENSORS_CHIP_NAME_PREFIX_ANY NULL |
|---|
| 30 | #define SENSORS_CHIP_NAME_ADDR_ANY -1 |
|---|
| 31 | |
|---|
| [4686] | 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_NR_ANY (-1) |
|---|
| 37 | |
|---|
| [722] | 38 | #ifdef __cplusplus |
|---|
| 39 | extern "C" { |
|---|
| 40 | #endif /* __cplusplus */ |
|---|
| 41 | |
|---|
| [4602] | 42 | extern const char *libsensors_version; |
|---|
| 43 | |
|---|
| [4686] | 44 | typedef struct sensors_bus_id { |
|---|
| 45 | short type; |
|---|
| 46 | short nr; |
|---|
| 47 | } sensors_bus_id; |
|---|
| 48 | |
|---|
| [4678] | 49 | /* A chip name is encoded in this structure */ |
|---|
| [95] | 50 | typedef struct sensors_chip_name { |
|---|
| [4678] | 51 | char *prefix; |
|---|
| [4686] | 52 | sensors_bus_id bus; |
|---|
| [4678] | 53 | int addr; |
|---|
| 54 | char *path; |
|---|
| [95] | 55 | } sensors_chip_name; |
|---|
| 56 | |
|---|
| [4678] | 57 | /* (Re)load the configuration file and the detected chips list. If this |
|---|
| [101] | 58 | returns a value unequal to zero, you are in trouble; you can not |
|---|
| 59 | assume anything will be initialized properly. */ |
|---|
| [4678] | 60 | int sensors_init(FILE *input); |
|---|
| [97] | 61 | |
|---|
| [2090] | 62 | /* Clean-up function: You can't access anything after |
|---|
| [97] | 63 | this, until the next sensors_init() call! */ |
|---|
| [4678] | 64 | void sensors_cleanup(void); |
|---|
| [97] | 65 | |
|---|
| [4678] | 66 | /* Parse a chip name to the internal representation. Return 0 on success, <0 |
|---|
| [95] | 67 | on error. */ |
|---|
| [4678] | 68 | int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res); |
|---|
| [95] | 69 | |
|---|
| [4676] | 70 | /* Print a chip name from its internal representation. Note that chip should |
|---|
| 71 | not contain wildcard values! Return the number of characters printed on |
|---|
| 72 | success (same as snprintf), <0 on error. */ |
|---|
| 73 | int sensors_snprintf_chip_name(char *str, size_t size, |
|---|
| 74 | const sensors_chip_name *chip); |
|---|
| 75 | |
|---|
| [95] | 76 | /* Compare two chips name descriptions, to see whether they could match. |
|---|
| 77 | Return 0 if it does not match, return 1 if it does match. */ |
|---|
| [4678] | 78 | int sensors_match_chip(const sensors_chip_name *chip1, |
|---|
| 79 | const sensors_chip_name *chip2); |
|---|
| [95] | 80 | |
|---|
| [4686] | 81 | /* This function returns the adapter name of a bus, |
|---|
| [4678] | 82 | as used within the sensors_chip_name structure. If it could not be found, |
|---|
| [103] | 83 | it returns NULL */ |
|---|
| [4686] | 84 | const char *sensors_get_adapter_name(const sensors_bus_id *bus); |
|---|
| [4208] | 85 | |
|---|
| [95] | 86 | /* Look up the label which belongs to this chip. Note that chip should not |
|---|
| 87 | contain wildcard values! *result is newly allocated (free it yourself). |
|---|
| [4684] | 88 | This function will return 0 on success, and <0 on failure. |
|---|
| 89 | If no label exists for this feature, its name is returned itself. */ |
|---|
| [4678] | 90 | int sensors_get_label(const sensors_chip_name *name, int feature, |
|---|
| 91 | char **result); |
|---|
| [95] | 92 | |
|---|
| 93 | /* Read the value of a feature of a certain chip. Note that chip should not |
|---|
| 94 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 95 | on failure. */ |
|---|
| [4678] | 96 | int sensors_get_feature(const sensors_chip_name *name, int feature, |
|---|
| 97 | double *result); |
|---|
| [95] | 98 | |
|---|
| 99 | /* Set the value of a feature of a certain chip. Note that chip should not |
|---|
| 100 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| [138] | 101 | on failure. */ |
|---|
| [4678] | 102 | int sensors_set_feature(const sensors_chip_name *name, int feature, |
|---|
| 103 | double value); |
|---|
| [95] | 104 | |
|---|
| [138] | 105 | /* Execute all set statements for this particular chip. The chip may contain |
|---|
| 106 | wildcards! This function will return 0 on success, and <0 on failure. */ |
|---|
| [4678] | 107 | int sensors_do_chip_sets(const sensors_chip_name *name); |
|---|
| [138] | 108 | |
|---|
| [102] | 109 | /* This function returns all detected chips, one by one. To start at the |
|---|
| 110 | beginning of the list, use 0 for nr; NULL is returned if we are |
|---|
| [4678] | 111 | at the end of the list. Do not try to change these chip names, as |
|---|
| [102] | 112 | they point to internal structures! Do not use nr for anything else. */ |
|---|
| [4678] | 113 | const sensors_chip_name *sensors_get_detected_chips(int *nr); |
|---|
| [102] | 114 | |
|---|
| [110] | 115 | /* These defines are used in the mode field of sensors_feature_data */ |
|---|
| 116 | #define SENSORS_MODE_NO_RW 0 |
|---|
| 117 | #define SENSORS_MODE_R 1 |
|---|
| 118 | #define SENSORS_MODE_W 2 |
|---|
| 119 | #define SENSORS_MODE_RW 3 |
|---|
| 120 | |
|---|
| 121 | /* This define is used in the mapping field of sensors_feature_data if no |
|---|
| 122 | mapping is available */ |
|---|
| 123 | #define SENSORS_NO_MAPPING -1 |
|---|
| 124 | |
|---|
| [4368] | 125 | /* This enum contains some "magic" used by sensors_read_dynamic_chip() from |
|---|
| [4554] | 126 | lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of |
|---|
| [4368] | 127 | 0x100 apart, and sensor features which should not have a compute_mapping to |
|---|
| 128 | the _input feature start at 0x?10. */ |
|---|
| [4360] | 129 | typedef enum sensors_feature_type { |
|---|
| [4678] | 130 | SENSORS_FEATURE_IN = 0x000, |
|---|
| 131 | SENSORS_FEATURE_IN_MIN, |
|---|
| 132 | SENSORS_FEATURE_IN_MAX, |
|---|
| 133 | SENSORS_FEATURE_IN_ALARM = 0x010, |
|---|
| 134 | SENSORS_FEATURE_IN_MIN_ALARM, |
|---|
| 135 | SENSORS_FEATURE_IN_MAX_ALARM, |
|---|
| 136 | |
|---|
| 137 | SENSORS_FEATURE_FAN = 0x100, |
|---|
| 138 | SENSORS_FEATURE_FAN_MIN, |
|---|
| 139 | SENSORS_FEATURE_FAN_ALARM = 0x110, |
|---|
| 140 | SENSORS_FEATURE_FAN_FAULT, |
|---|
| 141 | SENSORS_FEATURE_FAN_DIV, |
|---|
| 142 | |
|---|
| 143 | SENSORS_FEATURE_TEMP = 0x200, |
|---|
| 144 | SENSORS_FEATURE_TEMP_MAX, |
|---|
| 145 | SENSORS_FEATURE_TEMP_MAX_HYST, |
|---|
| 146 | SENSORS_FEATURE_TEMP_MIN, |
|---|
| 147 | SENSORS_FEATURE_TEMP_CRIT, |
|---|
| 148 | SENSORS_FEATURE_TEMP_CRIT_HYST, |
|---|
| 149 | SENSORS_FEATURE_TEMP_ALARM = 0x210, |
|---|
| 150 | SENSORS_FEATURE_TEMP_MAX_ALARM, |
|---|
| 151 | SENSORS_FEATURE_TEMP_MIN_ALARM, |
|---|
| 152 | SENSORS_FEATURE_TEMP_CRIT_ALARM, |
|---|
| 153 | SENSORS_FEATURE_TEMP_FAULT, |
|---|
| 154 | SENSORS_FEATURE_TEMP_SENS, |
|---|
| 155 | |
|---|
| 156 | SENSORS_FEATURE_VID = 0x300, |
|---|
| 157 | |
|---|
| 158 | SENSORS_FEATURE_UNKNOWN = INT_MAX, |
|---|
| 159 | |
|---|
| 160 | /* special the largest number of subfeatures used, iow the |
|---|
| 161 | highest ## from all the 0x?## above + 1*/ |
|---|
| 162 | SENSORS_FEATURE_MAX_SUB_FEATURES = 22 |
|---|
| [4360] | 163 | } sensors_feature_type; |
|---|
| 164 | |
|---|
| [4629] | 165 | /* This structure is used when you want to get all features of a specific |
|---|
| 166 | chip. */ |
|---|
| 167 | typedef struct sensors_feature_data { |
|---|
| [4678] | 168 | int number; |
|---|
| 169 | char *name; |
|---|
| 170 | sensors_feature_type type; |
|---|
| 171 | int mapping; |
|---|
| 172 | int compute_mapping; |
|---|
| 173 | int mode; |
|---|
| [4629] | 174 | } sensors_feature_data; |
|---|
| [4366] | 175 | |
|---|
| [4629] | 176 | /* This returns all features of a specific chip. They are returned in |
|---|
| 177 | bunches: everything with the same mapping is returned just after each |
|---|
| 178 | other, with the master feature in front (that feature does not map to |
|---|
| [4643] | 179 | itself, but has SENSORS_NO_MAPPING as mapping field). nr is |
|---|
| 180 | an internally used variable. Set it to zero to start again at the |
|---|
| [4629] | 181 | begin of the list. If no more features are found NULL is returned. |
|---|
| 182 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 183 | data structures. */ |
|---|
| [4678] | 184 | const sensors_feature_data *sensors_get_all_features |
|---|
| [4666] | 185 | (const sensors_chip_name *name, int *nr); |
|---|
| [4629] | 186 | |
|---|
| [722] | 187 | #ifdef __cplusplus |
|---|
| 188 | } |
|---|
| 189 | #endif /* __cplusplus */ |
|---|
| 190 | |
|---|
| [95] | 191 | #endif /* def LIB_SENSORS_ERROR_H */ |
|---|