Browse Source

hdxxvxta: Initial implementation

This driver was developed using the Veris HD2NVSTA1 humidity
transmitter.  The 'T' variant supports a temperature transmitter as
well.  Both signals are provided by the device as analog 0-5Vdc or
0-10Vdc outputs.

The A1 variant supports a temperature range of -40C-50C, while the A2
variant supports a range of 0C-50C.  Humidity ranges for all devices
in this device family range from 0% to 100% (non-condensing).

Temperature measurement can be disabled by passing -1 as the
temperature analog pin to the constructor.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Jon Trulson 9 years ago
parent
commit
fc7bfc113a

+ 1
- 0
examples/c++/CMakeLists.txt View File

@@ -236,6 +236,7 @@ if (MODBUS_FOUND)
236 236
   include_directories(${MODBUS_INCLUDE_DIRS})
237 237
   add_example (t3311)
238 238
 endif()
239
+add_example (hdxxvxta)
239 240
 
240 241
 # These are special cases where you specify example binary, source file and module(s)
241 242
 include_directories (${PROJECT_SOURCE_DIR}/src)

+ 79
- 0
examples/c++/hdxxvxta.cxx View File

@@ -0,0 +1,79 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2016 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+
29
+#include "hdxxvxta.h"
30
+
31
+using namespace std;
32
+
33
+bool shouldRun = true;
34
+
35
+void sig_handler(int signo)
36
+{
37
+  if (signo == SIGINT)
38
+    shouldRun = false;
39
+}
40
+
41
+int main(int argc, char **argv)
42
+{
43
+  signal(SIGINT, sig_handler);
44
+
45
+//! [Interesting]
46
+
47
+  cout << "Initializing..." << endl;
48
+
49
+  // Instantiate an HDXXVXTA instance, using A1 for humidity and A0
50
+  // for temperature
51
+  upm::HDXXVXTA *sensor = new upm::HDXXVXTA(1, 0);
52
+
53
+  // update and print available values every second
54
+  while (shouldRun)
55
+    {
56
+      // update our values from the sensor
57
+      sensor->update();
58
+
59
+      // we show both C and F for temperature
60
+      cout << "Temperature: " << sensor->getTemperature()
61
+           << " C / " << sensor->getTemperature(true) << " F"
62
+           << endl;
63
+
64
+      cout << "Humidity: " << sensor->getHumidity()
65
+           << " %" << endl;
66
+
67
+      cout << endl;
68
+
69
+      sleep(1);
70
+    }
71
+
72
+  cout << "Exiting..." << endl;
73
+
74
+  delete sensor;
75
+
76
+//! [Interesting]
77
+
78
+  return 0;
79
+}

+ 64
- 0
examples/javascript/hdxxvxta.js View File

@@ -0,0 +1,64 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+
4
+/*
5
+ * Author: Jon Trulson <jtrulson@ics.com>
6
+ * Copyright (c) 2016 Intel Corporation.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining
9
+ * a copy of this software and associated documentation files (the
10
+ * "Software"), to deal in the Software without restriction, including
11
+ * without limitation the rights to use, copy, modify, merge, publish,
12
+ * distribute, sublicense, and/or sell copies of the Software, and to
13
+ * permit persons to whom the Software is furnished to do so, subject to
14
+ * the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be
17
+ * included in all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
29
+var sensorObj = require('jsupm_hdxxvxta');
30
+
31
+
32
+/************** Main code **************/
33
+
34
+console.log("Initializing...");
35
+
36
+// Instantiate an HDXXVXTA instance, using A1 for humidity and A0
37
+// for temperature
38
+var sensor = new sensorObj.HDXXVXTA(1, 0);
39
+
40
+// update and print available values every second
41
+setInterval(function()
42
+{
43
+    // update our values from the sensor
44
+    sensor.update();
45
+
46
+    // we show both C and F for temperature
47
+    console.log("Temperature:", sensor.getTemperature(),
48
+                "C /", sensor.getTemperature(true), "F");
49
+
50
+    console.log("Humidity:", sensor.getHumidity(), "%");
51
+
52
+    console.log("");
53
+
54
+}, 1000);
55
+
56
+
57
+process.on('SIGINT', function()
58
+{
59
+    sensor = null;
60
+    sensorObj.cleanUp();
61
+    sensorObj = null;
62
+    console.log("Exiting...");
63
+    process.exit(0);
64
+});

