Timeout support for wait_for_edge

This change makes it able to wait for an edge change but bail out if no change is detected after a timeout. 
The code should be mostly backward compatible but enables programs to recover when the hardware goes weird.

The function wait_for_edge will now admit a timeout value and will return 0 or -1 . If the return is 0, an edge change is detected. If the return is -1 a timeout occurred.