| 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 | /* Look up the label which belongs to this chip. Note that chip should not |
|---|
| 86 | contain wildcard values! The returned string is newly allocated (free it |
|---|
| 87 | yourself). On failure, NULL is returned. |
|---|
| 88 | If no label exists for this feature, its name is returned itself. */ |
|---|
| 89 | char *sensors_get_label(const sensors_chip_name *name, int feature); |
|---|
| 90 | |
|---|
| 91 | /* Read the value of a feature of a certain chip. Note that chip should not |
|---|
| 92 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 93 | on failure. */ |
|---|
| 94 | int sensors_get_value(const sensors_chip_name *name, int feature, |
|---|
| 95 | double *value); |
|---|
| 96 | |
|---|
| 97 | /* Set the value of a feature of a certain chip. Note that chip should not |
|---|
| 98 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 99 | on failure. */ |
|---|
| 100 | int sensors_set_value(const sensors_chip_name *name, int feature, |
|---|
| 101 | double value); |
|---|
| 102 | |
|---|
| 103 | /* Execute all set statements for this particular chip. The chip may contain |
|---|
| 104 | wildcards! This function will return 0 on success, and <0 on failure. */ |
|---|
| 105 | int sensors_do_chip_sets(const sensors_chip_name *name); |
|---|
| 106 | |
|---|
| 107 | /* This function returns all detected chips that match a given chip name, |
|---|
| 108 | one by one. If no chip name is provided, all detected chips are returned. |
|---|
| 109 | To start at the beginning of the list, use 0 for nr; NULL is returned if |
|---|
| 110 | we are at the end of the list. Do not try to change these chip names, as |
|---|
| 111 | they point to internal structures! */ |
|---|
| 112 | const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name |
|---|
| 113 | *match, int *nr); |
|---|
| 114 | |
|---|
| 115 | /* These defines are used in the flags field of sensors_feature_data */ |
|---|
| 116 | #define SENSORS_MODE_R 1 |
|---|
| 117 | #define SENSORS_MODE_W 2 |
|---|
| 118 | #define SENSORS_COMPUTE_MAPPING 4 |
|---|
| 119 | |
|---|
| 120 | /* This define is used in the mapping field of sensors_feature_data if no |
|---|
| 121 | mapping is available */ |
|---|
| 122 | #define SENSORS_NO_MAPPING -1 |
|---|
| 123 | |
|---|
| 124 | /* This enum contains some "magic" used by sensors_read_dynamic_chip() from |
|---|
| 125 | lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of |
|---|
| 126 | 0x100 apart, and sensor features which should not have a compute mapping to |
|---|
| 127 | the _input feature start at 0x?10. */ |
|---|
| 128 | typedef enum sensors_feature_type { |
|---|
| 129 | SENSORS_FEATURE_IN = 0x000, |
|---|
| 130 | SENSORS_FEATURE_IN_MIN, |
|---|
| 131 | SENSORS_FEATURE_IN_MAX, |
|---|
| 132 | SENSORS_FEATURE_IN_ALARM = 0x010, |
|---|
| 133 | SENSORS_FEATURE_IN_MIN_ALARM, |
|---|
| 134 | SENSORS_FEATURE_IN_MAX_ALARM, |
|---|
| 135 | |
|---|
| 136 | SENSORS_FEATURE_FAN = 0x100, |
|---|
| 137 | SENSORS_FEATURE_FAN_MIN, |
|---|
| 138 | SENSORS_FEATURE_FAN_ALARM = 0x110, |
|---|
| 139 | SENSORS_FEATURE_FAN_FAULT, |
|---|
| 140 | SENSORS_FEATURE_FAN_DIV, |
|---|
| 141 | |
|---|
| 142 | SENSORS_FEATURE_TEMP = 0x200, |
|---|
| 143 | SENSORS_FEATURE_TEMP_MAX, |
|---|
| 144 | SENSORS_FEATURE_TEMP_MAX_HYST, |
|---|
| 145 | SENSORS_FEATURE_TEMP_MIN, |
|---|
| 146 | SENSORS_FEATURE_TEMP_CRIT, |
|---|
| 147 | SENSORS_FEATURE_TEMP_CRIT_HYST, |
|---|
| 148 | SENSORS_FEATURE_TEMP_ALARM = 0x210, |
|---|
| 149 | SENSORS_FEATURE_TEMP_MAX_ALARM, |
|---|
| 150 | SENSORS_FEATURE_TEMP_MIN_ALARM, |
|---|
| 151 | SENSORS_FEATURE_TEMP_CRIT_ALARM, |
|---|
| 152 | SENSORS_FEATURE_TEMP_FAULT, |
|---|
| 153 | SENSORS_FEATURE_TEMP_TYPE, |
|---|
| 154 | |
|---|
| 155 | SENSORS_FEATURE_VID = 0x1000, |
|---|
| 156 | |
|---|
| 157 | SENSORS_FEATURE_BEEP_ENABLE = 0x1100, |
|---|
| 158 | |
|---|
| 159 | SENSORS_FEATURE_UNKNOWN = INT_MAX, |
|---|
| 160 | } sensors_feature_type; |
|---|
| 161 | |
|---|
| 162 | /* This structure is used when you want to get all features of a specific |
|---|
| 163 | chip. */ |
|---|
| 164 | typedef struct sensors_feature_data { |
|---|
| 165 | char *name; |
|---|
| 166 | int number; |
|---|
| 167 | sensors_feature_type type; |
|---|
| 168 | int mapping; |
|---|
| 169 | unsigned int flags; |
|---|
| 170 | } sensors_feature_data; |
|---|
| 171 | |
|---|
| 172 | /* This returns all features of a specific chip. They are returned in |
|---|
| 173 | bunches: everything with the same mapping is returned just after each |
|---|
| 174 | other, with the master feature in front (that feature does not map to |
|---|
| 175 | itself, but has SENSORS_NO_MAPPING as mapping field). nr is |
|---|
| 176 | an internally used variable. Set it to zero to start again at the |
|---|
| 177 | begin of the list. If no more features are found NULL is returned. |
|---|
| 178 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 179 | data structures. */ |
|---|
| 180 | const sensors_feature_data *sensors_get_all_features |
|---|
| 181 | (const sensors_chip_name *name, int *nr); |
|---|
| 182 | |
|---|
| 183 | #ifdef __cplusplus |
|---|
| 184 | } |
|---|
| 185 | #endif /* __cplusplus */ |
|---|
| 186 | |
|---|
| 187 | #endif /* def LIB_SENSORS_ERROR_H */ |
|---|