light: Added light sensor C source

Added the C source for the light sensor with necessary changes to cmake,
examples, docs.

    * Renamed all files with grovelight to light
    * Replaced all instances of grovelight with light
    * Added C source for light sensor
    * Updated all cmake files
    * Added C example for light sensor
    * Split out light sensor from grove library

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-09 14:10:30 -07:00
parent 0e52ea619b
commit 571f9c9498
25 changed files with 564 additions and 51 deletions

View File

@ -1,5 +1,8 @@
set (libname "grove")
set (libdescription "upm grove module")
set (module_src grovebutton.cxx groveled.cxx grovelight.cxx groverelay.cxx groverotary.cxx groveslide.cxx grovetemp.cxx)
set (module_hpp grovebutton.hpp groveled.hpp grovelight.hpp groverelay.hpp groverotary.hpp groveslide.hpp grovetemp.hpp grovebase.hpp grove.hpp)
upm_module_init()
upm_mixed_module_init (NAME grove
DESCRIPTION "upm grove module"
CPP_HDR grovebutton.hpp groveled.hpp groverelay.hpp groverotary.hpp
groveslide.hpp grovetemp.hpp grovebase.hpp
grove.hpp
CPP_SRC grovebutton.cxx groveled.cxx groverelay.cxx groverotary.cxx
groveslide.cxx grovetemp.cxx
REQUIRES mraa)

View File

@ -27,7 +27,6 @@
#include <grovebutton.hpp>
#include <groveled.hpp>
#include <grovelight.hpp>
#include <groverelay.hpp>
#include <groverotary.hpp>
#include <groveslide.hpp>

View File

@ -1,63 +0,0 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <string>
#include <stdexcept>
#include "grovelight.hpp"
#include "math.h"
using namespace upm;
GroveLight::GroveLight(unsigned int pin)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Light Sensor";
}
GroveLight::~GroveLight()
{
mraa_aio_close(m_aio);
}
int GroveLight::value()
{
// rough conversion to lux, using formula from Grove Starter Kit booklet
float a = (float) mraa_aio_read(m_aio);
if (a == -1.0) return -1;
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
return (int) round(a);
}
float GroveLight::raw_value()
{
return (float) mraa_aio_read(m_aio);
}

View File

@ -1,82 +0,0 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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/aio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor grovelight
* @comname Grove Light Sensor
* @type light
* @man seeed
* @con analog
* @kit gsk
*
* @brief API for the Grove Light Sensor
*
* The Grove light sensor detects the intensity of the ambient light.
* As the light intensity of the environment increases, the resistance
* of the sensor decreases. This means the raw value from the
* analog pin is larger in bright light and smaller in the dark.
* An approximate lux value can also be returned.
*
* @image html grovelight.jpg
* @snippet grovelight.cxx Interesting
*/
class GroveLight: public Grove {
public:
/**
* Grove analog light sensor constructor
*
* @param pin Analog pin to use
*/
GroveLight(unsigned int pin);
/**
* GroveLight destructor
*/
~GroveLight();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets an approximate light value, in lux, from the sensor
*
* @return Normalized light reading in lux
*/
int value();
private:
mraa_aio_context m_aio;
};
}

View File

@ -24,11 +24,6 @@
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"

View File

@ -21,11 +21,6 @@
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"

View File

@ -25,11 +25,6 @@
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"