Home | History | Annotate | Download | only in rpr220
      1 /*
      2  * Author: Jon Trulson <jtrulson (at) ics.com>
      3  * Copyright (c) 2015 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 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
     30 #include "../IsrCallback.h"
     31 #endif
     32 
     33 namespace upm {
     34 
     35 /**
     36  * @brief RPR220 IR Reflective Sensor library
     37  * @defgroup rpr220 libupm-rpr220
     38  * @ingroup seeed gpio light tsk hak
     39  */
     40 /**
     41  * @library rpr220
     42  * @sensor rpr220
     43  * @comname RPR220 IR Reflective Sensor
     44  * @altname Grove IR Reflective Sensor
     45  * @type light
     46  * @man seeed
     47  * @web http://www.seeedstudio.com/wiki/Grove_-_Infrared_Reflective_Sensor
     48  * @con gpio
     49  * @kit tsk hak
     50  *
     51  * @brief API for the RPR220-based Grove IR Reflective Sensor
     52  *
     53  * UPM module for the Grove IR reflective sensor. The sensitivity
     54  * can be adjusted with the potentiometer on the sensor module. It
     55  * has a range of approximately 15 mm, and a quick response time.
     56  *
     57  * It detects high-contrast dark areas on a light background.
     58  *
     59  * This module allows the user to determine the current status
     60  * (black detected or not). Additionally, if desired, an interrupt
     61  * service routine (ISR) can be installed that is called when
     62  * black is detected. Either method can be used, depending on your
     63  * use case.
     64  *
     65  * @image html rpr220.jpg
     66  * @snippet rpr220.cxx Interesting
     67  * @snippet rpr220-intr.cxx Interesting
     68  */
     69   class RPR220 {
     70   public:
     71     /**
     72      * RPR220 constructor
     73      *
     74      * @param pin Digital pin to use
     75      */
     76     RPR220(int pin);
     77 
     78     /**
     79      * RPR220 destructor
     80      */
     81     ~RPR220();
     82 
     83     /**
     84      * Gets the status of the pin; true means black has been detected
     85      *
     86      * @return True if the sensor has detected black
     87      */
     88     bool blackDetected();
     89 
     90 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
     91     void installISR(IsrCallback *cb);
     92 #else
     93     /**
     94      * Installs an ISR to be called when
     95      * black is detected
     96      *
     97      * @param fptr Pointer to a function to be called on interrupt
     98      * @param arg Pointer to an object to be supplied as an
     99      * argument to the ISR.
    100      */
    101     void installISR(void (*isr)(void *), void *arg);
    102 #endif
    103 
    104     /**
    105      * Uninstalls the previously installed ISR
    106      *
    107      */
    108     void uninstallISR();
    109 
    110   private:
    111 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
    112     void installISR(void (*isr)(void *), void *arg);
    113 #endif
    114     bool m_isrInstalled;
    115     mraa_gpio_context m_gpio;
    116   };
    117 }
    118 
    119 
    120