2 Copyright (C) 2010-2011 jeanfi@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 return lmsensor_get_value(chip, sf);
65 double lmsensor_get_fan_input(struct psensor *sensor)
67 const sensors_chip_name *chip = sensor->iname;
68 const sensors_feature *feature = sensor->feature;
70 const sensors_subfeature *sf;
72 sf = sensors_get_subfeature(chip,
73 feature, SENSORS_SUBFEATURE_FAN_INPUT);
75 return lmsensor_get_value(chip, sf);
80 void lmsensor_psensor_list_update(struct psensor **sensors)
82 struct psensor **s_ptr = sensors;
85 struct psensor *sensor = *s_ptr;
87 if (sensor->type == SENSOR_TYPE_LMSENSOR_TEMP)
88 psensor_set_current_value
89 (sensor, lmsensor_get_temp_input(sensor));
90 else if (sensor->type == SENSOR_TYPE_LMSENSOR_FAN)
91 psensor_set_current_value
92 (sensor, lmsensor_get_fan_input(sensor));
99 lmsensor_psensor_create(const sensors_chip_name *chip,
100 const sensors_feature *feature,
101 int values_max_length)
104 const sensors_subfeature *sf;
108 struct psensor *psensor;
109 sensors_subfeature_type fault_subfeature;
111 if (sensors_snprintf_chip_name(name, 200, chip) < 0)
114 if (feature->type == SENSORS_FEATURE_TEMP) {
115 fault_subfeature = SENSORS_SUBFEATURE_TEMP_FAULT;
117 } else if (feature->type == SENSORS_FEATURE_FAN) {
118 fault_subfeature = SENSORS_SUBFEATURE_FAN_FAULT;
122 _("ERROR: create_sensor, wrong feature type\n"));
126 sf = sensors_get_subfeature(chip, feature, fault_subfeature);
127 if (sf && lmsensor_get_value(chip, sf))
130 label = sensors_get_label(chip, feature);
135 if (feature->type == SENSORS_FEATURE_TEMP)
136 type = SENSOR_TYPE_LMSENSOR_TEMP;
137 else if (feature->type == SENSORS_FEATURE_FAN)
138 type = SENSOR_TYPE_LMSENSOR_FAN;
142 id = malloc(strlen("lmsensor ") + 1 + strlen(name) + 1 + strlen(label) +
144 sprintf(id, "lmsensor %s %s", name, label);
146 psensor = psensor_create(id, label, type, values_max_length);
148 psensor->iname = chip;
149 psensor->feature = feature;
151 if (feature->type == SENSORS_FEATURE_TEMP
152 && (lmsensor_get_temp_input(psensor) == UNKNOWN_VALUE)) {
162 int err = sensors_init(NULL);
166 _("ERROR: lm-sensors initialization failure: %s\n"),
167 sensors_strerror(err));