X-Git-Url: http://git.wpitchoune.net/gitweb/?p=psensor.git;a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=f8c0a83a79a367d2ce6ec8eade3df2d30b46273a;hp=58731d50416afaab938b9c839e532fad49953240;hb=dd9cbee87e002a9954d5f9dd743311cccd4cedef;hpb=837c8ac28740acafd262a7c30818d53b9940cbfa diff --git a/src/lib/psensor.c b/src/lib/psensor.c index 58731d5..f8c0a83 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.c @@ -42,8 +42,16 @@ struct psensor *psensor_create(char *id, psensor->id = id; psensor->name = name; psensor->chip = chip; - psensor->min = UNKNOWN_DBL_VALUE; - psensor->max = UNKNOWN_DBL_VALUE; + psensor->sess_lowest = UNKNOWN_DBL_VALUE; + psensor->sess_highest = UNKNOWN_DBL_VALUE; + + if (type & SENSOR_TYPE_PERCENT) { + psensor->min = 0; + psensor->max = 100; + } else { + psensor->min = UNKNOWN_DBL_VALUE; + psensor->max = UNKNOWN_DBL_VALUE; + } psensor->type = type; @@ -57,12 +65,6 @@ struct psensor *psensor_create(char *id, psensor->cb_alarm_raised_data = NULL; psensor->alarm_raised = 0; - psensor->url = NULL; - - psensor->color = NULL; - - psensor->graph_enabled = 1; - psensor->provider_data = NULL; psensor->provider_data_free_fct = &free; @@ -105,13 +107,8 @@ void psensor_free(struct psensor *s) if (s->chip) free(s->chip); - if (s->color) - free(s->color); - measures_free(s->measures); - free(s->url); - if (s->provider_data && s->provider_data_free_fct) s->provider_data_free_fct(s->provider_data); @@ -258,11 +255,11 @@ void psensor_set_current_measure(struct psensor *s, double v, struct timeval tv) s->measures[s->values_max_length - 1].value = v; s->measures[s->values_max_length - 1].time = tv; - if (s->min == UNKNOWN_DBL_VALUE || v < s->min) - s->min = v; + if (s->sess_lowest == UNKNOWN_DBL_VALUE || v < s->sess_lowest) + s->sess_lowest = v; - if (s->max == UNKNOWN_DBL_VALUE || v > s->max) - s->max = v; + if (s->sess_highest == UNKNOWN_DBL_VALUE || v > s->sess_highest) + s->sess_highest = v; if (v > s->alarm_high_threshold || v < s->alarm_low_threshold) { if (!s->alarm_raised && s->cb_alarm_raised) { @@ -285,8 +282,8 @@ struct measure *psensor_get_current_measure(struct psensor *sensor) } /* - Returns the minimal value of a given 'type' (SENSOR_TYPE_TEMP or - SENSOR_TYPE_FAN) + * Returns the minimal value of a given 'type' (SENSOR_TYPE_TEMP or + * SENSOR_TYPE_FAN) */ static double get_min_value(struct psensor **sensors, int type) { @@ -317,8 +314,8 @@ static double get_min_value(struct psensor **sensors, int type) } /* - Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or - SENSOR_TYPE_FAN) + * Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or + * SENSOR_TYPE_FAN) */ double get_max_value(struct psensor **sensors, int type) { @@ -348,28 +345,6 @@ double get_max_value(struct psensor **sensors, int type) return m; } -double -psensor_get_max_current_value(struct psensor **sensors, unsigned int type) -{ - double m = UNKNOWN_DBL_VALUE; - struct psensor **s_cur = sensors; - - while (*s_cur) { - struct psensor *s = *s_cur; - - if (s->graph_enabled && (s->type & type)) { - double v = psensor_get_current_value(s); - - if (m == UNKNOWN_DBL_VALUE || v > m) - m = v; - } - - s_cur++; - } - - return m; -} - double get_min_temp(struct psensor **sensors) { return get_min_value(sensors, SENSOR_TYPE_TEMP); @@ -457,7 +432,10 @@ const char *psensor_type_to_unit_str(unsigned int type, int use_celsius) void psensor_log_measures(struct psensor **sensors) { - if (log_level == LOG_DEBUG) + if (log_level == LOG_DEBUG) { + if (!sensors) + return; + while (*sensors) { log_debug("Measure: %s %.2f", (*sensors)->name, @@ -465,6 +443,7 @@ void psensor_log_measures(struct psensor **sensors) sensors++; } + } } struct psensor **psensor_list_copy(struct psensor **sensors) @@ -488,26 +467,3 @@ psensor_current_value_to_str(const struct psensor *s, unsigned int use_celsius) psensor_get_current_value(s), use_celsius); } - -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; -}