Browse Source

yg1006: Initial implementation

This module implements support for the yg1006 flame sensor.  It was
tested with the Grove Flame Sensor.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Jon Trulson 10 years ago
parent
commit
40e0595892

+ 3
- 0
examples/CMakeLists.txt View File

@@ -67,6 +67,7 @@ add_executable (guvas12d-example guvas12d.cxx)
67 67
 add_executable (groveloudness-example groveloudness.cxx)
68 68
 add_executable (mpr121-example mpr121.cxx)
69 69
 add_executable (ublox6-example ublox6.cxx)
70
+add_executable (yg1006-example yg1006.cxx)
70 71
 
71 72
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
72 73
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -121,6 +122,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d)
121 122
 include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
122 123
 include_directories (${PROJECT_SOURCE_DIR}/src/mpr121)
123 124
 include_directories (${PROJECT_SOURCE_DIR}/src/ublox6)
125
+include_directories (${PROJECT_SOURCE_DIR}/src/yg1006)
124 126
 
125 127
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
126 128
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -191,3 +193,4 @@ target_link_libraries (guvas12d-example guvas12d ${CMAKE_THREAD_LIBS_INIT})
191 193
 target_link_libraries (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_INIT})
192 194
 target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT})
193 195
 target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT})
196
+target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT})

+ 47
- 0
examples/javascript/yg1006.js View File

@@ -0,0 +1,47 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+/*global */
4
+/*
5
+* Author: Zion Orent <zorent@ics.com>
6
+* Copyright (c) 2014 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
+var flameSensor = require('jsupm_yg1006');
29
+
30
+// Instantiate a flame sensor on digital pin D2
31
+var myFlameSensor = new flameSensor.YG1006(2);
32
+
33
+// Check every second for the presence of a flame
34
+setInterval(function()
35
+{
36
+	if (myFlameSensor.flameDetected())
37
+		console.log("Flame detected.");
38
+	else
39
+		console.log("No flame detected.");
40
+}, 1000);
41
+
42
+// Print message when exiting
43
+process.on('SIGINT', function()
44
+{
45
+	console.log("Exiting...");
46
+	process.exit(0);
47
+});

+ 66
- 0
examples/yg1006.cxx View File

@@ -0,0 +1,66 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.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 <signal.h>
28
+#include "yg1006.h"
29
+
30
+using namespace std;
31
+
32
+int shouldRun = true;
33
+
34
+void sig_handler(int signo)
35
+{
36
+  if (signo == SIGINT)
37
+    shouldRun = false;
38
+}
39
+
40
+
41
+int main ()
42
+{
43
+  signal(SIGINT, sig_handler);
44
+
45
+//! [Interesting]
46
+  // Instantiate a yg1006 flame sensor on digital pin D2
47
+  upm::YG1006* flame = new upm::YG1006(2);
48
+  
49
+  // check every second for the presence of a flame
50
+  while (shouldRun)
51
+    {
52
+      bool val = flame->flameDetected();
53
+      if (val)
54
+        cout << "Flame detected." << endl;
55
+      else
56
+        cout << "No flame detected." << endl;
57
+
58
+      sleep(1);
59
+    }
60
+//! [Interesting]
61
+
62
+  cout << "Exiting..." << endl;
63
+
64
+  delete flame;
65
+  return 0;
66
+}

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

@@ -0,0 +1,5 @@
1
+set (libname "yg1006")
2
+set (libdescription "upm yg1006 flame sensor module")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 8
- 0
src/yg1006/jsupm_yg1006.i View File

@@ -0,0 +1,8 @@
1
+%module jsupm_yg1006
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "yg1006.h"
6
+%}
7
+
8
+%include "yg1006.h"

+ 9
- 0
src/yg1006/pyupm_yg1006.i View File

@@ -0,0 +1,9 @@
1
+%module pyupm_yg1006
2
+%include "../upm.i"
3
+
4
+%feature("autodoc", "3");
5
+
6
+%include "yg1006.h"
7
+%{
8
+    #include "yg1006.h"
9
+%}

+ 51
- 0
src/yg1006/yg1006.cxx View File

@@ -0,0 +1,51 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.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 <iostream>
26
+
27
+#include "yg1006.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+YG1006::YG1006(int pin)
33
+{
34
+  if ( !(m_gpio = mraa_gpio_init(pin)) )
35
+    {
36
+      cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
37
+      return;
38
+    }
39
+
40
+  mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
41
+}
42
+
43
+YG1006::~YG1006()
44
+{
45
+  mraa_gpio_close(m_gpio);
46
+}
47
+
48
+bool YG1006::flameDetected()
49
+{
50
+  return (!mraa_gpio_read(m_gpio) ? true : false);
51
+}

+ 64
- 0
src/yg1006/yg1006.h View File

@@ -0,0 +1,64 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.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 <string>
27
+#include <mraa/gpio.h>
28
+
29
+namespace upm {
30
+
31
+  /**
32
+   * @brief C++ API for the YG1006 flame sensor
33
+   *
34
+   * UPM module for the YG1006 flame sensor.  It detects flame or any
35
+   * other light in the 760nm - 1100nm wavelength range.
36
+   *
37
+   * @ingroup gpio
38
+   * @snippet yg1006.cxx Interesting
39
+   */
40
+  class YG1006 {
41
+  public:
42
+    /**
43
+     * YG1006 digital flame sensor constructor
44
+     *
45
+     * @param pin digital pin to use
46
+     */
47
+    YG1006(int pin);
48
+    /**
49
+     * YG1006 Destructor
50
+     */
51
+    ~YG1006();
52
+    /**
53
+     * Determine whether a flame has been detected
54
+     *
55
+     * @return True if a flame or other comparable light source is detected
56
+     */
57
+    bool flameDetected();
58
+
59
+  private:
60
+    mraa_gpio_context m_gpio;
61
+  };
62
+}
63
+
64
+