/*
- * Copyright (C) 2010-2011 jeanfi@gmail.com
+ * Copyright (C) 2010-2012 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
psensor->values_max_length = values_max_length;
psensor->measures = measures_dbl_create(values_max_length);
- psensor->alarm_limit = 0;
+ psensor->alarm_enabled = 0;
+ psensor->alarm_high_thresold = 0;
+ psensor->alarm_low_thresold = 0;
psensor->cb_alarm_raised = NULL;
psensor->cb_alarm_raised_data = NULL;
psensor->alarm_raised = 0;
- psensor->alarm_enabled = 0;
-
psensor->url = NULL;
psensor->color = NULL;
void psensor_free(struct psensor *sensor)
{
if (sensor) {
+ log_debug("Cleanup %s", sensor->id);
+
free(sensor->name);
free(sensor->id);
return type & SENSOR_TYPE_FAN;
}
-char *psensor_value_to_string(unsigned int type, double value)
+double celcius_to_fahrenheit(double c)
+{
+ return c * (9.0/5.0) + 32;
+}
+
+double fahrenheit_to_celcius(double f)
+{
+ return (f - 32) * (5.0/9.0);
+}
+
+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 *unit;
if (is_temp_type(type))
- unit = "C";
+ if (use_celcius) {
+ unit = "°C";
+ } else {
+ unit = "°F";
+ value = celcius_to_fahrenheit(value);
+ }
else if (type & SENSOR_TYPE_CPU_USAGE)
unit = "%";
else
return str;
}
+char *
+psensor_measure_to_str(const struct measure *m,
+ unsigned int type,
+ unsigned int use_celcius)
+{
+ return psensor_value_to_str(type, m->value, use_celcius);
+}
+
void psensor_set_current_value(struct psensor *sensor, double value)
{
struct timeval tv;
&s->measures[1],
(s->values_max_length - 1) * sizeof(struct measure));
- s->measures[s->values_max_length - 1].value.d_num = v;
+ 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)
if (s->max == UNKNOWN_DBL_VALUE || v > s->max)
s->max = v;
- if (s->alarm_limit && s->alarm_enabled) {
- if (v > s->alarm_limit) {
+ if (s->alarm_enabled) {
+ if (v > s->alarm_high_thresold || v < s->alarm_low_thresold) {
if (!s->alarm_raised && s->cb_alarm_raised)
- s->cb_alarm_raised(s,
- s->cb_alarm_raised_data);
+ s->cb_alarm_raised(s, s->cb_alarm_raised_data);
s->alarm_raised = 1;
} else {
double psensor_get_current_value(struct psensor *sensor)
{
- return sensor->measures[sensor->values_max_length - 1].value.d_num;
+ return sensor->measures[sensor->values_max_length - 1].value;
}
struct measure *psensor_get_current_measure(struct psensor *sensor)
double t;
for (i = 0; i < sensor->values_max_length; i++) {
- t = sensor->measures[i].value.d_num;
+ t = sensor->measures[i].value;
if (t == UNKNOWN_DBL_VALUE)
continue;
int i;
double t;
for (i = 0; i < sensor->values_max_length; i++) {
- t = sensor->measures[i].value.d_num;
+ t = sensor->measures[i].value;
if (t == UNKNOWN_DBL_VALUE)
continue;
return get_max_value(sensors, SENSOR_TYPE_TEMP);
}
-struct psensor **get_all_sensors(int values_max_length)
+struct psensor **get_all_sensors(int use_libatasmart, int values_max_length)
{
struct psensor **psensors = NULL;
struct psensor **tmp_psensors;
psensors = lmsensor_psensor_list_add(NULL, values_max_length);
- tmp_psensors = hdd_psensor_list_add(psensors, values_max_length);
- if (tmp_psensors != psensors) {
- free(psensors);
- psensors = tmp_psensors;
+ if (!use_libatasmart) {
+ tmp_psensors = hddtemp_psensor_list_add(psensors,
+ values_max_length);
+ if (tmp_psensors != psensors) {
+ free(psensors);
+ psensors = tmp_psensors;
+ }
}
+#ifdef HAVE_ATASMART
+ else {
+ tmp_psensors = hdd_psensor_list_add(psensors,
+ values_max_length);
+ if (tmp_psensors != psensors) {
+ free(psensors);
+ psensors = tmp_psensors;
+ }
+ }
+#endif
if (!psensors) { /* there is no detected sensors */
psensors = malloc(sizeof(struct psensor *));
}
-const char *psensor_type_to_unit_str(unsigned int type)
+const char *psensor_type_to_unit_str(unsigned int type, int use_celcius)
{
- if (type & SENSOR_TYPE_TEMP)
- return _("C");
+ if (type & SENSOR_TYPE_TEMP) {
+ if (use_celcius)
+ return "\302\260C";
+ else
+ return "\302\260F";
+ }
if (type & SENSOR_TYPE_FAN)
return _("RPM");
if (type & SENSOR_TYPE_CPU_USAGE)
return _("%");
- return "N/A";
+ return _("N/A");
}
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)
- || psensor_list_contains_type(sensors,
- SENSOR_TYPE_HDD_TEMP_ATASMART))
+ if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDD_TEMP_HDDTEMP))
+ hddtemp_psensor_list_update(sensors);
+
+#ifdef HAVE_ATASMART
+ if (psensor_list_contains_type(sensors,
+ SENSOR_TYPE_HDD_TEMP_ATASMART))
hdd_psensor_list_update(sensors);
+#endif
+}
+
+void psensor_log_measures(struct psensor **sensors)
+{
+ if (log_level == LOG_DEBUG)
+ while (*sensors) {
+ log_debug("Measure: %s %.2f",
+ (*sensors)->name,
+ psensor_get_current_value(*sensors));
+
+ sensors++;
+ }
}
void psensor_init()