ソースを参照

cwlsxxa: Initial implementation

The driver was developed using the Veris CWLSHTA CO2 Gas sensor.  The
'T' variant supports a temperature sensor, and the 'H' variant
supports a humidity sensor.

All 3 signals are provided by the device as analog 0-5Vdc, 0-10Vdc, or
4-20ma loop current outputs.  For devices supporting temperature, the
valid temperature range is 10C to 50C.  The humidity ranges from 0% to
100% (non-condensing).  The CO2 sensor ranges from 0 to 2000 ppm.

This driver was developed using the 5Vdc outputs and the 4-20ma
outputs.  For voltage outputs, your MCU must be configured for 5V
operation.  In addition, you must configure the sensor (via it's
configuration switches) to output 0-5VDC only.  Using any other analog
reference voltage will require the appropriate external circuitry
(such as a voltage divider) in order to interface safely with your
MCU.

In addition, the sensor can be configured for 4-20ma usage, by
specifying the correct receiver resistance (in ohms) in the
constructor.  This sensor was tested with a Cooking Hacks (Libelium)
4-channel 4-20ma Arduino interface shield.  For this interface, the
receiver resistance was specified as 165.0 ohms.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
Jon Trulson 9 年 前
コミット
a8d96bd2d9

+ 1
- 0
examples/c++/CMakeLists.txt ファイルの表示

@@ -248,6 +248,7 @@ add_example (max44009)
248 248
 add_example (si1132)
249 249
 add_example (si7005)
250 250
 add_example (t6713)
251
+add_example (cwlsxxa)
251 252
 
252 253
 # These are special cases where you specify example binary, source file and module(s)
253 254
 include_directories (${PROJECT_SOURCE_DIR}/src)

+ 82
- 0
examples/c++/cwlsxxa.cxx ファイルの表示

@@ -0,0 +1,82 @@
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 "cwlsxxa.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 CWLSXXA instance, using A0 for CO2, A1 for
50
+  // humidity and A2 for temperature
51
+  upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
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 << "CO2: " << sensor->getCO2()
68
+           << " ppm" << endl;
69
+
70
+      cout << endl;
71
+
72
+      sleep(1);
73
+    }
74
+
75
+  cout << "Exiting..." << endl;
76
+
77
+  delete sensor;
78
+
79
+//! [Interesting]
80
+
81
+  return 0;
82
+}

+ 1
- 0
examples/java/CMakeLists.txt ファイルの表示

@@ -105,6 +105,7 @@ add_example(Ad8232Example ad8232)
105 105
 add_example(Gp2y0aExample gp2y0a)
106 106
 add_example(Th02Example th02)
107 107
 add_example(FlexSensorExample flex)
108
+add_example(CWLSXXA_Example cwlsxxa)
108 109
 
109 110
 
110 111
 add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)

+ 62
- 0
examples/java/CWLSXXA_Example.java ファイルの表示

@@ -0,0 +1,62 @@
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
+import upm_cwlsxxa.CWLSXXA;
26
+
27
+public class CWLSXXA_Example 
28
+{
29
+    public static void main(String[] args) throws InterruptedException
30
+    {
31
+// ! [Interesting]
32
+
33
+        // Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
34
+        // humidity and A2 for temperature
35
+        CWLSXXA sensor = new CWLSXXA(0, 1, 2);
36
+        
37
+        while (true)
38
+            {
39
+                // update our values from the sensor
40
+                sensor.update();
41
+
42
+                // we show both C and F for temperature
43
+                System.out.println("Temperature: " 
44
+                                   + sensor.getTemperature()
45
+                                   + " C / "
46
+                                   + sensor.getTemperature(true)
47
+                                   + " F");
48
+
49
+                System.out.println("Humidity: "
50
+                                   + sensor.getHumidity()
51
+                                   + " %");
52
+
53
+                System.out.println("CO2: "
54
+                                   + sensor.getCO2()
55
+                                   + " ppm");
56
+                
57
+                Thread.sleep(1000);
58
+            }
59
+
60
+// ! [Interesting]
61
+    }
62
+}

+ 66
- 0
examples/javascript/cwlsxxa.js ファイルの表示

