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>
This commit is contained in:
Jon Trulson 2014-12-10 13:19:29 -07:00 committed by Sarah Knepper
parent f53fab80fd
commit 40e0595892
8 changed files with 253 additions and 0 deletions

View File

@ -67,6 +67,7 @@ add_executable (guvas12d-example guvas12d.cxx)
add_executable (groveloudness-example groveloudness.cxx)
add_executable (mpr121-example mpr121.cxx)
add_executable (ublox6-example ublox6.cxx)
add_executable (yg1006-example yg1006.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -121,6 +122,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d)
include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
include_directories (${PROJECT_SOURCE_DIR}/src/mpr121)
include_directories (${PROJECT_SOURCE_DIR}/src/ublox6)
include_directories (${PROJECT_SOURCE_DIR}/src/yg1006)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -191,3 +193,4 @@ target_link_libraries (guvas12d-example guvas12d ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -0,0 +1,47 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*global */
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var flameSensor = require('jsupm_yg1006');
// Instantiate a flame sensor on digital pin D2
var myFlameSensor = new flameSensor.YG1006(2);
// Check every second for the presence of a flame
setInterval(function()
{
if (myFlameSensor.flameDetected())
console.log("Flame detected.");
else
console.log("No flame detected.");
}, 1000);
// Print message when exiting
process.on('SIGINT', function()
{
console.log("Exiting...");
process.exit(0);
});

66
examples/yg1006.cxx Normal file
View File

@ -0,0 +1,66 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "yg1006.h"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a yg1006 flame sensor on digital pin D2
upm::YG1006* flame = new upm::YG1006(2);
// check every second for the presence of a flame
while (shouldRun)
{
bool val = flame->flameDetected();
if (val)
cout << "Flame detected." << endl;
else
cout << "No flame detected." << endl;
sleep(1);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete flame;
return 0;
}

View File

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

View File

@ -0,0 +1,8 @@
%module jsupm_yg1006
%include "../upm.i"
%{
#include "yg1006.h"
%}
%include "yg1006.h"

View File

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

51
src/yg1006/yg1006.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include "yg1006.h"
using namespace upm;
using namespace std;
YG1006::YG1006(int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) )
{
cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
}
YG1006::~YG1006()
{
mraa_gpio_close(m_gpio);
}
bool YG1006::flameDetected()
{
return (!mraa_gpio_read(m_gpio) ? true : false);
}

64
src/yg1006/yg1006.h Normal file
View File

@ -0,0 +1,64 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/gpio.h>
namespace upm {
/**
* @brief C++ API for the YG1006 flame sensor
*
* UPM module for the YG1006 flame sensor. It detects flame or any
* other light in the 760nm - 1100nm wavelength range.
*
* @ingroup gpio
* @snippet yg1006.cxx Interesting
*/
class YG1006 {
public:
/**
* YG1006 digital flame sensor constructor
*
* @param pin digital pin to use
*/
YG1006(int pin);
/**
* YG1006 Destructor
*/
~YG1006();
/**
* Determine whether a flame has been detected
*
* @return True if a flame or other comparable light source is detected
*/
bool flameDetected();
private:
mraa_gpio_context m_gpio;
};
}