Reputation: 4198
I am starting my adventure with IoT and got some blinking led experience behind me. But now I wanted to do some more advanced thing so I figured I try to read infrared signals from remotes. Now everything is based on rPi3.
So what I have is:
let private _onPinValueChanged (gpioController: GpioController) =
new PinChangeEventHandler (
fun _ _ ->
Console.WriteLine DateTime.Now
Console.WriteLine (gpioController.Read GpioIrIn)) //pin number is 18
let StartIrRead (gpioController: GpioController) (cancellationToken: CancellationToken) =
let worker =
async {
Console.WriteLine $"Opening PIN {GpioIrIn}"
gpioController.OpenPin (GpioIrIn, PinMode.Input)
match gpioController.IsPinOpen GpioIrIn with
| true -> gpioController.RegisterCallbackForPinValueChangedEvent (GpioIrIn, PinEventTypes.Rising, _onPinValueChanged gpioController)
| false -> raise (Exception($"Problem with opening PIN {GpioIrIn}"))
}
Async.Start (worker, cancellationToken)
And well it works to some matter. Event is firing up when I point a remote on it and press any button, but what I understand I need pulse or some values, but what I am getting is just PinStatus (eg. High). So how can I register that signal and convert it so I can send it back?
Upvotes: 1
Views: 205
Reputation: 17185
Unfortunately, there's no binding in Iot.Device.Bindings (yet) that directly supports IR sensors.
So your start is good, I think. You are listening to events that are generated from the IR receiver. The IR communication however, is a digital communication where a signal is transmitted with a few bytes of data, similar to a serial communication, meaning you will receive many events when you press a button. For each event, you need to store the new value (high or low) and the timestamp. After collecting a set of events (check with different timeout values), you need to calculate a bit set from these events.
This gets difficult again, because the way remotes encode their bits is not standardized. Here's a sheet describing some common encoding formats. You might be able to find the correct encoding format for your remote already from the data set you get (but remember that your timing measurement will have some error)
If you think you don't get a reasonable data sequence, you might need to use busy-waiting after the first event (and poll for input changes), because there's a limit in how fast events can be triggered.
Upvotes: 1