mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-29 14:15:33 +03:00 
			
		
		
		
	Added iProximity interface
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:
		 Stefan Andritoiu
					Stefan Andritoiu
				
			
				
					committed by
					
						 Serban Waltter
						Serban Waltter
					
				
			
			
				
	
			
			
			 Serban Waltter
						Serban Waltter
					
				
			
						parent
						
							55b2787e08
						
					
				
				
					commit
					ab54cb7058
				
			| @@ -67,3 +67,8 @@ float GP2Y0A::value(float aref, uint8_t samples) | ||||
|  | ||||
|   return volts; | ||||
| } | ||||
|  | ||||
| float GP2Y0A::getValue() | ||||
| { | ||||
|     return GP2Y0A::value(5.0, (uint8_t) 1); | ||||
| } | ||||
|   | ||||
| @@ -26,6 +26,7 @@ | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <mraa/aio.h> | ||||
| #include <interfaces/iProximity.hpp> | ||||
|  | ||||
| namespace upm { | ||||
|   /** | ||||
| @@ -46,15 +47,15 @@ namespace upm { | ||||
|    * | ||||
|    * @brief API for the GP2Y0A family of IR Proximity Sensors | ||||
|    * | ||||
|    * Sensors of this family return an analog voltage corresponding to the distance  | ||||
|    * Sensors of this family return an analog voltage corresponding to the distance | ||||
|    * of an object from the sensor. The voltage is lower when objects | ||||
|    * are far away; the voltage increases as objects get closer | ||||
|    * to the sensor.   | ||||
|    * to the sensor. | ||||
|    * | ||||
|    * @image html gp2y0a.jpg | ||||
|    * @snippet gp2y0a.cxx Interesting | ||||
|    */ | ||||
|   class GP2Y0A { | ||||
|   class GP2Y0A : virtual public iProximity { | ||||
|   public: | ||||
|  | ||||
|     /** | ||||
| @@ -78,11 +79,19 @@ namespace upm { | ||||
|      */ | ||||
|     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: | ||||
|     mraa_aio_context m_aio; | ||||
|     // ADC resolution | ||||
|     int m_aRes; | ||||
|   }; | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -58,6 +58,11 @@ MAX44000::getProximity () { | ||||
|     return data; | ||||
| } | ||||
|  | ||||
| float | ||||
| MAX44000::getValue() { | ||||
|     return (float) MAX44000::getProximity(); | ||||
| } | ||||
|  | ||||
| uint16_t | ||||
| MAX44000::getAmbient () { | ||||
|     uint16_t data = 0; | ||||
|   | ||||
| @@ -25,6 +25,7 @@ | ||||
|  | ||||
| #include <string> | ||||
| #include <mraa/i2c.hpp> | ||||
| #include <interfaces/iProximity.hpp> | ||||
|  | ||||
| #define ADDR               0x4A // device address | ||||
|  | ||||
| @@ -71,14 +72,14 @@ namespace upm { | ||||
|  * Maxim Integrated* | ||||
|  * [MAX44000](http://datasheets.maximintegrated.com/en/ds/MAX44000.pdf) | ||||
|  * is an ambient and infrared proximity sensor. This module was tested on the | ||||
|  * Maxim Integrated  | ||||
|  * Maxim Integrated | ||||
|  * [MAX44000PMB1 PMOD module] | ||||
|  * (http://datasheets.maximintegrated.com/en/ds/MAX44000PMB1.pdf) from the | ||||
|  * analog PMOD kit. | ||||
|  * | ||||
|  * @snippet max44000.cxx Interesting | ||||
|  */ | ||||
| class MAX44000 { | ||||
| class MAX44000 : virtual public iProximity { | ||||
|     public: | ||||
|         /** | ||||
|          * Instantiates an MAX44000 object | ||||
| @@ -99,6 +100,12 @@ class MAX44000 { | ||||
|          * Reads the proximity value from the sensor (based on ambient data). | ||||
|          */ | ||||
|         uint16_t getProximity (); | ||||
|  | ||||
|         /** | ||||
|          * Reads the proximity value from the sensor. | ||||
|          */ | ||||
|         virtual float getValue (); | ||||
|  | ||||
|         /** | ||||
|          * Reads the ambient value from the sensor (based on ambient data). | ||||
|          */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user