Unfortunately, I did not work with this unit, but I know that you have to look for hardware interrupts and their handling. Here is what I found so far:
https://projects.drogon.net/raspberry-pi/wiringpi/functions[
^] (see
waitForInterrupt
,
wiringPiISR
).
See also threading API.
Note: "The GPIO can be set to interrupt on a rising, falling or both edges of the incoming signal". Basically, you need to setup/enable interrupts on some external events on incoming signal. Then you should call
waitForInterrupt
in some thread which you can allow to block. This will be a blocking call which should put the thread in the wait state, which spends zero CPU time: switched out and not scheduled to execution until it is waken up by some event; one of such events is the interrupt you are waiting for. This way, you will avoid any polling and wast of any processor time.
You should also learn how to terminate the thread in this system even if no hardware events are invoked. But if you supply the external event, the thread will always pass the wait. Then you can cycle it and exit the thread execution simply by checking some "exit" flag you could set by your main (or other) thread.
Alternatively, you can supply a handler in the last parameter of
wiringPiISR
. This way, you can handle multiple pins calling this function several time, per each pin you need to handle. As the function passed accepts no parameters, you can have separate handler for each of the pins.
I know nothing about the CLR of Raspberry PI, but I hope you can use it and use available managed analogs of the functions I mentioned or can make them using P/Invoke.
—SA