X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=2ae60119b14c576609edb6b098455576b1dd5837;hb=c4b37e0535dfb2caa60fc49c2bb4b01124d91109;hp=5726b2d4581e23d94ce1e398690e62967aee45bc;hpb=85925e68a92452f4b8acd66118a579204c6df4d5;p=psensor.git diff --git a/src/lib/psensor.c b/src/lib/psensor.c index 5726b2d..2ae6011 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 jeanfi@gmail.com + * 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 @@ -31,15 +31,18 @@ #include "cpu.h" #endif - -struct psensor *psensor_create(char *id, char *name, - unsigned int type, int values_max_length) +struct psensor *psensor_create(char *id, + char *name, + char *chip, + unsigned int type, + int values_max_length) { struct psensor *psensor = (struct psensor *)malloc(sizeof(struct psensor)); psensor->id = id; psensor->name = name; + psensor->chip = chip; psensor->enabled = 1; psensor->min = UNKNOWN_DBL_VALUE; psensor->max = UNKNOWN_DBL_VALUE; @@ -50,8 +53,8 @@ struct psensor *psensor_create(char *id, char *name, psensor->measures = measures_dbl_create(values_max_length); psensor->alarm_enabled = 0; - psensor->alarm_high_thresold = 0; - psensor->alarm_low_thresold = 0; + psensor->alarm_high_threshold = 0; + psensor->alarm_low_threshold = 0; psensor->cb_alarm_raised = NULL; psensor->cb_alarm_raised_data = NULL; @@ -61,6 +64,8 @@ struct psensor *psensor_create(char *id, char *name, psensor->color = NULL; + psensor->appindicator_enabled = 0; + return psensor; } @@ -94,6 +99,9 @@ void psensor_free(struct psensor *sensor) free(sensor->name); free(sensor->id); + if (sensor->chip) + free(sensor->chip); + if (sensor->color) free(sensor->color); @@ -151,7 +159,7 @@ int psensor_list_contains_type(struct psensor **sensors, unsigned int type) s = sensors; while (*s) { - if ((*s)->type == type) + if ((*s)->type & type) return 1; s++; } @@ -213,25 +221,19 @@ double fahrenheit_to_celcius(double f) char * psensor_value_to_str(unsigned int type, double value, int use_celcius) { - /* should not be possible to exceed 20 characters with temp or - rpm values the .x part is never displayed */ - char *str = malloc(20); + char *str; + const char *unit; - char *unit; + /* + * should not be possible to exceed 20 characters with temp or + * rpm values the .x part is never displayed + */ + str = malloc(20); - if (is_temp_type(type)) - if (use_celcius) { - unit = "°C"; - } else { - unit = "°F"; - value = celcius_to_fahrenheit(value); - } - else if (is_fan_type(type)) - unit = _("RPM"); - else if (type & SENSOR_TYPE_CPU_USAGE) - unit = _("%"); - else - unit = _("N/A"); + unit = psensor_type_to_unit_str(type, use_celcius); + + if (is_temp_type(type) && !use_celcius) + value = celcius_to_fahrenheit(value); sprintf(str, "%.0f%s", value, unit); @@ -274,7 +276,7 @@ psensor_set_current_measure(struct psensor *s, s->max = v; if (s->alarm_enabled) { - if (v > s->alarm_high_thresold || v < s->alarm_low_thresold) { + if (v > s->alarm_high_threshold || v < s->alarm_low_threshold) { if (!s->alarm_raised && s->cb_alarm_raised) s->cb_alarm_raised(s, s->cb_alarm_raised_data); @@ -402,7 +404,7 @@ double get_max_temp(struct psensor **sensors) struct psensor **get_all_sensors(int use_libatasmart, int values_max_length) { - struct psensor **psensors = NULL; + struct psensor **psensors; struct psensor **tmp_psensors; psensors = lmsensor_psensor_list_add(NULL, values_max_length); @@ -436,19 +438,22 @@ struct psensor **get_all_sensors(int use_libatasmart, int values_max_length) const char *psensor_type_to_str(unsigned int type) { - if ((type & SENSOR_TYPE_NVIDIA_TEMP) == SENSOR_TYPE_NVIDIA_TEMP) - return "NVidia GPU Temperature"; + if (type & SENSOR_TYPE_NVCTRL) + return "NVidia GPU"; - 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_ATIADL) { + if (type & SENSOR_TYPE_TEMP) + return "AMD GPU Temperature"; + else if (type & SENSOR_TYPE_RPM) + return "AMD GPU Fan Speed"; + else /* type & SENSOR_TYPE_USAGE */ + return "AMD GPU Usage"; + } if ((type & SENSOR_TYPE_HDD_TEMP) == SENSOR_TYPE_HDD_TEMP) return "HDD Temperature"; - if (type & SENSOR_TYPE_CPU_USAGE) + if ((type & SENSOR_TYPE_CPU_USAGE) == SENSOR_TYPE_CPU_USAGE) return "CPU Usage"; if (type & SENSOR_TYPE_TEMP) @@ -457,29 +462,30 @@ const char *psensor_type_to_str(unsigned int type) if (type & SENSOR_TYPE_FAN) return "Fan"; + if (type & SENSOR_TYPE_CPU) + return "CPU"; + if (type & SENSOR_TYPE_REMOTE) return "Remote"; - return "N/A"; /* should not be possible */ + return "N/A"; } const char *psensor_type_to_unit_str(unsigned int type, int use_celcius) { - if (type & SENSOR_TYPE_TEMP) { + if (is_temp_type(type)) { if (use_celcius) return "\302\260C"; else return "\302\260F"; - } - - if (type & SENSOR_TYPE_FAN) + } else if (is_fan_type(type)) { return _("RPM"); - - if (type & SENSOR_TYPE_CPU_USAGE) + } else if (type & SENSOR_TYPE_CPU_USAGE) { return _("%"); - - return _("N/A"); + } else { + return _("N/A"); + } } void psensor_list_update_measures(struct psensor **sensors) @@ -490,12 +496,11 @@ void psensor_list_update_measures(struct psensor **sensors) cpu_psensor_list_update(sensors); #endif - if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP_HDDTEMP)) + if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDDTEMP)) hddtemp_psensor_list_update(sensors); #ifdef HAVE_ATASMART - if (psensor_list_contains_type(sensors, - SENSOR_TYPE_HDD_TEMP_ATASMART)) + if (psensor_list_contains_type(sensors, SENSOR_TYPE_ATASMART)) hdd_psensor_list_update(sensors); #endif } @@ -521,3 +526,18 @@ void psensor_cleanup() { lmsensor_cleanup(); } + +struct psensor **psensor_list_copy(struct psensor **sensors) +{ + struct psensor **result; + int n, i; + + n = psensor_list_size(sensors); + result = malloc((n+1) * sizeof(struct psensor *)); + for (i = 0; i < n; i++) + result[i] = sensors[i]; + result[n] = NULL; + + return result; +} +