X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=835741fbfb102c424d26aad8ff5c10fb08afeb8b;hb=f606bd3f16446091d0b88255a497a64e3f623aa3;hp=128dc0251b6ee59ccee53c83181900379b2c3818;hpb=845932214067b9137c7e2cf85be692673857ad4d;p=psensor.git diff --git a/src/lib/psensor.c b/src/lib/psensor.c index 128dc02..835741f 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.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-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 + */ #include #include @@ -28,6 +27,11 @@ #include "psensor.h" #include "lmsensor.h" +#ifdef HAVE_GTOP +#include "cpu.h" +#endif + + struct psensor *psensor_create(char *id, char *name, unsigned int type, int values_max_length) { @@ -204,6 +208,8 @@ char *psensor_value_to_string(unsigned int type, double value) if (is_temp_type(type)) unit = "C"; + else if (type & SENSOR_TYPE_CPU_USAGE) + unit = "%"; else unit = ""; @@ -298,7 +304,7 @@ double get_min_value(struct psensor **sensors, int type) Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or SENSOR_TYPE_FAN) */ -static double get_max_value(struct psensor **sensors, int type) +double get_max_value(struct psensor **sensors, int type) { double m = UNKNOWN_DBL_VALUE; struct psensor **s = sensors; @@ -375,7 +381,6 @@ struct psensor **get_all_sensors(int values_max_length) psensors = lmsensor_psensor_list_add(NULL, values_max_length); tmp_psensors = hdd_psensor_list_add(psensors, values_max_length); - if (tmp_psensors != psensors) { free(psensors); psensors = tmp_psensors; @@ -391,20 +396,29 @@ struct psensor **get_all_sensors(int values_max_length) const char *psensor_type_to_str(unsigned int type) { - if (type & SENSOR_TYPE_REMOTE) - return "Remote"; + if ((type & SENSOR_TYPE_NVIDIA_TEMP) == SENSOR_TYPE_NVIDIA_TEMP) + return "NVidia GPU Temperature"; + + if ((type & SENSOR_TYPE_AMD_TEMP) == SENSOR_TYPE_AMD_TEMP) + return "AMD GPU Temperature"; + + if ((type & SENSOR_TYPE_AMD_FAN) == SENSOR_TYPE_AMD_FAN) + return "AMD GPU Fan Speed"; - if (type & SENSOR_TYPE_LMSENSOR_TEMP) + if ((type & SENSOR_TYPE_HDD_TEMP) == SENSOR_TYPE_HDD_TEMP) + return "HDD Temperature"; + + if (type & SENSOR_TYPE_CPU_USAGE) + return "CPU Usage"; + + if (type & SENSOR_TYPE_TEMP) return "Temperature"; - if (type & SENSOR_TYPE_LMSENSOR_FAN) + if (type & SENSOR_TYPE_FAN) return "Fan"; - if (type & SENSOR_TYPE_NVIDIA) - return "NVidia GPU Temperature"; - - if (type & SENSOR_TYPE_HDD_TEMP) - return "HDD Temperature"; + if (type & SENSOR_TYPE_REMOTE) + return "Remote"; return "N/A"; /* should not be possible */ } @@ -418,6 +432,9 @@ const char *psensor_type_to_unit_str(unsigned int type) if (type & SENSOR_TYPE_FAN) return _("RPM"); + if (type & SENSOR_TYPE_CPU_USAGE) + return _("%"); + return "N/A"; } @@ -425,7 +442,13 @@ void psensor_list_update_measures(struct psensor **sensors) { lmsensor_psensor_list_update(sensors); - if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP)) +#ifdef HAVE_GTOP + cpu_psensor_list_update(sensors); +#endif + + if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP_HDDTEMP) + || psensor_list_contains_type(sensors, + SENSOR_TYPE_HDD_TEMP_ATASMART)) hdd_psensor_list_update(sensors); }