@@ -0,0 +1,66 @@
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_cwlsxxa');
30
+
31
+
32
+/************** Main code **************/
33
+
34
+console.log("Initializing...");
35
+
36
+// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
37
+// humidity and A2 for temperature
38
+var sensor = new sensorObj.CWLSXXA(0, 1, 2);
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("CO2:", sensor.getCO2(), "ppm");
53
+
54
+    console.log("");
55
+
56
+}, 1000);
57
+
58
+
59
+process.on('SIGINT', function()
60
+{
61
+    sensor = null;
62
+    sensorObj.cleanUp();
63
+    sensorObj = null;
64
+    console.log("Exiting...");
65
+    process.exit(0);
66
+});

+ 61
- 0
examples/python/cwlsxxa.py ファイルの表示

@@ -0,0 +1,61 @@
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_cwlsxxa 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 CWLSXXA instance, using A0 for CO2, A1 for
44
+# humidity and A2 for temperature
45
+sensor = sensorObj.CWLSXXA(0, 1, 2)
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 "CO2:", sensor.getCO2(), "ppm"
59
+
60
+        print
61
+	time.sleep(1)

+ 5
- 0
src/cwlsxxa/CMakeLists.txt ファイルの表示

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

+ 183
- 0
src/cwlsxxa/cwlsxxa.cxx ファイルの表示

@@ -0,0 +1,183 @@
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 "cwlsxxa.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+// for current loop reads that seems a little noisy, we average over
33
+// several aio reads.
34
+static const int maxSamples = 50;
35
+
36
+// conversion from celcius to fahrenheit
37
+
38
+static float c2f(float c)
39
+{
40
+  return (c * (9.0 / 5.0) + 32.0);
41
+}
42
+
43
+
44
+CWLSXXA::CWLSXXA(int gPin, int hPin, int tPin, float rResistor, float aref) :
45
+  m_aioCO2(gPin), m_aioHum(0), m_aioTemp(0)
46
+{
47
+  m_hasHum = (hPin >= 0) ? true : false;
48
+  m_hasTemp = (tPin >= 0) ? true : false;
49
+
50
+  if (m_hasTemp)
51
+    {
52
+      m_aioTemp = new mraa::Aio(tPin);
53
+      m_aResTemp = (1 << m_aioTemp->getBit());
54
+    }
55
+  else
56
+    m_aResTemp = 0;
57
+
58
+  if (m_hasHum)
59
+    {
60
+      m_aioHum = new mraa::Aio(hPin);
61
+      m_aResHum = (1 << m_aioHum->getBit());
62
+    }
63
+  else
64
+    m_aResHum = 0;
65
+
66
+  m_aResCO2 = (1 << m_aioCO2.getBit());
67
+
68
+  m_temperature = 0.0;
69
+  m_humidity = 0.0;
70
+  m_co2 = 0.0;
71
+
72
+  m_aref = aref;
73
+  m_rResistor = rResistor;
74
+}
75
+
76
+CWLSXXA::~CWLSXXA()
77
+{
78
+  if (m_aioHum)
79
+    delete m_aioHum;
80
+  if (m_aioTemp)
81
+    delete m_aioTemp;
82
+}
83
+
84
+void CWLSXXA::update()
85
+{
86
+  // temperature
87
+  int val;
88
+  float volts;
89
+  float milliamps = 0.0;
90
+
91
+  int samples;
92
+  if (m_rResistor)
93
+    samples = maxSamples;
94
+  else
95
+    samples = 1;
96
+
97
+
98
+  // temperature
99
+  if (m_hasTemp)
100
+    {
101
+      // fortunately, this sensor always reports temperatures in C,
102
+      // regardless of the configuration of the LCD display (for
103
+      // models that have an LCD display)
104
+
105
+      val = average(m_aioTemp, samples);
106
+
107
+      volts = (float(val) * (m_aref / m_aResTemp));
108
+
109
+      // valid range is 10-35C, current loop range is 16ma (20ma - 4ma)
110
+      if (!m_rResistor)
111
+        m_temperature = ((volts / m_aref) * 25.0) + 10.0;
112
+      else
113
+        {
114
+          milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
115
+          if (milliamps < 0.0) // not connected
116
+            milliamps = 0.0;
117
+          m_temperature = (milliamps * (25.0 / 16.0)) + 10.0;
118
+        }
119
+    }
120
+
121
+  // humidity
122
+  if (m_hasHum)
123
+    {
124
+      val = average(m_aioHum, samples);
125
+      volts = (float(val) * (m_aref / m_aResHum));
126
+
127
+      // range is 0-100
128
+      if (!m_rResistor)
129
+        m_humidity = ((volts / m_aref) * 100.0);
130
+      else
131
+        {
132
+          milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
133
+          if (milliamps < 0.0) // not connected
134
+            milliamps = 0.0;
135
+          m_humidity = milliamps * (100.0 / 16.0);
136
+        }
137
+    }
138
+
139
+  // CO2
140
+  val = average(&m_aioCO2, samples);
141
+  volts = (float(val) * (m_aref / m_aResCO2));
142
+  
143
+  // CO2 range is 0-2000ppm
144
+  if (!m_rResistor)
145
+    m_co2 = ((volts / m_aref) * 2000.0);
146
+  else
147
+    {
148
+      milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
149
+      if (milliamps < 0.0) // not connected
150
+        milliamps = 0.0;
151
+      m_co2 = milliamps * (2000.0 / 16.0);
152
+    }
153
+}
154
+
155
+float CWLSXXA::getTemperature(bool fahrenheit)
156
+{
157
+  if (fahrenheit)
158
+    return c2f(m_temperature);
159
+  else
160
+    return m_temperature;
161
+}
162
+
163
+float CWLSXXA::getHumidity()
164
+{
165
+  return m_humidity;
166
+}
167
+
168
+float CWLSXXA::getCO2()
169
+{
170
+  return m_co2;
171
+}
172
+
173
+int CWLSXXA::average(mraa::Aio *aio, int samples)
174
+{
175
+  if (samples <= 0)
176
+    samples = 1;
177
+
178
+  int avg = 0;
179
+  for (int i=0; i<samples; i++)
180
+    avg += aio->read();
181
+
182
+  return (avg / samples);
183
+}

