upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Data Fields
HCSR04 Class Reference

C++ API for HCSR04 (ultrasonic ranging module) component. More...

Detailed Description

This file defines the HCSR04 C++ interface for libhcsr04

void
interrupt (void * args) {
sonar->ackEdgeDetected ();
}
int
main(int argc, char **argv)
{
sonar = new upm::HCSR04(5, 7, &interrupt);
signal(SIGINT, sig_handler);
printf ("width = %d\n", sonar->getDistance());
std::cout << "exiting application" << std::endl;
delete sonar;
return 0;
}

Public Member Functions

 HCSR04 (uint8_t triggerPin, uint8_t echoPin, void(*fptr)(void *))
 
 ~HCSR04 ()
 
int getDistance ()
 
void ackEdgeDetected ()
 
std::string name ()
 

Data Fields

uint8_t m_doWork
 

Constructor & Destructor Documentation

HCSR04 ( uint8_t  triggerPin,
uint8_t  echoPin,
void(*)(void *)  fptr 
)

Instanciates a HCSR04 object

Parameters
triggerPinpin for triggering the sensor for distance
echoPinpulse response to triggering
fptrfunction pointer for handling raising and falling interrupts
~HCSR04 ( )

HCSR04 object destructor.

Member Function Documentation

int getDistance ( )

Get the distance from the sensor.

void ackEdgeDetected ( )

On each interrupt this function will detect if the interrupt was falling edge or rising. Should be called from the interrupt handler.

std::string name ( )
inline

Return name of the component

Field Documentation

uint8_t m_doWork

Flag to controll blocking function while waiting for falling edge interrupt


The documentation for this class was generated from the following files: