X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Flmsensor.c;h=84b36b35abc4f1cab6944a791b997ca8433be237;hb=cc35e177d57bc4ee2cc57ae25f130dfc168aa61d;hp=48850f158429f57c005dc0af132c21f6bc236053;hpb=4baa2d781c883c79cc7f5e33e253c5e1b00a1575;p=psensor.git diff --git a/src/lib/lmsensor.c b/src/lib/lmsensor.c index 48850f1..84b36b3 100644 --- a/src/lib/lmsensor.c +++ b/src/lib/lmsensor.c @@ -1,22 +1,21 @@ /* - Copyright (C) 2010-2011 jeanfi@gmail.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - + * Copyright (C) 2010-2013 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ #include #include #define _(str) gettext(str) @@ -40,8 +39,7 @@ static double get_value(const sensors_chip_name *name, err = sensors_get_value(name, sub->number, &val); if (err) { - fprintf(stderr, - _("ERROR: Can't get value of subfeature %s: %s\n"), + log_err(_("lmsensor: cannot get value of subfeature %s: %s."), sub->name, sensors_strerror(err)); val = UNKNOWN_DBL_VALUE; } @@ -86,14 +84,15 @@ void lmsensor_psensor_list_update(struct psensor **sensors) return ; while (*s_ptr) { - struct psensor *sensor = *s_ptr; - - if (sensor->type == SENSOR_TYPE_LMSENSOR_TEMP) - psensor_set_current_value - (sensor, get_temp_input(sensor)); - else if (sensor->type == SENSOR_TYPE_LMSENSOR_FAN) - psensor_set_current_value(sensor, - get_fan_input(sensor)); + struct psensor *s = *s_ptr; + + if (s->type & SENSOR_TYPE_LMSENSOR) { + if (s->type & SENSOR_TYPE_TEMP) + psensor_set_current_value(s, + get_temp_input(s)); + else if (s->type & SENSOR_TYPE_RPM) + psensor_set_current_value(s, get_fan_input(s)); + } s_ptr++; } @@ -106,9 +105,8 @@ lmsensor_psensor_create(const sensors_chip_name *chip, { char name[200]; const sensors_subfeature *sf; - char *label; int type; - char *id; + char *id, *label, *cname; struct psensor *psensor; sensors_subfeature_type fault_subfeature; @@ -117,13 +115,11 @@ lmsensor_psensor_create(const sensors_chip_name *chip, if (feature->type == SENSORS_FEATURE_TEMP) { fault_subfeature = SENSORS_SUBFEATURE_TEMP_FAULT; - } else if (feature->type == SENSORS_FEATURE_FAN) { fault_subfeature = SENSORS_SUBFEATURE_FAN_FAULT; - } else { - fprintf(stderr, - _("ERROR: create_sensor, wrong feature type\n")); + log_err(_( +"lmsensor: lmsensor_psensor_create failure: wrong feature type.")); return NULL; } @@ -135,11 +131,11 @@ lmsensor_psensor_create(const sensors_chip_name *chip, if (!label) return NULL; - type = 0; + type = SENSOR_TYPE_LMSENSOR; if (feature->type == SENSORS_FEATURE_TEMP) - type = SENSOR_TYPE_LMSENSOR_TEMP; + type |= SENSOR_TYPE_TEMP; else if (feature->type == SENSORS_FEATURE_FAN) - type = SENSOR_TYPE_LMSENSOR_FAN; + type |= (SENSOR_TYPE_RPM|SENSOR_TYPE_FAN); else return NULL; @@ -147,7 +143,20 @@ lmsensor_psensor_create(const sensors_chip_name *chip, 1); sprintf(id, "lmsensor %s %s", name, label); - psensor = psensor_create(id, label, type, values_max_length); + if (!strcmp(chip->prefix, "coretemp")) + cname = strdup("Intel CPU"); + else if (!strcmp(chip->prefix, "k10temp") + || !strcmp(chip->prefix, "k8temp") + || !strcmp(chip->prefix, "fam15h_power")) + cname = strdup("AMD CPU"); + else if (!strcmp(chip->prefix, "nouveau")) + cname = strdup("Nvidia GPU"); + else if (!strcmp(chip->prefix, "via-cputemp")) + cname = strdup("VIA CPU"); + else + cname = strdup(chip->prefix); + + psensor = psensor_create(id, label, cname, type, values_max_length); psensor->iname = chip; psensor->feature = feature; @@ -172,7 +181,7 @@ struct psensor **lmsensor_psensor_list_add(struct psensor **sensors, int i; if (!init_done) - return ; + return NULL; result = sensors; while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) { @@ -205,8 +214,7 @@ void lmsensor_init() int err = sensors_init(NULL); if (err) { - fprintf(stderr, - _("ERROR: lm-sensors initialization failure: %s\n"), + log_err(_("lmsensor: initialization failure: %s."), sensors_strerror(err)); init_done = 0; } else {