+ 189
- 0
src/cwlsxxa/cwlsxxa.h ファイルの表示

@@ -0,0 +1,189 @@
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 CWLSXXA_DEFAULT_AREF 5.0
33
+
34
+namespace upm {
35
+    /**
36
+     * @brief Veris CWLSXXA CO2 Sensor
37
+     * @defgroup cwlsxxa libupm-cwlsxxa
38
+     * @ingroup veris ainput temp gaseous
39
+     */
40
+
41
+    /**
42
+     * @library cwlsxxa
43
+     * @sensor cwlsxxa
44
+     * @comname Veris CWLSXXA CO2 Sensor Family
45
+     * @type temp gaseous
46
+     * @man veris
47
+     * @con ainput
48
+     * @web http://www.veris.com/Item/CWLSHTA.aspx
49
+     *
50
+     * @brief API for the Veris CWLSXXA CO2 Sensor Family
51
+     *
52
+     * The driver was developed using the CWLSHTA CO2 Gas sensor.  The
53
+     * 'T' variant supports a temperature transmitter, and the 'H'
54
+     * variant supports a humidity sensor.  All 3 signals are provided
55
+     * by the device as analog 0-5Vdc, 0-10Vdc, or 4-20ma loop current
56
+     * outputs.  For devices supporting temperature, the valid
57
+     * temperature range is 10C to 50C.  The humidity ranges from 0%
58
+     * to 100% (non-condensing).  The CO2 sensor ranges from 0 to 2000
59
+     * ppm.
60
+     *
61
+     * This driver was developed using the 5Vdc outputs and the 4-20ma
62
+     * outputs.  For voltage outputs, your MCU must be configured for
63
+     * 5V operation.  In addition, you must configure the sensor (via
64
+     * it's configuration switches) to output 0-5VDC only.  Using any
65
+     * other analog reference voltage will require the appropriate
66
+     * external circuitry (such as a voltage divider) in order to
67
+     * interface safely with your MCU.
68
+     *
69
+     * In addition, the sensor can be configured for 4-20ma usage, by
70
+     * specifying the correct receiver resistance (in ohms) in the
71
+     * constructor.  This sensor was tested with a Cooking Hacks
72
+     * (Libelium) 4-channel 4-20ma Arduino interface shield.  For this
73
+     * interface, the receiver resistance was specified as 165.0 ohms.
74
+     *
75
+     * For devices which do not support temperature, use '-1' as the
76
+     * temperature pin number in the object constructor.  If
77
+     * temperature measurement is disabled, getTemperature() will always
78
+     * return 0C/32F.
79
+     *
80
+     * For devices which do not support humidity, use '-1' as the
81
+     * temperature pin number in the object constructor.  If
82
+     * humidity measurement is disabled, getHumidity() will always
83
+     * return 0.
84
+     *
85
+     * @snippet cwlsxxa.cxx Interesting
86
+     */
87
+
88
+  class CWLSXXA {
89
+  public:
90
+
91
+    /**
92
+     * CWLSXXA object constructor
93
+     *
94
+     * @param gPin Analog pin to use for the CO2 measurement
95
+     * @param hPin Analog pin to use for the humidity measurement.  If
96
+     * your device does not support humidity, use -1 as the value so
97
+     * that humidity will not be queried and an analog pin won't be
98
+     * wasted.
99
+     * @param tPin Analog pin to use for temperature.  If your device
100
+     * does not support temperature, use -1 as the value so that
101
+     * temperature will not be queried and an analog pin won't be
102
+     * wasted.
103
+     * @param rResistor The receiver resistance in ohms, when using a
104
+     * 4-20ma current loop interface.  When specified, this value will
105
+     * be used in computing the current based on the voltage read when
106
+     * scaling the return values.  Default is 0.0, for standard
107
+     * scaling based on voltage output rather than current (4-20ma
108
+     * mode).
109
+     * @param aref The analog reference voltage, default 5.0
110
+     */
111
+    CWLSXXA(int gPin, int hPin, int tPin, float rResistor=0.0,
112
+            float aref=CWLSXXA_DEFAULT_AREF);
113
+
114
+    /**
115
+     * CWLSXXA object destructor
116
+     */
117
+    ~CWLSXXA();
118
+
119
+    /**
120
+     * Read current values from the sensor and update internal stored
121
+     * values.  This method must be called prior to querying any
122
+     * values, such as CO2, temperature, or humidity.
123
+     */
124
+    void update();
125
+
126
+    /**
127
+     * Get the current temperature.  update() must have been called
128
+     * prior to calling this method.  If temperature measurement was
129
+     * disabled (by passing -1 as the temperature pin in the
130
+     * constructor) then this function will always return 0C/32F.
131
+     *
132
+     * @param fahrenheit true to return the temperature in degrees
133
+     * fahrenheit, false to return the temperature in degrees celcius.
134
+     * The default is false (degrees Celcius).
135
+     * @return The last temperature reading in Celcius or Fahrenheit
136
+     */
137
+    float getTemperature(bool fahrenheit=false);
138
+
139
+    /**
140
+     * Get the current relative humidity.  update() must have been called
141
+     * prior to calling this method. If humidity measurement was
142
+     * disabled (by passing -1 as the te pin in the
143
+     * constructor) then this function will always return 0.
144
+     *
145
+     * @return The last humidity reading
146
+     */
147
+    float getHumidity();
148
+
149
+    /**
150
+     * Get the current CO2 concentration in Parts Per Million (PPM).
151
+     * update() must have been called prior to calling this method.
152
+     *
153
+     * @return The last CO2 reading
154
+     */
155
+    float getCO2();
156
+
157
+
158
+  protected:
159
+    // temperature and humidity are optional features of this transmitter
160
+    mraa::Aio *m_aioTemp;
161
+    mraa::Aio *m_aioHum;
162
+
163
+    // CO2 reporting is always supported
164
+    mraa::Aio m_aioCO2;
165
+
166
+  private:
167
+    float m_aref;
168
+    float m_rResistor;
169
+    int m_aResTemp;
170
+    int m_aResHum;
171
+    int m_aResCO2;
172
+
173
+    // does this sensor support temperature and/or humidity reporting?
174
+    bool m_hasTemp;
175
+    bool m_hasHum;
176
+
177
+    // in Celcius
178
+    float m_temperature;
179
+
180
+    float m_humidity;
181
+
182
+    // in PPM
183
+    float m_co2;
184
+
185
+    int average(mraa::Aio *aio, int samples);
186
+  };
187
+}
188
+
189
+

+ 19
- 0
src/cwlsxxa/javaupm_cwlsxxa.i ファイルの表示

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

+ 10
- 0
src/cwlsxxa/jsupm_cwlsxxa.i ファイルの表示

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

+ 13
- 0
src/cwlsxxa/pyupm_cwlsxxa.i ファイルの表示

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