You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module provides functions to receive InfraRed (IR) signals from a IR receiver (e.g. TSOP38238). It can also decode RC-5 encoded signals.
8
+
9
+
## Functions
10
+
11
+
## ir.setup()
12
+
Setup the GPIO pin connected to the IR receiver. The GPIO pin will be configured to general interrupts on level changes. If the IR interface is no longer required then calling with no arguments will remove the interrupt hook.
13
+
14
+
#### Syntax
15
+
`ir.setup([pin])`
16
+
17
+
#### Parameters
18
+
-`pin` Pin connected to the IR receiver. If omitted then the module is unregistered.
19
+
20
+
#### Returns
21
+
None
22
+
23
+
## ir.on()
24
+
Register a callback for when IR data is received. Two callbacks are available `raw` returns a table with the raw IR timing for decoding in Lua. `rc5` provides the decoded RC5 payload. Omitting the callback argument removes the callback.
25
+
26
+
#### Syntax
27
+
`ir.on(event[, callback])`
28
+
29
+
#### Parameters
30
+
- event: Either `raw` or `rc5`
31
+
- callback: Function to call when IR data is received. The callback takes a single argument which is a table.
32
+
33
+
#### Returns
34
+
None
35
+
36
+
#### Example
37
+
```lua
38
+
ir.on("raw", function(t)
39
+
-- Handle raw IR data
40
+
end)
41
+
ir.on("rc5", function(t)
42
+
print(t.code, t.toggle, t.device, t.command)
43
+
end)
44
+
```
45
+
46
+
#### `raw` callback
47
+
The table passed to the `raw` callback is a simple array with the length(s) of the 'on' times and 'off' times. The least significant bit encodes whether the length is for an 'on' or 'off'. Lengths are in microseconds and are 16 bits (so periods longer than 65,535 microseconds are capped).
48
+
49
+
#### `rc5` callback
50
+
The table passed to the `rc5` callback has 4 fields. `code` is the raw code received (without the first start bit), including the toggle bit. `toggle` is a boolean which changes every time a button is pressed on the remote - this allows you to distinguish between key repeat and a button being repeatedly pressed. `device` and `command` are defined by the RC5 spec - in general all buttons on a remote will have the same 'device' but different 'commands'.
0 commit comments