#include <stdlib.h>
#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
#include <sensors/sensors.h>
#include <sensors/error.h>
psensor->id = id;
psensor->name = name;
psensor->enabled = 1;
- psensor->min = UNKNOWN_VALUE;
- psensor->max = UNKNOWN_VALUE;
+ psensor->min = UNKNOWN_DBL_VALUE;
+ psensor->max = UNKNOWN_DBL_VALUE;
psensor->type = type;
psensor->values_max_length = values_max_length;
- psensor->measures = measures_create(values_max_length);
+ psensor->measures = measures_dbl_create(values_max_length);
psensor->alarm_limit = 0;
cur_size = s->values_max_length;
cur_ms = s->measures;
- new_ms = measures_create(new_size);
+ new_ms = measures_dbl_create(new_size);
if (cur_ms) {
int i;
&s->measures[1],
(s->values_max_length - 1) * sizeof(struct measure));
- s->measures[s->values_max_length - 1].value = v;
+ s->measures[s->values_max_length - 1].value.d_num = v;
s->measures[s->values_max_length - 1].time = tv;
- if (s->min == UNKNOWN_VALUE || v < s->min)
+ if (s->min == UNKNOWN_DBL_VALUE || v < s->min)
s->min = v;
- if (s->max == UNKNOWN_VALUE || v > s->max)
+ if (s->max == UNKNOWN_DBL_VALUE || v > s->max)
s->max = v;
if (s->alarm_limit && s->alarm_enabled) {
double psensor_get_current_value(struct psensor *sensor)
{
- return sensor->measures[sensor->values_max_length - 1].value;
+ return sensor->measures[sensor->values_max_length - 1].value.d_num;
}
struct measure *psensor_get_current_measure(struct psensor *sensor)
*/
double get_min_value(struct psensor **sensors, int type)
{
- double m = UNKNOWN_VALUE;
+ double m = UNKNOWN_DBL_VALUE;
struct psensor **s = sensors;
while (*s) {
double t;
for (i = 0; i < sensor->values_max_length; i++) {
- t = sensor->measures[i].value;
+ t = sensor->measures[i].value.d_num;
- if (t == UNKNOWN_VALUE)
+ if (t == UNKNOWN_DBL_VALUE)
continue;
- if (m == UNKNOWN_VALUE || t < m)
+ if (m == UNKNOWN_DBL_VALUE || t < m)
m = t;
}
}
*/
static double get_max_value(struct psensor **sensors, int type)
{
- double m = UNKNOWN_VALUE;
+ double m = UNKNOWN_DBL_VALUE;
struct psensor **s = sensors;
while (*s) {
int i;
double t;
for (i = 0; i < sensor->values_max_length; i++) {
- t = sensor->measures[i].value;
+ t = sensor->measures[i].value.d_num;
- if (t == UNKNOWN_VALUE)
+ if (t == UNKNOWN_DBL_VALUE)
continue;
- if (m == UNKNOWN_VALUE || t > m)
+ if (m == UNKNOWN_DBL_VALUE || t > m)
m = t;
}
}
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->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);
return "N/A"; /* should not be possible */
}
+
+const char *psensor_type_to_unit_str(unsigned int type)
+{
+ if (type & SENSOR_TYPE_TEMP)
+ return _("C");
+
+ if (type & SENSOR_TYPE_FAN)
+ return _("RPM");
+
+ return "N/A";
+}
+
void psensor_list_update_measures(struct psensor **sensors)
{
lmsensor_psensor_list_update(sensors);
- hdd_psensor_list_update(sensors);
+
+ if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP))
+ hdd_psensor_list_update(sensors);
}