upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for rpr220.h:

API Description

/*
* 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.
*/
#include <unistd.h>
#include <signal.h>
#include <upm_utilities.h>
#include <rpr220.h>
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// This example uses a simple method to determine current status
// Instantiate an RPR220 digital pin D2
// This was tested on the Grove IR Reflective Sensor
if (!sensor)
{
printf("rpr220_init() failed\n");
return 1;
}
while (shouldRun)
{
if (rpr220_black_detected(sensor))
printf("Black detected\n");
else
printf("Black NOT detected\n");
upm_delay_ms(100); // 100ms
}
printf("Exiting...\n");
rpr220_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _rpr220_context
 

Functions

rpr220_context rpr220_init (int pin)
 
void rpr220_close (rpr220_context dev)
 
bool rpr220_black_detected (const rpr220_context dev)
 
void rpr220_install_isr (const rpr220_context dev, void(*isr)(void *), void *arg)
 
void rpr220_uninstall_isr (const rpr220_context dev)
 

Typedefs

typedef struct _rpr220_contextrpr220_context
 

Function Documentation

rpr220_context rpr220_init ( int  pin)

RPR220 initialization.

Parameters
pinDigital pin to use.
Returns
rpr220 device context

Here is the call graph for this function:

void rpr220_close ( rpr220_context  dev)

RPR220 destructor

Parameters
devDevice context.

Here is the call graph for this function:

Here is the caller graph for this function:

bool rpr220_black_detected ( const rpr220_context  dev)

Gets the status of the pin; true means black has been detected

Parameters
devDevice context.
Returns
True if the sensor has detected black

Here is the caller graph for this function:

void rpr220_install_isr ( const rpr220_context  dev,
void(*)(void *)  isr,
void *  arg 
)

Installs an ISR to be called when black is detected

Parameters
devDevice context.
isrPointer to a function to be called on interrupt
argPointer to an object to be supplied as an argument to the ISR.

Here is the call graph for this function:

Here is the caller graph for this function:

void rpr220_uninstall_isr ( const rpr220_context  dev)

Uninstalls the previously installed ISR

Parameters
devDevice context.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _rpr220_context * rpr220_context

Device context