HCSR04: Modifying implementation and adding examples

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2017-06-07 10:46:57 -07:00
parent 28f964cb48
commit b90c5a7710
13 changed files with 391 additions and 138 deletions

View File

@@ -24,14 +24,7 @@
*/
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/pwm.h>
#include <sys/time.h>
#define CM 1
#define INC 0
#include "hcsr04.h"
namespace upm {
/**
@@ -73,37 +66,13 @@ class HCSR04 {
/**
* Gets the distance from the sensor
*
* @param sys Selects units for measurement: 0 = inch, 1 = cm
* @param unit Selects units for measurement
*/
double getDistance (int sys);
uint8_t m_doWork; /**< Flag to control blocking function while waiting for a falling-edge interrupt */
/**
* Returns the name of the sensor
*/
std::string name()
{
return m_name;
}
double getDistance (HCSR04_U unit);
private:
/**
* On each interrupt, this function detects if the interrupt
* was falling-edge or rising-edge.
*/
static void ackEdgeDetected (void *ctx);
double timing();
mraa_gpio_context m_triggerPinCtx;
mraa_gpio_context m_echoPinCtx;
long m_RisingTimeStamp;
long m_FallingTimeStamp;
uint8_t m_InterruptCounter;
std::string m_name;
};
hcsr04_context m_hcsr04;
HCSR04(const HCSR04& src) { /* do not create copied constructor */ }
HCSR04& operator=(const HCSR04&) {return *this;}
};
}