From d7ac8f546afb75bd2d626b5cc639939337560cf6 Mon Sep 17 00:00:00 2001 From: meyma Date: Thu, 22 Feb 2007 14:08:01 +0000 Subject: We have a SRF10, not SRF05 --- .../Framework/modules/input/distance_sensor.h | 102 +++++++++++++-------- 1 file changed, 66 insertions(+), 36 deletions(-) (limited to 'source/Concept/Framework/modules/input/distance_sensor.h') diff --git a/source/Concept/Framework/modules/input/distance_sensor.h b/source/Concept/Framework/modules/input/distance_sensor.h index 8e6aa21..9efa021 100755 --- a/source/Concept/Framework/modules/input/distance_sensor.h +++ b/source/Concept/Framework/modules/input/distance_sensor.h @@ -2,7 +2,21 @@ #define _DISTANCE_SENSOR_H #include "../../stdafx.h" -#include "sensor.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 { @@ -10,11 +24,8 @@ public: Distance_Sensor() { this->parent = NULL; - this->moduleId = 0; - this->hardwarePort = NULL; - this->hardwareDDR = NULL; - this->hardwarePin = NULL; - this->pin = 0; + this->moduleId = 0; + this->slaveAddr = 0; // Set the I2C Slave-Adress } Distance_Sensor(uint32 sensorId) @@ -24,45 +35,64 @@ public: switch(sensorId) { - case IO_SENSOR_DISTANCE_0_DEG: - this->hardwarePort = &PORTC; - this->hardwareDDR = &DDRC; - this->hardwarePin = &PINC; - this->pin = (1 << 0); + case IO_SENSOR_DISTANCE_0_DEG: + this->slaveAddr = 0xE0; // Set the I2C Slave-Adress break; - case IO_SENSOR_DISTANCE_90_DEG: - this->hardwarePort = &PORTC; - this->hardwareDDR = &DDRC; - this->hardwarePin = &PINC; - this->pin = (1 << 1); + case IO_SENSOR_DISTANCE_90_DEG: + this->slaveAddr = 0xE2; break; - case IO_SENSOR_DISTANCE_180_DEG: - this->hardwarePort = &PORTC; - this->hardwareDDR = &DDRC; - this->hardwarePin = &PINC; - this->pin = (1 << 2); + case IO_SENSOR_DISTANCE_180_DEG: + this->slaveAddr = 0xE4; break; - case IO_SENSOR_DISTANCE_270_DEG: - this->hardwarePort = &PORTC; - this->hardwareDDR = &DDRC; - this->hardwarePin = &PINC; - this->pin = (1 << 3); + case IO_SENSOR_DISTANCE_270_DEG: + this->slaveAddr = 0xE6; break; - default: - this->hardwarePort = NULL; - this->hardwareDDR = NULL; - this->hardwarePin = NULL; - this->pin = 0; + default: + this->slaveAddr = 0; break; } } protected: - //Hardware - volatile uint8* hardwarePort; - volatile uint8* hardwareDDR; - volatile uint8* hardwarePin; - uint8 pin; + //Hardware + slaveAddr; + + /*! + * SRF10 initialsieren + */ +extern void srf10_init(void); + +/*! + * Verstaerkungsfaktor setzen + * @param gain Verstaerkungsfaktor + */ +extern void srf10_set_gain(uint8 gain); + +/*! + * Reichweite setzen, hat auch Einfluss auf die Messdauer + * @param millimeters Reichweite in mm + */ +extern void srf10_set_range(uint16 millimeters); + +/*! + * Messung ausloesen + * @param metric_unit 0x50 in Zoll, 0x51 in cm, 0x52 ms + * @return Resultat der Aktion + */ +extern uint8 srf10_ping(uint8 metric_unit); + +/*! + * Register auslesen + * @param srf10_register welches Register soll ausgelsen werden + * @return Inhalt des Registers + */ +extern uint8 srf10_read_register(uint8 SRF10_register); + +/*! + * Messung starten Ergebniss aufbereiten und zurueckgeben + * @return Messergebniss + */ +extern uint16 srf10_get_measure(void); public: float GetDistance(); -- cgit v1.2.3