mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
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:

committed by
Sarah Knepper

parent
f53fab80fd
commit
40e0595892
5
src/yg1006/CMakeLists.txt
Normal file
5
src/yg1006/CMakeLists.txt
Normal 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()
|
8
src/yg1006/jsupm_yg1006.i
Normal file
8
src/yg1006/jsupm_yg1006.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_yg1006
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "yg1006.h"
|
||||
%}
|
||||
|
||||
%include "yg1006.h"
|
9
src/yg1006/pyupm_yg1006.i
Normal file
9
src/yg1006/pyupm_yg1006.i
Normal 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
51
src/yg1006/yg1006.cxx
Normal 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
64
src/yg1006/yg1006.h
Normal 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user