Explorar el Código

teams: Initial implementation

The driver adds support for the Veris TEAMS Temperature Transmitter.

It provides it's output via a 4-20ma current loop.  The supported
temperature range is 10C to 35C.

This sensor was developed with a Cooking Hacks (Libelium)
4-channel 4-20ma Arduino interface shield.  For this interface,
the receiver resistance (rResistor) 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 hace 8 años
padre
commit
42ff8b3a6e

+ 1
- 0
examples/c++/CMakeLists.txt Ver fichero

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

+ 84
- 0
examples/c++/teams.cxx Ver fichero

@@ -0,0 +1,84 @@
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 "teams.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 TEAMS instance, using A0 for temperature, and
50
+  // 165.0 ohms for the rResistor value (for the libelium 4-20ma
51
+  // interface)
52
+  upm::TEAMS *sensor = new upm::TEAMS(0, 165.0);
53
+
54
+  // update and print available values every second
55
+  while (shouldRun)
56
+    {
57
+      // update our values from the sensor
58
+      sensor->update();
59
+
60
+      // is the sensor connected? (current >= 4ma)
61
+      cout << "Is Connected: " << sensor->isConnected() << endl;
62
+
63
+      // print computed current on the loop.  This includes the offset,
64
+      // if one was set by setOffsetMilliamps().
65
+      cout << "Milliamps: " << sensor->getRawMilliamps() << endl;
66
+
67
+      // we show both C and F for temperature
68
+      cout << "Temperature: " << sensor->getTemperature()
69
+           << " C / " << sensor->getTemperature(true) << " F"
70
+           << endl;
71
+
72
+      cout << endl;
73
+
74
+      sleep(1);
75
+    }
76
+
77
+  cout << "Exiting..." << endl;
78
+
79
+  delete sensor;
80
+
81
+//! [Interesting]
82
+
83
+  return 0;
84
+}

+ 1
- 0
examples/java/CMakeLists.txt Ver fichero

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

+ 64
- 0
examples/java/TEAMS_Example.java Ver fichero

@@ -0,0 +1,64 @@
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_teams.TEAMS;
26
+
27
+public class TEAMS_Example 
28
+{
29
+    public static void main(String[] args) throws InterruptedException
30
+    {
31
+// ! [Interesting]
32
+        System.out.println("Initializing...");
33
+
34
+        // Instantiate an TEAMS instance, using A0 for temperature, and
35
+        // 165.0 ohms for the rResistor value (for the libelium 4-20ma
36
+        // interface)
37
+        TEAMS sensor = new TEAMS(0, 165.0f);
38
+        
39
+        while (true)
40
+            {
41
+                // update our values from the sensor
42
+                sensor.update();
43
+
44
+                // is the sensor connected? (current >= 4ma)
45
+                System.out.println("Is Connected: " + sensor.isConnected());
46
+    
47
+                // print computed current on the loop.  This includes
48
+                // the offset, if one was set by setOffsetMilliamps().
49
+                System.out.println("Milliamps: " + sensor.getRawMilliamps());
50
+
51
+                // we show both C and F for temperature
52
+                System.out.println("Temperature: " 
53
+                                   + sensor.getTemperature()
54
+                                   + " C / "
55
+                                   + sensor.getTemperature(true)
56
+                                   + " F");
57
+
58
+                System.out.println();
59
+                Thread.sleep(1000);
60
+            }
61
+
62
+// ! [Interesting]
63
+    }
64
+}

+ 70
- 0
examples/javascript/teams.js Ver fichero

@@ -0,0 +1,70 @@
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_teams');
30
+
31
+
32
+/************** Main code **************/
33
+
34
+console.log("Initializing...");
35
+
36
+// Instantiate an TEAMS instance, using A0 for temperature, and
37
+// 165.0 ohms for the rResistor value (for the libelium 4-20ma
38
+// interface)
39
+var sensor = new sensorObj.TEAMS(0, 165.0);
40
+
41
+// update and print available values every second
42
+setInterval(function()
43
+{
44
+    // update our values from the sensor
45
+    sensor.update();
46
+
47
+    // is the sensor connected? (current >= 4ma)
48
+    console.log("Is Connected:", sensor.isConnected());
49
+    
50
+    // print computed current on the loop.  This includes the offset,
51
+    // if one was set by setOffsetMilliamps().
52
+    console.log("Milliamps:", sensor.getRawMilliamps());
53
+
54
+    // we show both C and F for temperature
55
+    console.log("Temperature:", sensor.getTemperature(),
56
+                "C /", sensor.getTemperature(true), "F");
57
+
58
+    console.log("");
59
+
60
+}, 1000);
61
+
62
+
63
+process.on('SIGINT', function()
64
+{
65
+    sensor = null;
66
+    sensorObj.cleanUp();
67
+    sensorObj = null;
68
+    console.log("Exiting...");
69
+    process.exit(0);
70
+});

