]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx/acquire.py
7b492e015b4c2dca02d584e5ffe11caf48950d4e
1 # acquire.py Acquire a pulse train from an IR remote
2 # Supports NEC protocol.
3 # For a remote using NEC see https://www.adafruit.com/products/389
6 # Copyright Peter Hinch 2020 Released under the MIT license
8 from machine
import Pin
, freq
9 from sys
import platform
11 from utime
import sleep_ms
, ticks_us
, ticks_diff
12 from ir_rx
import IR_RX
16 def __init__(self
, pin
, nedges
=100, twait
=100, display
=True):
17 self
.display
= display
18 super().__init
__(pin
, nedges
, twait
, lambda *_
: None)
23 return target
* 0.8 < v
< target
* 1.2
28 duration
= ticks_diff(self
._times
[0], self
._times
[nedges
]) # 24892 for RC-5 22205 for RC-6
29 for x
in range(nedges
- 1):
30 dt
= ticks_diff(self
._times
[x
+ 1], self
._times
[x
])
31 if x
> 0 and dt
> 10000: # Reached gap between repeats
37 for x
, e
in enumerate(burst
):
38 print('{:03d} {:5d}'.format(x
, e
))
43 elif burst
[0] > 2000: # Sony or Philips RC-6
44 if burst
[1] > 750: # Probably Philips
46 print('Philips RC-6 mode 0')
51 nbits
= {25:12, 31:15, 41:20}
[len(burst
)]
57 print('Sony {}bit'.format(nbits
))
63 print('Unknown protocol')
67 # Set up for new data burst. Run null callback
68 self
.do_callback(0, 0, 0)
71 while self
.data
is None:
77 # Define pin according to platform
78 if platform
== 'pyboard':
79 pin
= Pin('X3', Pin
.IN
)
80 elif platform
== 'esp8266':
83 elif platform
== 'esp32' or platform
== 'esp32_LoBo':
86 print('Waiting for IR data...')
89 # RC Python Calculated
91 # Sony 12: 24 24 26 (2 hdr + 2*(7 data + 5 addr) RC issues another: detect 26ms gap
96 # Pi/Vista MCE RC6 mode 0 Din't receive
97 # Panasonic TV recorder RC6 mode 0 Didn't receive
98 # Virgin RC-5 Receive OK
99 # Samsung TV RC6 mode 0 Didn't receive