Skip to content

Commit fc574eb

Browse files
committed
Add documentation for IR module
1 parent b2175a2 commit fc574eb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/modules/ir.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# IR Module
2+
| Since | Origin / Contributor | Maintainer | Source |
3+
| :----- | :-------------------- | :---------- | :------ |
4+
| 2020-05-01 | [Steven Price](https://github.com/ecrips) | [Steven Price](https://github.com/ecrips) | [ir.c](../../app/modules/ir.c)|
5+
6+
7+
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'.

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pages:
8787
- 'http': 'modules/http.md'
8888
- 'hx711' : 'modules/hx711.md'
8989
- 'i2c' : 'modules/i2c.md'
90+
- 'ir' : 'modules/ir.md'
9091
- 'l3g4200d' : 'modules/l3g4200d.md'
9192
- 'mcp4725': 'modules/mcp4725.md'
9293
- 'mdns': 'modules/mdns.md'

0 commit comments

Comments
 (0)