summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorYojiro Uo <yuo@cvs.openbsd.org>2012-09-20 20:11:59 +0000
committerYojiro Uo <yuo@cvs.openbsd.org>2012-09-20 20:11:59 +0000
commit862a65ad28ed788f381eaec33721df1ee8b6ee61 (patch)
tree6f03c3aec2b8c99104edb01384f26c9896b7f700 /usr.sbin
parent0e23b6d7673107501af89200b19d0af5aea84086 (diff)
add more sensor types to sensor framework.
- Pressure (10^-3 Pa) - distance (10^-6 m) - acceleration (10^-6 m/s^2) ok deraadt@ reyk@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sensorsd/sensorsd.c14
-rw-r--r--usr.sbin/snmpd/mib.c10
2 files changed, 21 insertions, 3 deletions
diff --git a/usr.sbin/sensorsd/sensorsd.c b/usr.sbin/sensorsd/sensorsd.c
index 77da0922e58..c84e0399504 100644
--- a/usr.sbin/sensorsd/sensorsd.c
+++ b/usr.sbin/sensorsd/sensorsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensorsd.c,v 1.51 2011/09/16 17:45:06 yuo Exp $ */
+/* $OpenBSD: sensorsd.c,v 1.52 2012/09/20 20:11:58 yuo Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -671,6 +671,15 @@ print_sensor(enum sensor_type type, int64_t value)
case SENSOR_ANGLE:
snprintf(fbuf, RFBUFSIZ, "%lld", value);
break;
+ case SENSOR_DISTANCE:
+ snprintf(fbuf, RFBUFSIZ, "%.2f mm", value / 1000.0);
+ break;
+ case SENSOR_PRESSURE:
+ snprintf(fbuf, RFBUFSIZ, "%.2f Pa", value / 1000.0);
+ break;
+ case SENSOR_ACCEL:
+ snprintf(fbuf, RFBUFSIZ, "%2.4f m/s^2", value / 1000000.0);
+ break;
default:
snprintf(fbuf, RFBUFSIZ, "%lld ???", value);
}
@@ -781,12 +790,15 @@ get_val(char *buf, int upper, enum sensor_type type)
case SENSOR_AMPHOUR:
case SENSOR_LUX:
case SENSOR_FREQ:
+ case SENSOR_ACCEL:
rval = val * 1000 * 1000;
break;
case SENSOR_TIMEDELTA:
rval = val * 1000 * 1000 * 1000;
break;
case SENSOR_HUMIDITY:
+ case SENSOR_DISTANCE:
+ case SENSOR_PRESSURE:
rval = val * 1000.0;
break;
default:
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c
index 734b6056f59..68ddc7c2f20 100644
--- a/usr.sbin/snmpd/mib.c
+++ b/usr.sbin/snmpd/mib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mib.c,v 1.59 2012/09/18 08:29:09 reyk Exp $ */
+/* $OpenBSD: mib.c,v 1.60 2012/09/20 20:11:58 yuo Exp $ */
/*
* Copyright (c) 2012 Joel Knight <joel@openbsd.org>
@@ -2580,7 +2580,8 @@ static const char * const sensor_drive_s[SENSOR_DRIVE_STATES] = {
static const char * const sensor_unit_s[SENSOR_MAX_TYPES + 1] = {
"degC", "RPM", "V DC", "V AC", "Ohm", "W", "A", "Wh", "Ah",
- "", "", "%", "lx", "", "sec", "%RH", "Hz", "degree", ""
+ "", "", "%", "lx", "", "sec", "%RH", "Hz", "degree",
+ "mm", "Pa", "m/s^2", ""
};
const char *
@@ -2611,6 +2612,7 @@ mib_sensorvalue(struct sensor *s)
case SENSOR_AMPHOUR:
case SENSOR_LUX:
case SENSOR_FREQ:
+ case SENSOR_ACCEL:
ret = asprintf(&v, "%.2f", s->value / 1000000.0);
break;
case SENSOR_INDICATOR:
@@ -2620,6 +2622,10 @@ mib_sensorvalue(struct sensor *s)
case SENSOR_HUMIDITY:
ret = asprintf(&v, "%.2f%%", s->value / 1000.0);
break;
+ case SENSOR_DISTANCE:
+ case SENSOR_PRESSURE:
+ ret = asprintf(&v, "%.2f", s->value / 1000.0);
+ break;
case SENSOR_TIMEDELTA:
ret = asprintf(&v, "%.6f", s->value / 1000000000.0);
break;