diff options
author | sicarius <devnull@localhost> | 2007-02-22 14:12:03 +0100 |
---|---|---|
committer | sicarius <devnull@localhost> | 2007-02-22 14:12:03 +0100 |
commit | 655dd7522fb60e2ef0e68437337178184109f347 (patch) | |
tree | bebff27847c72ebf4be3d763f1da4f66d704dffa /source/Concept/Framework/modules/input/distance_sensor.c | |
parent | 9525458918383afbf324854fc2130d3740154da3 (diff) | |
download | rc2007-soccer-655dd7522fb60e2ef0e68437337178184109f347.tar rc2007-soccer-655dd7522fb60e2ef0e68437337178184109f347.zip |
Codework
Diffstat (limited to 'source/Concept/Framework/modules/input/distance_sensor.c')
-rwxr-xr-x | source/Concept/Framework/modules/input/distance_sensor.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/source/Concept/Framework/modules/input/distance_sensor.c b/source/Concept/Framework/modules/input/distance_sensor.c index 262d35f..e6fd3f8 100755 --- a/source/Concept/Framework/modules/input/distance_sensor.c +++ b/source/Concept/Framework/modules/input/distance_sensor.c @@ -5,21 +5,36 @@ float Distance_Sensor::GetDistance() {
uint32 result = 0;
+ //(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("Gen Pulse; Pin:",1,4);
+ //(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print((int)(*hardwarePin & pin));
+
+ msleep(500);
+
//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
+ *hardwarePort &= ~pin;//Deactivate port
+ //(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("Wait response; Pin:",1,4);
+ //(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print((int)(*hardwarePin & pin));
+
+ uint16 i;
//Wait for response
- for(uint16 i = 0; (!(*hardwarePin & pin)) && (i < 1000); i++) { asm volatile("nop"); }
+ for(i = 0; (!(*hardwarePin & pin)) && (i < 1000); i++) { asm volatile("nop"); }
//Calculate duration of response
while((*hardwarePin & pin)&&(result < 300000))
{
result++;
asm volatile("nop");
+ asm volatile("nop");
+ asm volatile("nop");
+ asm volatile("nop");
+ asm volatile("nop");
+ asm volatile("nop");
+ asm volatile("nop");
}
return (float(result) * DISTANCE_PER_VALUE);
|