Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add support for light sensors that report Illuminance in lux.



details:   https://anonhg.NetBSD.org/src/rev/82c221105639
branches:  trunk
changeset: 319343:82c221105639
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 27 01:39:00 2018 +0000

description:
Add support for light sensors that report Illuminance in lux.

diffstat:

 sys/dev/sysmon/sysmon_envsys_tables.c |   5 ++-
 sys/sys/envsys.h                      |   5 ++-
 usr.sbin/envstat/envstat.c            |  50 +++++++++++++++++++++++++++++++++-
 3 files changed, 54 insertions(+), 6 deletions(-)

diffs (123 lines):

diff -r 0b2391f5fc4b -r 82c221105639 sys/dev/sysmon/sysmon_envsys_tables.c
--- a/sys/dev/sysmon/sysmon_envsys_tables.c     Sun May 27 01:14:50 2018 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_tables.c     Sun May 27 01:39:00 2018 +0000
@@ -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 @@
        { 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" }
 };
 
diff -r 0b2391f5fc4b -r 82c221105639 sys/sys/envsys.h
--- a/sys/sys/envsys.h  Sun May 27 01:14:50 2018 +0000
+++ b/sys/sys/envsys.h  Sun May 27 01:39:00 2018 +0000
@@ -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 @@
        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 @@
 #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",
diff -r 0b2391f5fc4b -r 82c221105639 usr.sbin/envstat/envstat.c
--- a/usr.sbin/envstat/envstat.c        Sun May 27 01:14:50 2018 +0000
+++ b/usr.sbin/envstat/envstat.c        Sun May 27 01:39:00 2018 +0000
@@ -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 @@
 
                        (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)



Home | Main Index | Thread Index | Old Index