Swapping digital input/output

I have a sensor which I would like to use which requires swapping a pin between input and output. Basically you set the pin to output/high, charge a capacitor, then set it to an input and time how long until the input reads low. Is there an easy way to do this with WPILib?

Based on my reading of the code, the current objects do not allow swapping the direction of a DIO pin. To change this would require modifying the DigitalModule class, probably cloning the AllocateDIO method to make a SetDIO method which would call m_fpgaDIO->writeOutputEnable to change the direction. Next I’d probably want a wrapper class which combines the DigitalInput and DigitalOutput classes. Finally I’d want a class similar to (or perhaps actually using) the Counter class which would have an interrupt on the falling edge to stop a timer which gets started on direction change.

Does this sound like the right track? Am I missing anything? Is there an easier way to do this? Has anyone else done this already?

Thanks.

I just thought of this:

Maybe the Ultrasonic class, two I/O pins and a diode would solve the problem: Charge the cap through a diode from an output pin. This corresponds to the “ping” in the Ultrasonic class. When the output pin goes low, the diode prevents the cap from being discharged by the output pin, and the input pin can be used to measure the discharge rate.

Thoughts?

Last year, switching I/O directions caused a delay in all DIO. See http://forums.usfirst.org/showthread.php?t=10460

Not sure if anything changed for this year.

Sounds like you are on the right track to me. Personally, I’d use a FET instead of a diode to eliminate the .6V, but it likely doesn’t matter.

Out of curiosity, what sensor are you using? Datasheet link please!