Browse Source

mq2:: added new sensor

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 years ago
parent
commit
30187ba5f9
5 changed files with 171 additions and 2 deletions
  1. 2
    0
      examples/CMakeLists.txt
  2. 74
    0
      examples/mq2-example.cxx
  3. 2
    2
      src/gas/CMakeLists.txt
  4. 33
    0
      src/gas/mq2.cxx
  5. 60
    0
      src/gas/mq2.h

+ 2
- 0
examples/CMakeLists.txt View File

@@ -29,6 +29,7 @@ add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx)
29 29
 add_executable (lpd8806-example lpd8806-example.cxx)
30 30
 add_executable (mlx90614-example mlx90614-example.cxx)
31 31
 add_executable (ecs1030-example ecs1030-example.cxx)
32
+add_executable (mq2-example mq2-example.cxx)
32 33
 add_executable (mq9-example mq9-example.cxx)
33 34
 
34 35
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
@@ -89,4 +90,5 @@ target_link_libraries (nrf8001-helloworld-example nrf8001 ${CMAKE_THREAD_LIBS_IN
89 90
 target_link_libraries (lpd8806-example lpd8806 ${CMAKE_THREAD_LIBS_INIT})
90 91
 target_link_libraries (mlx90614-example mlx90614 ${CMAKE_THREAD_LIBS_INIT})
91 92
 target_link_libraries (ecs1030-example ecs1030 ${CMAKE_THREAD_LIBS_INIT})
93
+target_link_libraries (mq2-example gas ${CMAKE_THREAD_LIBS_INIT})
92 94
 target_link_libraries (mq9-example gas ${CMAKE_THREAD_LIBS_INIT})

+ 74
- 0
examples/mq2-example.cxx View File

@@ -0,0 +1,74 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 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 "mq2.h"
28
+#include <signal.h>
29
+#include <stdlib.h>
30
+#include <sys/time.h>
31
+
32
+int is_running = 0;
33
+uint16_t buffer [128];
34
+upm::MQ2 *sensor = NULL;
35
+
36
+void
37
+sig_handler(int signo)
38
+{
39
+    printf("got signal\n");
40
+    if (signo == SIGINT) {
41
+        is_running = 1;
42
+    }
43
+}
44
+
45
+//! [Interesting]
46
+int
47
+main(int argc, char **argv)
48
+{
49
+    sensor = new upm::MQ2(0);
50
+    signal(SIGINT, sig_handler);
51
+
52
+    thresholdContext ctx;
53
+    ctx.averageReading = 0;
54
+    ctx.runningAverage = 0;
55
+    ctx.averagedOver   = 2;
56
+
57
+    while (!is_running) {
58
+        int len = sensor->getSampledWindow (2, 128, buffer);
59
+        if (len) {
60
+            int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
61
+            sensor->printGraph(&ctx, 5);
62
+            if (thresh) {
63
+                // do something ....
64
+            }
65
+        }
66
+    }
67
+
68
+    std::cout << "exiting application" << std::endl;
69
+
70
+    delete sensor;
71
+
72
+    return 0;
73
+}
74
+//! [Interesting]

+ 2
- 2
src/gas/CMakeLists.txt View File

@@ -1,5 +1,5 @@
1 1
 set (libname "gas")
2 2
 set (libdescription "Gas sensors")
3
-set (module_src ${libname}.cxx mq9.cxx)
4
-set (module_h ${libname}.h mq9.h)
3
+set (module_src ${libname}.cxx mq2.cxx mq9.cxx)
4
+set (module_h ${libname}.h mq2.h mq9.h)
5 5
 upm_module_init()

+ 33
- 0
src/gas/mq2.cxx View File

@@ -0,0 +1,33 @@
1
+/*
2
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3
+ * Copyright (c) 2014 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 "mq2.h"
26
+
27
+using namespace upm;
28
+
29
+MQ2::MQ2 (int gasPin) : Gas (gasPin) {
30
+}
31
+
32
+MQ2::~MQ2 () {
33
+}

+ 60
- 0
src/gas/mq2.h View File

@@ -0,0 +1,60 @@
1
+/*
2
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3
+ * Copyright (c) 2014 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 <iostream>
27
+#include <string>
28
+#include "gas.h"
29
+
30
+namespace upm {
31
+    /**
32
+     * @brief C++ API for MQ2 gas sensor
33
+     *
34
+     * @snippet mq2-example.cxx Interesting
35
+     */
36
+    class MQ2 : public Gas {
37
+        public:
38
+            /**
39
+             * MQ2 constructor
40
+             *
41
+             * @param gasPin analog pin where sensor connected
42
+             */
43
+            MQ2 (int gasPin);
44
+
45
+            /**
46
+             * MQ2 destructor
47
+             */
48
+            ~MQ2 ();
49
+
50
+            /**
51
+             * Return name of the component
52
+             */
53
+            std::string name()
54
+            {
55
+                return m_name;
56
+            }
57
+        private:
58
+            std::string m_name;
59
+    };
60
+}