+ 65
- 0
examples/python/teams.py Ver fichero

@@ -0,0 +1,65 @@
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_teams 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 TEAMS instance, using A0 for temperature, and
44
+# 165.0 ohms for the rResistor value (for the libelium 4-20ma
45
+# interface)
46
+sensor = sensorObj.TEAMS(0, 165.0)
47
+
48
+# update and print available values every second
49
+while (1):
50
+        # update our values from the sensor
51
+        sensor.update()
52
+
53
+        # is the sensor connected? (current >= 4ma)
54
+        print "Is Connected:", sensor.isConnected()
55
+    
56
+        # print computed current on the loop.  This includes the offset,
57
+        # if one was set by setOffsetMilliamps().
58
+        print "Milliamps:", sensor.getRawMilliamps()
59
+
60
+        # we show both C and F for temperature
61
+        print "Temperature:", sensor.getTemperature(), "C /",
62
+        print sensor.getTemperature(True), "F"
63
+
64
+        print
65
+	time.sleep(1)

+ 5
- 0
src/teams/CMakeLists.txt Ver fichero

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

+ 19
- 0
src/teams/javaupm_teams.i Ver fichero

@@ -0,0 +1,19 @@
1
+%module javaupm_teams
2
+%include "../upm.i"
3
+%include "std_string.i"
4
+
5
+%include "teams.h"
6
+%{
7
+    #include "teams.h"
8
+%}
9
+
10
+%pragma(java) jniclasscode=%{
11
+    static {
12
+        try {
13
+            System.loadLibrary("javaupm_teams");
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/teams/jsupm_teams.i Ver fichero

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

+ 13
- 0
src/teams/pyupm_teams.i Ver fichero

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

+ 125
- 0
src/teams/teams.cxx Ver fichero

@@ -0,0 +1,125 @@
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 "teams.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
+TEAMS::TEAMS(int tPin, float rResistor, float aref) :
45
+  m_aioTemp(tPin)
46
+{
47
+  if (rResistor < 0.0)
48
+    {
49
+      throw std::out_of_range(std::string(__FUNCTION__) +
50
+                              ": rResistor must be >= 0.0");
51
+    }
52
+
53
+  m_aResTemp = (1 << m_aioTemp.getBit());
54
+
55
+  m_temperature = 0.0;
56
+
57
+  m_aref = aref;
58
+  m_rResistor = rResistor;
59
+  m_connected = false;
60
+
61
+  // this will only be non-zero when using a direct 4-20ma interface
62
+  // like libelium
63
+  m_rawMilliamps = 0.0;
64
+
65
+  m_offset = 0.0;
66
+}
67
+
68
+TEAMS::~TEAMS()
69
+{
70
+}
71
+
72
+void TEAMS::update()
73
+{
74
+  float milliamps = 0.0;
75
+
76
+  int val = average(maxSamples);
77
+  float volts = (float(val) * (m_aref / m_aResTemp));
78
+
79
+  // valid temp range is 25.0 (35C - 10C), current loop range is 16ma
80
+  // (20ma - 4ma)
81
+  if (m_rResistor)
82
+    {
83
+      // direct 4-20 current loop interface
84
+      milliamps = (volts / m_rResistor * 1000.0) + m_offset;
85
+      m_rawMilliamps = milliamps;
86
+
87
+      // subtract 0 (4ma) value
88
+      milliamps -= 4.0;
89
+      if (milliamps < 0.0) // not connected
90
+        {
91
+          milliamps = 0.0;
92
+          m_connected = false;
93
+        }
94
+      else
95
+        m_connected = true;
96
+
97
+      m_temperature = (milliamps * (25.0 / 16.0)) + 10.0;
98
+    }
99
+  else
100
+    {
101
+      // normal analog read, already scaled to 0-5v, always connected
102
+      m_temperature = ((volts / m_aref) * 25.0) + 10.0;
103
+      m_connected = true;
104
+    }
105
+}
106
+
107
+float TEAMS::getTemperature(bool fahrenheit)
108
+{
109
+  if (fahrenheit)
110
+    return c2f(m_temperature);
111
+  else
112
+    return m_temperature;
113
+}
114
+
115
+int TEAMS::average(int samples)
116
+{
117
+  if (samples <= 0)
118
+    samples = 1;
119
+
120
+  int avg = 0;
121
+  for (int i=0; i<samples; i++)
122
+    avg += m_aioTemp.read();
123
+
124
+  return (avg / samples);
125
+}

+ 174
- 0
src/teams/teams.h Ver fichero

@@ -0,0 +1,174 @@
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
32
+#define TEAMS_DEFAULT_AREF 5.0
33
+
34
+namespace upm {
35
+    /**
36
+     * @brief Veris TEAMS Temperature Transmitter
37
+     * @defgroup teams libupm-teams
38
+     * @ingroup veris ainput temp 
39
+     */
40
+
41
+    /**
42
+     * @library teams
43
+     * @sensor teams
44
+     * @comname Veris TEAMS Temperature Transmitter
45
+     * @type temp
46
+     * @man veris
47
+     * @con ainput
48
+     * @web http://www.veris.com/Item/TEAMS.aspx
49
+     *
50
+     * @brief API for the Veris TEAMS Temperature Transmitter
51
+     *
52
+     * The Veris TEAMS temperature sensor provides it's output via a
53
+     * 4-20ma current loop.  The supported temperature range is 10C to
54
+     * 35C.
55
+     *
56
+     * This sensor was developed with a Cooking Hacks (Libelium)
57
+     * 4-channel 4-20ma Arduino interface shield.  For this interface,
58
+     * the receiver resistance (rResistor) was specified as 165.0
59
+     * ohms.
60
+     *
61
+     * When using a 4-20ma current loop interface which scales the
62
+     * sensors' values to a 0-5vdc range, you can supply 0.0 as the
63
+     * rResistor value in the constructor (default), and it will act
64
+     * just like a normal analog input.
65
+     *
66
+     * @snippet teams.cxx Interesting
67
+     */
68
+
69
+  class TEAMS {
70
+  public:
71
+
72
+    /**
73
+     * TEAMS object constructor
74
+     *
75
+     * @param tPin Analog pin to use for temperature.
76
+     * @param rResistor The receiver resistance in ohms, when using a
77
+     * 4-20ma current loop interface.  When specified, this value will
78
+     * be used in computing the current based on the voltage read when
79
+     * scaling the return values.  Default is 0.0, for standard
80
+     * scaling based on voltage output rather than current (4-20ma
81
+     * mode).
82
+     * @param aref The analog reference voltage, default 5.0
83
+     */
84
+    TEAMS(int tPin, float rResistor=0.0, float aref=TEAMS_DEFAULT_AREF);
85
+
86
+    /**
87
+     * TEAMS object destructor
88
+     */
89
+    ~TEAMS();
90
+
91
+    /**
92
+     * Read current values from the sensor and update internal stored
93
+     * values.  This method must be called prior to querying any
94
+     * values, such as temperature.
95
+     */
96
+    void update();
97
+
98
+    /**
99
+     * Get the current temperature.  update() must have been called
100
+     * prior to calling this method.
101
+     *
102
+     * @param fahrenheit true to return the temperature in degrees
103
+     * fahrenheit, false to return the temperature in degrees celcius.
104
+     * The default is false (degrees Celcius).
105
+     * @return The last temperature reading in Celcius or Fahrenheit
106
+     */
107
+    float getTemperature(bool fahrenheit=false);
108
+
109
+    /**
110
+     * When using a direct 4-20ma interface (rResistor supplied in the
111
+     * constructor is >0.0), this function will return false when the
112
+     * computed milliamps falls below 4ma, indicating that the sensor
113
+     * is not connected.  If rResistor was specified as 0.0 in the
114
+     * constructor, this function will always return true.
115
+     *
116
+     * @return true if the sensor is connected, false otherwise.
117
+     */
118
+    bool isConnected()
119
+    {
120
+      return m_connected;
121
+    };
122
+
123
+    /**
124
+     * When using a direct 4-20ma interface (rResistor supplied in the
125
+     * constructor is >0.0), this function will return the computed
126
+     * milliamps (after the offset has been applied).  If rResistor was
127
+     * specified as 0.0 in the constructor, this function will always
128
+     * return 0.0.
129
+     *
130
+     * @return The last measured current in milliamps after any offset
131
+     * has been applied.
132
+     */
133
+    float getRawMilliamps()
134
+    {
135
+      return m_rawMilliamps;
136
+    };
137
+
138
+    /**
139
+     * Specify an offset in milliamps to be applied to the computed
140
+     * current prior to scaling and conversion.  This can be used to
141
+     * 'adjust' the computed value.  If rResistor was specified as 0.0
142
+     * in the constructor, this function will have no effect.
143
+     *
144
+     * @param offset a positive or negative value that will be applied
145
+     * to the computed current measured.
146
+     */
147
+    void setOffsetMilliamps(float offset)
148
+    {
149
+      m_offset = offset;
150
+    };
151
+
152
+  protected:
153
+    mraa::Aio m_aioTemp;
154
+
155
+  private:
156
+    float m_aref;
157
+    float m_rResistor;
158
+    int m_aResTemp;
159
+
160
+    // for a 4-20 ma loop
161
+    bool m_connected;
162
+    float m_rawMilliamps;
163
+
164
+    // in Celcius
165
+    float m_temperature;
166
+
167
+    // in case an offset should be applied to the cumputed current
168
+    float m_offset;
169
+
170
+    int average(int samples);
171
+  };
172
+}
173
+
174
+