+ 59
- 0
examples/python/hdxxvxta.py View File

@@ -0,0 +1,59 @@
1
+#!/usr/bin/python
2
+# Author: Jon Trulson <jtrulson@ics.com>
3
+# Copyright (c) 2016 Intel Corporation.
4
+#
5
+# Permission is hereby granted, free of charge, to any person obtaining
6
+# a copy of this software and associated documentation files (the
7
+# "Software"), to deal in the Software without restriction, including
8
+# without limitation the rights to use, copy, modify, merge, publish,
9
+# distribute, sublicense, and/or sell copies of the Software, and to
10
+# permit persons to whom the Software is furnished to do so, subject to
11
+# the following conditions:
12
+#
13
+# The above copyright notice and this permission notice shall be
14
+# included in all copies or substantial portions of the Software.
15
+#
16
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+import time, sys, signal, atexit
25
+import pyupm_hdxxvxta as sensorObj
26
+
27
+## Exit handlers ##
28
+# This function stops python from printing a stacktrace when you hit control-C
29
+def SIGINTHandler(signum, frame):
30
+	raise SystemExit
31
+
32
+# This function lets you run code on exit
33
+def exitHandler():
34
+	print "Exiting"
35
+	sys.exit(0)
36
+
37
+# Register exit handlers
38
+atexit.register(exitHandler)
39
+signal.signal(signal.SIGINT, SIGINTHandler)
40
+
41
+print "Initializing..."
42
+
43
+# Instantiate an HDXXVXTA instance, using A1 for humidity and A0
44
+# for temperature
45
+sensor = sensorObj.HDXXVXTA(1, 0)
46
+
47
+# update and print available values every second
48
+while (1):
49
+        # update our values from the sensor
50
+        sensor.update()
51
+
52
+        # we show both C and F for temperature
53
+        print "Temperature:", sensor.getTemperature(), "C /",
54
+        print sensor.getTemperature(True), "F"
55
+
56
+        print "Humidity:", sensor.getHumidity(), "%"
57
+
58
+        print
59
+	time.sleep(1)

+ 5
- 0
src/hdxxvxta/CMakeLists.txt View File

@@ -0,0 +1,5 @@
1
+set (libname "hdxxvxta")
2
+set (libdescription "upm Veris HDXXVXTA Temperature/Humidity transmitter")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 122
- 0
src/hdxxvxta/hdxxvxta.cxx View File

@@ -0,0 +1,122 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2016 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <iostream>
26
+
27
+#include "hdxxvxta.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+// conversion from celcius to fahrenheit
33
+
34
+static float c2f(float c)
35
+{
36
+  return (c * (9.0 / 5.0) + 32.0);
37
+}
38
+
39
+
40
+HDXXVXTA::HDXXVXTA(int hPin, int tPin, float aref) :
41
+  m_aioHum(hPin), m_aioTemp(0)
42
+{
43
+  if (tPin >= 0)
44
+    m_hasTemp = true;
45
+  else
46
+    m_hasTemp = false;
47
+
48
+  m_temperature = 0.0;
49
+  m_humidity = 0.0;
50
+
51
+  if (m_hasTemp)
52
+    {
53
+      m_aioTemp = new mraa::Aio(tPin);
54
+      m_aResTemp = (1 << m_aioTemp->getBit());
55
+    }
56
+  else
57
+    m_aResTemp = 0;
58
+
59
+  m_aResHum = (1 << m_aioHum.getBit());
60
+  m_aref = aref;
61
+
62
+  // set the default temperature range to the A1 series (-40C-50C),
63
+  // regardless of whether temperature measuring is enabled
64
+  setRange(RANGE_MINUS40_50);
65
+}
66
+
67
+HDXXVXTA::~HDXXVXTA()
68
+{
69
+  if (m_aioTemp)
70
+    delete m_aioTemp;
71
+}
72
+
73
+void HDXXVXTA::update()
74
+{
75
+  // temperature
76
+  int val;
77
+  float volts;
78
+
79
+  if (m_hasTemp)
80
+    {
81
+      val = m_aioTemp->read();
82
+      volts = (float(val) * (m_aref / m_aResTemp));
83
+
84
+      switch (m_range)
85
+        {
86
+        case RANGE_MINUS40_50:
87
+          // valid range is 50 + abs(-40) = 90
88
+          m_temperature = ((volts / m_aref) * 90.0) - 40.0;
89
+          break;
90
+          
91
+        case RANGE_0_50:
92
+          // valid range is 50
93
+          m_temperature = ((volts / m_aref) * 50.0);
94
+          break;
95
+          
96
+        default:
97
+          // shouldn't happen, but...
98
+          throw std::out_of_range(std::string(__FUNCTION__) +
99
+                                  ": internal error, invalid range value");
100
+          break;
101
+        }
102
+    }
103
+
104
+  // humidity
105
+  val = m_aioHum.read();
106
+  volts = (float(val) * (m_aref / m_aResHum));
107
+  m_humidity = ((volts / m_aref) * 100.0);
108
+}
109
+
110
+float HDXXVXTA::getTemperature(bool fahrenheit)
111
+{
112
+  if (fahrenheit)
113
+    return c2f(m_temperature);
114
+  else
115
+    return m_temperature;
116
+}
117
+
118
+float HDXXVXTA::getHumidity()
119
+{
120
+  return m_humidity;
121
+}
122
+

