X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=5be048ee2f6bb5cd6a125946597331439d1adb52;hb=9a712780735732606accbdece91eaeff366e220d;hp=c399544606b2ec8cb4850bd108914a0324f5140c;hpb=b01d095d6b123bcc7ed221cccf2c04295834cc84;p=psensor.git diff --git a/src/lib/psensor.c b/src/lib/psensor.c index c399544..5be048e 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,20 +31,19 @@ #include "cpu.h" #endif - 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)); + struct psensor *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; @@ -65,6 +64,7 @@ struct psensor *psensor_create(char *id, psensor->color = NULL; + psensor->graph_enabled = 1; psensor->appindicator_enabled = 0; return psensor; @@ -160,7 +160,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++; } @@ -233,6 +233,9 @@ psensor_value_to_str(unsigned int type, double value, int use_celcius) 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); return str; @@ -256,9 +259,7 @@ void psensor_set_current_value(struct psensor *sensor, double value) psensor_set_current_measure(sensor, value, tv); } -void -psensor_set_current_measure(struct psensor *s, - double v, struct timeval tv) +void psensor_set_current_measure(struct psensor *s, double v, struct timeval tv) { memmove(s->measures, &s->measures[1], @@ -285,7 +286,7 @@ psensor_set_current_measure(struct psensor *s, } } -double psensor_get_current_value(struct psensor *sensor) +double psensor_get_current_value(const struct psensor *sensor) { return sensor->measures[sensor->values_max_length - 1].value; } @@ -299,7 +300,7 @@ struct measure *psensor_get_current_measure(struct psensor *sensor) Returns the minimal value of a given 'type' (SENSOR_TYPE_TEMP or SENSOR_TYPE_FAN) */ -double get_min_value(struct psensor **sensors, int type) +static double get_min_value(struct psensor **sensors, int type) { double m = UNKNOWN_DBL_VALUE; struct psensor **s = sensors; @@ -307,7 +308,7 @@ double get_min_value(struct psensor **sensors, int type) while (*s) { struct psensor *sensor = *s; - if (sensor->enabled && (sensor->type & type)) { + if (sensor->type & type) { int i; double t; @@ -339,7 +340,7 @@ double get_max_value(struct psensor **sensors, int type) while (*s) { struct psensor *sensor = *s; - if (sensor->enabled && (sensor->type & type)) { + if (sensor->type & type) { int i; double t; for (i = 0; i < sensor->values_max_length; i++) { @@ -367,7 +368,7 @@ psensor_get_max_current_value(struct psensor **sensors, unsigned int type) while (*s_cur) { struct psensor *s = *s_cur; - if (s->enabled && (s->type & type)) { + if (s->graph_enabled && (s->type & type)) { double v = psensor_get_current_value(s); if (m == UNKNOWN_DBL_VALUE || v > m) @@ -402,7 +403,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 +437,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_AMD_TEMP) == SENSOR_TYPE_AMD_TEMP) - return "AMD GPU Temperature"; + if (type & SENSOR_TYPE_NVCTRL) + return "NVidia GPU"; - 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,10 +461,13 @@ 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"; } @@ -488,12 +495,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 } @@ -519,3 +525,48 @@ 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; +} + +char * +psensor_current_value_to_str(const struct psensor *s, unsigned int celcius) +{ + return psensor_value_to_str(s->type, + psensor_get_current_value(s), + celcius); +} + +struct psensor **psensor_list_filter_graph_enabled(struct psensor **sensors) +{ + int n, i; + struct psensor **result, **cur, *s; + + if (!sensors) + return NULL; + + n = psensor_list_size(sensors); + result = malloc((n+1) * sizeof(struct psensor *)); + + for (cur = sensors, i = 0; *cur; cur++) { + s = *cur; + + if (s->graph_enabled) + result[i++] = s; + } + + result[i] = NULL; + + return result; +}