2
Copyright (C) 2010-2011 wpitchoune@gmail.com
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
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
22
#define _(str) gettext(str)
28
#include <sensors/sensors.h>
29
#include <sensors/error.h>
34
lmsensor_get_value(const sensors_chip_name *name,
35
const sensors_subfeature *sub)
40
err = sensors_get_value(name, sub->number, &val);
43
_("ERROR: Can't get value of subfeature %s: %s\n"),
44
sub->name, sensors_strerror(err));
50
double lmsensor_get_temp_input(struct psensor *sensor)
52
const sensors_chip_name *chip = sensor->iname;
53
const sensors_feature *feature = sensor->feature;
55
const sensors_subfeature *sf;
57
sf = sensors_get_subfeature(chip,
58
feature, SENSORS_SUBFEATURE_TEMP_INPUT);
60
double val = lmsensor_get_value(chip, sf);
70
double lmsensor_get_fan_input(struct psensor *sensor)
72
const sensors_chip_name *chip = sensor->iname;
73
const sensors_feature *feature = sensor->feature;
75
const sensors_subfeature *sf;
77
sf = sensors_get_subfeature(chip,
78
feature, SENSORS_SUBFEATURE_FAN_INPUT);
80
return lmsensor_get_value(chip, sf);
85
void lmsensor_psensor_list_update(struct psensor **sensors)
87
struct psensor **s_ptr = sensors;
90
struct psensor *sensor = *s_ptr;
92
if (sensor->type == SENSOR_TYPE_LMSENSOR_TEMP)
93
psensor_set_current_value
94
(sensor, lmsensor_get_temp_input(sensor));
95
else if (sensor->type == SENSOR_TYPE_LMSENSOR_FAN)
96
psensor_set_current_value
97
(sensor, lmsensor_get_fan_input(sensor));
104
lmsensor_psensor_create(const sensors_chip_name *chip,
105
const sensors_feature *feature,
106
int values_max_length)
109
const sensors_subfeature *sf;
113
struct psensor *psensor;
114
sensors_subfeature_type fault_subfeature;
116
if (sensors_snprintf_chip_name(name, 200, chip) < 0)
119
if (feature->type == SENSORS_FEATURE_TEMP) {
120
fault_subfeature = SENSORS_SUBFEATURE_TEMP_FAULT;
122
} else if (feature->type == SENSORS_FEATURE_FAN) {
123
fault_subfeature = SENSORS_SUBFEATURE_FAN_FAULT;
127
_("ERROR: create_sensor, wrong feature type\n"));
131
sf = sensors_get_subfeature(chip, feature, fault_subfeature);
132
if (sf && lmsensor_get_value(chip, sf))
135
label = sensors_get_label(chip, feature);
140
if (feature->type == SENSORS_FEATURE_TEMP)
141
type = SENSOR_TYPE_LMSENSOR_TEMP;
142
else if (feature->type == SENSORS_FEATURE_FAN)
143
type = SENSOR_TYPE_LMSENSOR_FAN;
147
id = malloc(strlen("lmsensor ") + 1 + strlen(name) + 1 + strlen(label) +
149
sprintf(id, "lmsensor %s %s", name, label);
151
psensor = psensor_create(id, strdup(label), type, values_max_length);
153
psensor->iname = chip;
154
psensor->feature = feature;
156
if (feature->type == SENSORS_FEATURE_TEMP
157
&& (lmsensor_get_temp_input(psensor) <= 0.0)) {
167
int err = sensors_init(NULL);
171
_("ERROR: lm-sensors initialization failure: %s\n"),
172
sensors_strerror(err));