+ 166
- 0
src/hdxxvxta/hdxxvxta.h View File

@@ -0,0 +1,166 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2016 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+#pragma once
25
+
26
+#include <string>
27
+#include <iostream>
28
+
29
+#include <mraa/aio.hpp>
30
+
31
+// Unlikey to be changable without external circuitry (voltage divider)
32
+#define HDXXVXTA_DEFAULT_AREF 5.0
33
+
34
+namespace upm {
35
+    /**
36
+     * @brief Veris HDXXVXTA Humidity Transmitter
37
+     * @defgroup hdxxvxta libupm-hdxxvxta
38
+     * @ingroup veris ainput temp
39
+     */
40
+
41
+    /**
42
+     * @library hdxxvxta
43
+     * @sensor hdxxvxta
44
+     * @comname Veris HDXXVXTA Humidity Transmitter family
45
+     * @type temp
46
+     * @man veris
47
+     * @con ainput
48
+     * @web http://www.veris.com/Item/HD2NVSTA1.aspx
49
+     *
50
+     * @brief API for the Veris HDXXVXTA Humidity Transmitter
51
+     *
52
+     * The driver was developed using the HD2NVSTA1 humidity
53
+     * transmitter.  The 'T' variant supports a temperature
54
+     * transmitter as well.  Both signals are provided by the device
55
+     * as analog 0-5Vdc or 0-10Vdc outputs.  The A1 variant supports a
56
+     * temperature range of -40C-50C, while the A2 variant supports a
57
+     * range of 0C-50C.  Humidity ranges for all devices in this
58
+     * device family range from 0% to 100% (non-condensing).
59
+     *
60
+     * This driver used the 5Vdc outputs for obvious reasons.  Your
61
+     * MCU must be configured for 5V operation.  Using any other
62
+     * analog reference voltage will require the appropriate external
63
+     * circuitry (such as a voltage divider) in order to interface
64
+     * safely with your MCU.
65
+     *
66
+     * For devices which do not support temperature, use '-1' as the
67
+     * temperature pin number in the object constructor.  If
68
+     * temperature measurement is disabled, getTemperature() will always
69
+     * return 0C/32F.
70
+     *
71
+     * @snippet hdxxvxta.cxx Interesting
72
+     */
73
+
74
+  class HDXXVXTA {
75
+  public:
76
+
77
+    typedef enum {
78
+      // *A1 series (-40C-50C)
79
+      RANGE_MINUS40_50                      = 1,
80
+      // *A2 series (0C-50C)
81
+      RANGE_0_50                            = 2
82
+    } RANGE_T;
83
+
84
+    /**
85
+     * HDXXVXTA object constructor
86
+     *
87
+     * @param hPin Analog pin to use for the humidity measurement
88
+     * @param tPin Analog pin to use for temperature.  If your device
89
+     * does not support temperature, use -1 as the value so that
90
+     * temperature will not be queried and an analog pin won't be
91
+     * wasted.
92
+     * @param aref The analog reference voltage, default 5.0
93
+     */
94
+    HDXXVXTA(int hPin, int tPin, float aref=HDXXVXTA_DEFAULT_AREF);
95
+
96
+    /**
97
+     * HDXXVXTA object destructor
98
+     */
99
+    ~HDXXVXTA();
100
+
101
+    /**
102
+     * Set the temperature range of the sensor.  HD*A1 sensors support
103
+     * a range of -40C-50C, while HD*A2 devices support a temperature
104
+     * range of 0C-50C.  The constructor sets a default of
105
+     * RANGE_MINUS40_50.
106
+     *
107
+     * @param One of the RANGE_T values, default is RANGE_MINUS40_50
108
+     */
109
+    void setRange(RANGE_T range=RANGE_MINUS40_50)
110
+    {
111
+      m_range = range;
112
+    };
113
+
114
+    /**
115
+     * Read current values from the sensor and update internal stored
116
+     * values.  This method must be called prior to querying any
117
+     * values, such as temperature or humidity.
118
+     */
119
+    void update();
120
+
121
+    /**
122
+     * Get the current temperature.  update() must have been called
123
+     * prior to calling this method.  If temperature measurement was
124
+     * disabled (by passing -1 as the temperature pin in the
125
+     * constructor) then this function will always return 0C/32F.
126
+     *
127
+     * @param fahrenheit true to return the temperature in degrees
128
+     * fahrenheit, false to return the temperature in degrees celcius.
129
+     * The default is false (degrees Celcius).
130
+     * @return The last temperature reading in Celcius or Fahrenheit
131
+     */
132
+    float getTemperature(bool fahrenheit=false);
133
+
134
+    /**
135
+     * Get the current relative humidity.  update() must have been called
136
+     * prior to calling this method.
137
+     *
138
+     * @return The last humidity reading
139
+     */
140
+    float getHumidity();
141
+
142
+
143
+  protected:
144
+    // temperature is an optional feature of the humidity transmitter
145
+    mraa::Aio *m_aioTemp;
146
+
147
+    mraa::Aio m_aioHum;
148
+
149
+  private:
150
+    float m_aref;
151
+    int m_aResTemp;
152
+    int m_aResHum;
153
+
154
+    // does this sensor support temperature reporting?
155
+    bool m_hasTemp;
156
+
157
+    // in Celcius
158
+    float m_temperature;
159
+
160
+    float m_humidity;
161
+
162
+    RANGE_T m_range;
163
+  };
164
+}
165
+
166
+

