X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=8b92c0100de23509fe10232dda8ef3901f201eec;hb=f3b05dae619a7909bd7422b3a82422c9442aa114;hp=bf7765bcfa31757b891cde5fa01d04326e476173;hpb=dcf1b53921f5f9fdab59295be938c766bb572793;p=psensor.git diff --git a/src/lib/psensor.c b/src/lib/psensor.c index bf7765b..8b92c01 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013 jeanfi@gmail.com + * Copyright (C) 2010-2014 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 @@ -37,13 +37,13 @@ struct psensor *psensor_create(char *id, 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; @@ -64,6 +64,7 @@ struct psensor *psensor_create(char *id, psensor->color = NULL; + psensor->graph_enabled = 1; psensor->appindicator_enabled = 0; return psensor; @@ -258,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], @@ -301,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; @@ -309,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; @@ -341,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++) { @@ -369,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) @@ -548,3 +547,26 @@ psensor_current_value_to_str(const struct psensor *s, unsigned int celcius) 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; +}