mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 09:20:39 +03:00
Added iProximity interface
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
6d8e6d8a9f
commit
75c7bd8d12
39
include/interfaces/iProximity.hpp
Normal file
39
include/interfaces/iProximity.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
|
||||||
|
* Copyright (c) 2018 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace upm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Interface for Proximity sensors
|
||||||
|
*/
|
||||||
|
class iProximity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~iProximity() {}
|
||||||
|
|
||||||
|
virtual float getValue() = 0;
|
||||||
|
};
|
||||||
|
}
|
@ -67,3 +67,8 @@ float GP2Y0A::value(float aref, uint8_t samples)
|
|||||||
|
|
||||||
return volts;
|
return volts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GP2Y0A::getValue()
|
||||||
|
{
|
||||||
|
return GP2Y0A::value(5.0, (uint8_t) 1);
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/aio.h>
|
#include <mraa/aio.h>
|
||||||
|
#include <interfaces/iProximity.hpp>
|
||||||
|
|
||||||
namespace upm {
|
namespace upm {
|
||||||
/**
|
/**
|
||||||
@ -54,7 +55,7 @@ namespace upm {
|
|||||||
* @image html gp2y0a.jpg
|
* @image html gp2y0a.jpg
|
||||||
* @snippet gp2y0a.cxx Interesting
|
* @snippet gp2y0a.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class GP2Y0A {
|
class GP2Y0A : virtual public iProximity {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,11 +79,19 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
float value(float aref, uint8_t samples);
|
float value(float aref, uint8_t samples);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the voltage value from the sensor from a single sample
|
||||||
|
* A refernce voltage of 5.0V is used for the reading.
|
||||||
|
*
|
||||||
|
* @return Voltage reading from a single sample
|
||||||
|
*/
|
||||||
|
virtual float getValue();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mraa_aio_context m_aio;
|
mraa_aio_context m_aio;
|
||||||
// ADC resolution
|
// ADC resolution
|
||||||
int m_aRes;
|
int m_aRes;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,11 @@ MAX44000::getProximity () {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
MAX44000::getValue() {
|
||||||
|
return (float) MAX44000::getProximity();
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t
|
uint16_t
|
||||||
MAX44000::getAmbient () {
|
MAX44000::getAmbient () {
|
||||||
uint16_t data = 0;
|
uint16_t data = 0;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/i2c.hpp>
|
#include <mraa/i2c.hpp>
|
||||||
|
#include <interfaces/iProximity.hpp>
|
||||||
|
|
||||||
#define ADDR 0x4A // device address
|
#define ADDR 0x4A // device address
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ namespace upm {
|
|||||||
*
|
*
|
||||||
* @snippet max44000.cxx Interesting
|
* @snippet max44000.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class MAX44000 {
|
class MAX44000 : virtual public iProximity {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Instantiates an MAX44000 object
|
* Instantiates an MAX44000 object
|
||||||
@ -99,6 +100,12 @@ class MAX44000 {
|
|||||||
* Reads the proximity value from the sensor (based on ambient data).
|
* Reads the proximity value from the sensor (based on ambient data).
|
||||||
*/
|
*/
|
||||||
uint16_t getProximity ();
|
uint16_t getProximity ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the proximity value from the sensor.
|
||||||
|
*/
|
||||||
|
virtual float getValue ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the ambient value from the sensor (based on ambient data).
|
* Reads the ambient value from the sensor (based on ambient data).
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user