renamed alarm_limit to alarm_high_thresold
[psensor.git] / src / lib / psensor.h
1 /*
2  * Copyright (C) 2010-2012 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #ifndef _PSENSOR_PSENSOR_H_
20 #define _PSENSOR_PSENSOR_H_
21
22 #include "config.h"
23 #include <sensors/sensors.h>
24
25 #ifdef HAVE_ATASMART
26 #include <atasmart.h>
27 #endif
28
29 #include "color.h"
30 #include "log.h"
31 #include "measure.h"
32
33 enum psensor_type {
34         SENSOR_TYPE_TEMP = 0x0001,
35         SENSOR_TYPE_FAN = 0x0002,
36         SENSOR_TYPE_REMOTE = 0x0004,
37
38         SENSOR_TYPE_LMSENSOR = 0x0100,
39         SENSOR_TYPE_NVIDIA_TEMP = 0x0200 | SENSOR_TYPE_TEMP,
40         SENSOR_TYPE_HDD_TEMP = 0x0400 | SENSOR_TYPE_TEMP,
41         SENSOR_TYPE_CPU_USAGE = 0x0800,
42         SENSOR_TYPE_AMD = 0x1000,
43
44         SENSOR_TYPE_HDD_TEMP_ATASMART = 0x2000 | SENSOR_TYPE_HDD_TEMP,
45         SENSOR_TYPE_HDD_TEMP_HDDTEMP = 0x4000 | SENSOR_TYPE_HDD_TEMP,
46
47         SENSOR_TYPE_AMD_TEMP = SENSOR_TYPE_AMD | SENSOR_TYPE_TEMP,
48         SENSOR_TYPE_AMD_FAN = SENSOR_TYPE_AMD | SENSOR_TYPE_FAN,
49
50         SENSOR_TYPE_LMSENSOR_TEMP = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP,
51         SENSOR_TYPE_LMSENSOR_FAN = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_FAN
52 };
53
54 struct psensor {
55         /* Human readable name of the sensor.  It may not be uniq. */
56         char *name;
57
58         /* Uniq id of the sensor */
59         char *id;
60
61         /* lm-sensor */
62         const sensors_chip_name *iname;
63         const sensors_feature *feature;
64
65         /* Maximum length of 'values' */
66         int values_max_length;
67
68         /* Last registered measures of the sensor.  Index 0 for the
69            oldest measure.  */
70         struct measure *measures;
71
72         /* Color of the sensor used for the graph */
73         struct color *color;
74
75         /* Whether the sensor is displayed in the graph */
76         int enabled;
77
78         /* see psensor_type */
79         unsigned int type;
80
81         /* The maximum detected value of the sensor */
82         double max;
83
84         /* The minimum detected value of the sensor */
85         double min;
86
87         /* Whether alarm alert is enabled for this sensor */
88         unsigned int alarm_enabled;
89
90         int alarm_high_thresold;
91
92         /* Whether the current value is bigger than 'alarm_high_thresold'. */
93         int alarm_raised;
94
95         void (*cb_alarm_raised) (struct psensor *, void *);
96         void *cb_alarm_raised_data;
97
98 #ifdef HAVE_NVIDIA
99         /* Nvidia id for the nvctrl */
100         int nvidia_id;
101 #endif
102 #ifdef HAVE_LIBATIADL
103         /* AMD id for the aticonfig */
104         int amd_id;
105 #endif
106 #ifdef HAVE_ATASMART
107         SkDisk *disk;
108 #endif
109
110         char *url;
111 };
112
113 struct psensor *psensor_create(char *id,
114                                char *name, unsigned int type,
115                                int values_max_length);
116
117 void psensor_values_resize(struct psensor *s, int new_size);
118
119 void psensor_free(struct psensor *sensor);
120
121 void psensor_list_free(struct psensor **sensors);
122 int psensor_list_size(struct psensor **sensors);
123
124 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
125                                        const char *id);
126
127 /*
128   Return 1 if there is at least one sensor of a given type, else
129   returns 0 */
130 int psensor_list_contains_type(struct psensor **sensors, unsigned int type);
131
132 int is_temp_type(unsigned int type);
133 int is_fan_type(unsigned int type);
134
135 double get_min_temp(struct psensor **sensors);
136 double get_max_temp(struct psensor **sensors);
137
138 double get_min_rpm(struct psensor **sensors);
139 double get_max_rpm(struct psensor **sensors);
140
141 /*
142   Get the maximal current value of all sensors of a given type.
143 */
144 double
145 psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
146
147 /*
148   Converts the value of a sensor to a string.
149
150   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
151   or SENSOR_TYPE_LMSENSOR_FAN
152 */
153 char *psensor_value_to_str(unsigned int type,
154                            double value,
155                            int use_celcius);
156
157 char *psensor_measure_to_str(const struct measure *m,
158                              unsigned int type,
159                              unsigned int use_celcius);
160
161 struct psensor **get_all_sensors(int use_libatasmart, int values_max_length);
162
163 struct psensor **psensor_list_add(struct psensor **sensors,
164                                   struct psensor *sensor);
165
166 void psensor_set_current_value(struct psensor *sensor, double value);
167 void psensor_set_current_measure(struct psensor *sensor, double value,
168                                  struct timeval tv);
169
170 double psensor_get_current_value(struct psensor *sensor);
171
172 struct measure *psensor_get_current_measure(struct psensor *sensor);
173
174 /*
175   Returns a string representation of a psensor type.
176 */
177 const char *psensor_type_to_str(unsigned int type);
178
179 const char *psensor_type_to_unit_str(unsigned int type, int use_celcius);
180
181 void psensor_list_update_measures(struct psensor **sensors);
182
183 void psensor_init();
184
185 void psensor_cleanup();
186
187 double get_max_value(struct psensor **sensors, int type);
188
189 double celcius_to_fahrenheit(double c);
190 double fahrenheit_to_celcius(double c);
191
192
193 void psensor_log_measures(struct psensor **sensors);
194
195 #endif