Easyuino  1.2.0
Easyuino::DistanceMeterNonBlock Class Reference

DistanceMeterNonBlock offers an API to interact with an Ultrasonic Module to measure distance in a non-block way. More...

#include <DistanceMeterNonBlock.h>

Inheritance diagram for Easyuino::DistanceMeterNonBlock:
Easyuino::DistanceMeter Easyuino::Device Easyuino::DistanceMeterAccurate

Public Member Functions

 DistanceMeterNonBlock (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeterNonBlock (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeterNonBlock ()
 Destructor.
 
bool begin ()
 Used to put the device ready to receive requests. More...
 
void end ()
 Used to stop the device API. More...
 
float getDistanceCentimeters ()
 Gets the last value that the API measured using the Ultrasonic Module. More...
 
void updateDistance ()
 Updates the distance of the Ultrasonic Module to the objects in a blocking way. More...
 
virtual void updateDistanceNonBlock ()
 Updates the distance of the Ultrasonic Module to the objects in a non-blocking way. More...
 
- Public Member Functions inherited from Easyuino::DistanceMeter
 DistanceMeter (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeter (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeter ()
 Destructor.
 
float getDistanceInches ()
 Gets the last value that the API measured using the US. More...
 
- Public Member Functions inherited from Easyuino::Device
 Device ()
 Constructor called by every sub-classes.
 
 ~Device ()
 Destroy all the resources associated with the device.
 
bool isInitialized () const
 Verify is the device is initialized and ready to use. More...
 

Protected Member Functions

void executeUpdateDistanceNonBlock ()
 Execute a non-block distance measurement.
 
bool isUpdateDistanceNonBlockTimeout ()
 Verify if there is a non-block measuremenet on going that has already timeouted. More...
 
float calculateDistance (IN float soundSpeedCmPerSec)
 Calculates the distance to the object based on the sound speed in air using the last distance value measured! More...
 
- Protected Member Functions inherited from Easyuino::DistanceMeter
float executeUpdateDistanceBlock (IN float soundSpeed)
 Execute a block distance measurement and calculates the distance based on the sound speed. More...
 

Additional Inherited Members

- Protected Attributes inherited from Easyuino::DistanceMeter
uint8_t _triggerPin
 Arduino pin used to trigger the echo wave emission.
 
uint8_t _echoPin
 Arduino pin that is set to LOW by when reflected echo wave arrives.
 
volatile bool _isEchoing
 Used to know if it is in a middle of a measurement.
 
volatile float _distance
 It contains a cached value of the last distance measured. More...
 
- Protected Attributes inherited from Easyuino::Device
bool _isInitialized
 Used to know if the device API is initialized and ready to receive requests.
 

Detailed Description

DistanceMeterNonBlock offers an API to interact with an Ultrasonic Module to measure distance in a non-block way.

It offers a the same as DistanceMeter API plus updateDistanceNonBlock() that allows your application code run while the distance is calculated in "background" without stopping your program.

See also
Limitation: This allows ONLY 2 instances of DistanceMeterNonBlock per sketch!!
Limitation: The accuracy of the non-block method is much smaller because it uses interruption mechanism
Devices Supported: HC-SR03, HC-SR04, HC-SR05
Devices Tested: HC-SR04

Constructor & Destructor Documentation

◆ DistanceMeterNonBlock() [1/2]

Easyuino::DistanceMeterNonBlock::DistanceMeterNonBlock ( IN uint8_t  triggerPin,
IN uint8_t  echoPin 
)

Constructor.

Parameters
triggerPinArduino pin connected to the trigger pin of the Ultrasonic Module
echoPinArduino pin connected to the echo pin of the Ultrasonic Module

◆ DistanceMeterNonBlock() [2/2]

Easyuino::DistanceMeterNonBlock::DistanceMeterNonBlock ( IN uint8_t  triggerEchoPin)

Contructor used with Ultrasonic Modules that have only one pin for trigger and echo.

Parameters
triggerEchoPinArduino pin connected to the trigger&echo pin of the Ultrasonic Module

Member Function Documentation

◆ begin()

bool Easyuino::DistanceMeterNonBlock::begin ( )
virtual

Used to put the device ready to receive requests.

Normally this have some default behaviour some devices have other overload method with same name that receives other arguments to device customization.

Returns
True: If the device was initialized. False: Otherwise.

Reimplemented from Easyuino::DistanceMeter.

◆ calculateDistance()

float Easyuino::DistanceMeterNonBlock::calculateDistance ( IN float  soundSpeedCmPerSec)
protected

Calculates the distance to the object based on the sound speed in air using the last distance value measured!

Parameters
soundSpeedCmPerSec(Cm/Sec) The sound speed to be taken in account during the calculation
Returns
distance (Centimeters) The new calculated distance

◆ end()

void Easyuino::DistanceMeterNonBlock::end ( )
virtual

Used to stop the device API.

After this the the device will not process API requests.

Reimplemented from Easyuino::DistanceMeter.

◆ getDistanceCentimeters()

float Easyuino::DistanceMeterNonBlock::getDistanceCentimeters ( )
virtual

Gets the last value that the API measured using the Ultrasonic Module.

Returns
distance (Centimeters) The most recent measurement the API have done

Reimplemented from Easyuino::DistanceMeter.

◆ isUpdateDistanceNonBlockTimeout()

bool Easyuino::DistanceMeterNonBlock::isUpdateDistanceNonBlockTimeout ( )
protected

Verify if there is a non-block measuremenet on going that has already timeouted.

Returns
True: If it timeout. False: Otherwise.

◆ updateDistance()

void Easyuino::DistanceMeterNonBlock::updateDistance ( )
virtual

Updates the distance of the Ultrasonic Module to the objects in a blocking way.

The new distance value is available using getDistanceCentimeters() or getDistanceInches() method after calling this method.

Warning
This method blocks while the measurement is on going, so the arduino waits for the measure to be concluded, if you want a non block update distance method look for DistanceMeterNonBlock API

Reimplemented from Easyuino::DistanceMeter.

◆ updateDistanceNonBlock()

virtual void Easyuino::DistanceMeterNonBlock::updateDistanceNonBlock ( )
virtual

Updates the distance of the Ultrasonic Module to the objects in a non-blocking way.

This means that the call to the method will return immediatly and in the "background" the distance measure will ocurr after a while. When the measurement is concluded and you call getDistanceCentimeters() or getDistanceInches() the new distance value will be returned. While the measurement is on going the distance will be from the last measurement.


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