+ 21
- 0
src/hdxxvxta/javaupm_hdxxvxta.i View File

@@ -0,0 +1,21 @@
1
+%module javaupm_hdxxvxta
2
+%include "../upm.i"
3
+%include "std_string.i"
4
+
5
+%{
6
+    #include "hdxxvxta.h"
7
+%}
8
+
9
+%include "hdxxvxta.h"
10
+
11
+
12
+%pragma(java) jniclasscode=%{
13
+    static {
14
+        try {
15
+            System.loadLibrary("javaupm_hdxxvxta");
16
+        } catch (UnsatisfiedLinkError e) {
17
+            System.err.println("Native code library failed to load. \n" + e);
18
+            System.exit(1);
19
+        }
20
+    }
21
+%}

+ 10
- 0
src/hdxxvxta/jsupm_hdxxvxta.i View File

@@ -0,0 +1,10 @@
1
+%module jsupm_hdxxvxta
2
+%include "../upm.i"
3
+%include "std_string.i"
4
+
5
+%{
6
+    #include "hdxxvxta.h"
7
+%}
8
+
9
+%include "hdxxvxta.h"
10
+

+ 13
- 0
src/hdxxvxta/pyupm_hdxxvxta.i View File

@@ -0,0 +1,13 @@
1
+// Include doxygen-generated documentation
2
+%include "pyupm_doxy2swig.i"
3
+%module pyupm_hdxxvxta
4
+%include "../upm.i"
5
+%include "std_string.i"
6
+
7
+%feature("autodoc", "3");
8
+
9
+%{
10
+    #include "hdxxvxta.h"
11
+%}
12
+%include "hdxxvxta.h"
13
+

+ 6
- 0
src/upm.h View File

@@ -344,6 +344,12 @@
344 344
  * @ingroup byman
345 345
  */
346 346
 
347
+/**
348
+ * @brief Veris Industries
349
+ * @defgroup veris Veris Industries
350
+ * @ingroup byman
351
+ */
352
+
347 353
 ////////////////////////////////////////////////////////////////// @cond KIT
348 354
 /// Groups for the various Starter Kits.
349 355
 ////////////////////////////////////////////////////////////////// @endcond KIT