2015-01-14 15:13:55 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2015 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>
|
|
|
|
|
2015-08-18 16:57:38 +03:00
|
|
|
#ifdef SWIGJAVA
|
|
|
|
#include "../IsrCallback.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-14 15:13:55 -07:00
|
|
|
namespace upm {
|
|
|
|
|
2015-04-14 11:52:38 -07:00
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* @brief RPR220 IR Reflective Sensor library
|
2015-04-14 11:52:38 -07:00
|
|
|
* @defgroup rpr220 libupm-rpr220
|
2015-06-24 13:39:09 -07:00
|
|
|
* @ingroup seeed gpio light tsk hak
|
2015-04-14 11:52:38 -07:00
|
|
|
*/
|
|
|
|
/**
|
2015-04-14 17:35:47 -07:00
|
|
|
* @library rpr220
|
2015-04-14 11:52:38 -07:00
|
|
|
* @sensor rpr220
|
2015-06-01 15:44:07 -07:00
|
|
|
* @comname RPR220 IR Reflective Sensor
|
|
|
|
* @altname Grove IR Reflective Sensor
|
2015-04-14 11:52:38 -07:00
|
|
|
* @type light
|
|
|
|
* @man seeed
|
|
|
|
* @web http://www.seeedstudio.com/wiki/Grove_-_Infrared_Reflective_Sensor
|
|
|
|
* @con gpio
|
2015-06-24 13:39:09 -07:00
|
|
|
* @kit tsk hak
|
2015-04-14 11:52:38 -07:00
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* @brief API for the RPR220-based Grove IR Reflective Sensor
|
2015-04-14 11:52:38 -07:00
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* UPM module for the Grove IR reflective sensor. The sensitivity
|
|
|
|
* can be adjusted with the potentiometer on the sensor module. It
|
|
|
|
* has a range of approximately 15 mm, and a quick response time.
|
2015-04-14 11:52:38 -07:00
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* It detects high-contrast dark areas on a light background.
|
2015-04-14 11:52:38 -07:00
|
|
|
*
|
|
|
|
* This module allows the user to determine the current status
|
2015-08-10 18:53:31 +03:00
|
|
|
* (black detected or not). Additionally, if desired, an interrupt
|
|
|
|
* service routine (ISR) can be installed that is called when
|
|
|
|
* black is detected. Either method can be used, depending on your
|
2015-04-14 11:52:38 -07:00
|
|
|
* use case.
|
|
|
|
*
|
2015-04-14 16:00:25 -07:00
|
|
|
* @image html rpr220.jpg
|
2015-04-14 11:52:38 -07:00
|
|
|
* @snippet rpr220.cxx Interesting
|
|
|
|
* @snippet rpr220-intr.cxx Interesting
|
|
|
|
*/
|
2015-01-14 15:13:55 -07:00
|
|
|
class RPR220 {
|
|
|
|
public:
|
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* RPR220 constructor
|
2015-01-14 15:13:55 -07:00
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* @param pin Digital pin to use
|
2015-01-14 15:13:55 -07:00
|
|
|
*/
|
|
|
|
RPR220(int pin);
|
|
|
|
|
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* RPR220 destructor
|
2015-01-14 15:13:55 -07:00
|
|
|
*/
|
|
|
|
~RPR220();
|
|
|
|
|
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* Gets the status of the pin; true means black has been detected
|
2015-01-14 15:13:55 -07:00
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* @return True if the sensor has detected black
|
2015-01-14 15:13:55 -07:00
|
|
|
*/
|
|
|
|
bool blackDetected();
|
|
|
|
|
2015-08-18 16:57:38 +03:00
|
|
|
#ifdef SWIGJAVA
|
|
|
|
void installISR(IsrCallback *cb);
|
|
|
|
#else
|
2015-01-14 15:13:55 -07:00
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* Installs an ISR to be called when
|
2015-01-14 15:13:55 -07:00
|
|
|
* black is detected
|
|
|
|
*
|
2015-08-10 18:53:31 +03:00
|
|
|
* @param fptr Pointer to a function to be called on interrupt
|
|
|
|
* @param arg Pointer to an object to be supplied as an
|
|
|
|
* argument to the ISR.
|
2015-01-14 15:13:55 -07:00
|
|
|
*/
|
|
|
|
void installISR(void (*isr)(void *), void *arg);
|
2015-08-18 16:57:38 +03:00
|
|
|
#endif
|
2015-01-14 15:13:55 -07:00
|
|
|
|
|
|
|
/**
|
2015-08-10 18:53:31 +03:00
|
|
|
* Uninstalls the previously installed ISR
|
2015-01-14 15:13:55 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
void uninstallISR();
|
|
|
|
|
|
|
|
private:
|
2015-08-18 16:57:38 +03:00
|
|
|
#ifdef SWIGJAVA
|
|
|
|
void installISR(void (*isr)(void *), void *arg);
|
|
|
|
#endif
|
2015-01-14 15:13:55 -07:00
|
|
|
bool m_isrInstalled;
|
|
|
|
mraa_gpio_context m_gpio;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|