diff options
author | sicarius <devnull@localhost> | 2007-02-17 01:35:01 +0100 |
---|---|---|
committer | sicarius <devnull@localhost> | 2007-02-17 01:35:01 +0100 |
commit | 4a2ba4b7105d168932163cbd07a062fdf2ba00e9 (patch) | |
tree | 1891a3eab64be1ae1a31e1b882ad9e6ce356620e /source/Concept/Framework/distance_sensor.cpp | |
parent | 37d4d23f1dca88b6d074fb09739c9ae071551694 (diff) | |
download | rc2007-soccer-4a2ba4b7105d168932163cbd07a062fdf2ba00e9.tar rc2007-soccer-4a2ba4b7105d168932163cbd07a062fdf2ba00e9.zip |
+++ enhanced framework hardware interface
Diffstat (limited to 'source/Concept/Framework/distance_sensor.cpp')
-rw-r--r-- | source/Concept/Framework/distance_sensor.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/source/Concept/Framework/distance_sensor.cpp b/source/Concept/Framework/distance_sensor.cpp index a11460c..c6c0582 100644 --- a/source/Concept/Framework/distance_sensor.cpp +++ b/source/Concept/Framework/distance_sensor.cpp @@ -1 +1,26 @@ -#include "distance_sensor.h"
\ No newline at end of file +#include "distance_sensor.h"
+
+//-----------------------------------------------------------------------------
+float Distance_Sensor::GetDistance()
+{
+ uint32 result = 0;
+
+ //Generate pulse
+ *hardwareDDR |= pin;//Set pin output
+ *hardwarePort |= pin;//Activate port
+ usleep(10);//Wait for 10µs
+ *hardwarePort &= ~pin;//Deactivate port
+ *hardwareDDR &= ~pin;//Set pin input
+
+ //Wait for response
+ while(!(*hardwarePin & pin));
+
+ //Calculate duration of response
+ while(*hardwarePin & pin)
+ {
+ result++;
+ asm volatile("nop");
+ }
+
+ return (float(result) * DISTANCE_PER_VALUE);
+}
|