Add support for light sensors that report Illuminance in lux.

This commit is contained in:
thorpej 2018-05-27 01:39:00 +00:00
parent c50a4e606c
commit 033d68f1b3
3 changed files with 54 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_envsys_tables.c,v 1.12 2014/05/18 11:46:23 kardel Exp $ */
/* $NetBSD: sysmon_envsys_tables.c,v 1.13 2018/05/27 01:39:00 thorpej Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.12 2014/05/18 11:46:23 kardel Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.13 2018/05/27 01:39:00 thorpej Exp $");
#include <sys/types.h>
@ -52,6 +52,7 @@ static const struct sme_descr_entry sme_units_description[] = {
{ ENVSYS_BATTERY_CAPACITY, PENVSYS_TYPE_BATTERY,"Battery capacity" },
{ ENVSYS_BATTERY_CHARGE, -1, "Battery charge" },
{ ENVSYS_SRELHUMIDITY, -1, "relative Humidity" },
{ ENVSYS_LUX, -1, "Illuminance" },
{ -1, -1, "unknown" }
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: envsys.h,v 1.36 2016/01/23 01:26:14 dholland Exp $ */
/* $NetBSD: envsys.h,v 1.37 2018/05/27 01:39:00 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2007, 2014 The NetBSD Foundation, Inc.
@ -64,6 +64,7 @@ enum envsys_units {
ENVSYS_BATTERY_CAPACITY, /* Battery capacity */
ENVSYS_BATTERY_CHARGE, /* Battery charging/discharging */
ENVSYS_SRELHUMIDITY, /* relative humidity */
ENVSYS_LUX, /* illumanice in lux */
ENVSYS_NSENSORS
};
@ -162,7 +163,7 @@ typedef struct envsys_tre_data envsys_tre_data_t;
#ifdef ENVSYSUNITNAMES
static const char * const envsysunitnames[] = {
"degC", "RPM", "VAC", "V", "Ohms", "W",
"A", "Wh", "Ah", "bool", "integer", "drive", "%rH", "Unk"
"A", "Wh", "Ah", "bool", "integer", "drive", "%rH", "lux", "Unk"
};
static const char * const envsysdrivestatus[] = {
"unknown", "empty", "ready", "powering up", "online", "idle", "active",

View File

@ -1,4 +1,4 @@
/* $NetBSD: envstat.c,v 1.95 2014/05/18 11:46:24 kardel Exp $ */
/* $NetBSD: envstat.c,v 1.96 2018/05/27 01:39:00 thorpej Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: envstat.c,v 1.95 2014/05/18 11:46:24 kardel Exp $");
__RCSID("$NetBSD: envstat.c,v 1.96 2018/05/27 01:39:00 thorpej Exp $");
#endif /* not lint */
#include <stdio.h>
@ -959,6 +959,52 @@ do { \
(void)printf(":%10s", sensor->battcap);
/* Illuminance */
} else if (strcmp(sensor->type, "Illuminance") == 0) {
stype = "lux";
(void)printf(":%10u ", sensor->cur_value);
ilen = 8;
if (statistics) {
/* show statistics if flag set */
(void)printf("%8u %8u %8u ",
stats->max, stats->min, stats->avg);
ilen += 2;
} else {
if (sensor->critmax_value) {
(void)printf("%*u ", (int)ilen,
sensor->critmax_value);
ilen = 8;
} else
ilen += 9;
if (sensor->warnmax_value) {
(void)printf("%*u ", (int)ilen,
sensor->warnmax_value);
ilen = 8;
} else
ilen += 9;
if (sensor->warnmin_value) {
(void)printf("%*u ", (int)ilen,
sensor->warnmin_value);
ilen = 8;
} else
ilen += 9;
if (sensor->critmin_value) {
(void)printf( "%*u ", (int)ilen,
sensor->critmin_value);
ilen = 8;
} else
ilen += 9;
}
(void)printf("%*s", (int)ilen - 3, stype);
/* everything else */
} else {
if (strcmp(sensor->type, "Voltage DC") == 0)