summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/modules/input/distance_sensor.h
blob: 0bb2baf2b877f4e1793240926891f114d99c3e20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef _DISTANCE_SENSOR_H
#define _DISTANCE_SENSOR_H

#include "../../stdafx.h"
#include "sensor.h"

#define SRF10_MIN_GAIN        0      /*!< setze Verstaerung auf 40 */
#define SRF10_MAX_GAIN        16     /*!< setze Verstaerung auf 700 */
#define SRF10_MIN_RANGE       0      /*!< Minimale Reichweite 43mm */
#define SRF10_MAX_RANGE       5977   /*!< Maximale Reichweite 5977mm */

#define SRF10_INCHES          0x50	 /*!< Messung in INCHES */
#define SRF10_CENTIMETERS     0x51	 /*!< Messung in CM */
#define SRF10_MICROSECONDS    0x52	 /*!< Messung in Millisekunden */

#define SRF10_COMMAND         0		 /*!< W=Befehls-Register R=Firmware*/
#define SRF10_LIGHT           1		 /*!< W=Verstaerkungsfaktor R=Nicht benutzt */
#define SRF10_HIB             2		 /*!< W=Reichweite R=Messung High-Byte */
#define SRF10_LOB             3		 /*!< W=Nicht benutzt R=Messung Low-Byte */

class Distance_Sensor : public Sensor
{
public:
	Distance_Sensor()
	{
		this->parent = NULL;
		this->moduleId = 0;
		this->slaveAddr = 0; // Set the I2C Slave-Adress
	}

	Distance_Sensor(uint32 sensorId)
	{
		this->parent = NULL;
		this->moduleId = sensorId;

		switch(sensorId)
		{
			case IO_SENSOR_DISTANCE_0_DEG:
				this->slaveAddr = 0xE0; // Set the I2C Slave-Adress
				break;
			case IO_SENSOR_DISTANCE_90_DEG:
				this->slaveAddr = 0xE2;
				break;
			case IO_SENSOR_DISTANCE_180_DEG:
				this->slaveAddr = 0xE4;
				break;
			case IO_SENSOR_DISTANCE_270_DEG:
				this->slaveAddr = 0xE6;
				break;
			default:
				this->slaveAddr = 0;
				break;
		}

		//SetRange(100);
		SetRange(2000);
		SetSignalFactor(0x06);
	}

protected:
	//Hardware
	uint8 slaveAddr;

	void SetSignalFactor(uint8 factor);

	void SetRange(uint16 millimeters);

/*!
 * Messung ausloesen
 * @param metric_unit 0x50 in Zoll, 0x51 in cm, 0x52 ms
 * @return Resultat der Aktion
 */
 uint8	srf10_ping(uint8 metric_unit);

/*!
 * Register auslesen
 * @param srf10_register welches Register soll ausgelsen werden
 * @return Inhalt des Registers
 */
 uint8	ReadRegister(uint8 registerToRead);

/*!
 * Messung starten Ergebniss aufbereiten und zurueckgeben
 * @return Messergebniss
 */
 uint16	srf10_get_measure(void);

public:
	uint16 GetDistance();
	void SetSlaveAddress(uint8 newSlaveAddress);
};

#endif