]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx/acquire.py
0f094f9a5244ae10f41a06d874c41fd3473758e7
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
24 lb
= self
.edge
- 1 # Possible length of burst
29 dt
= ticks_diff(self
._times
[x
+ 1], self
._times
[x
])
30 if x
> 0 and dt
> 10000: # Reached gap between repeats
33 lb
= len(burst
) # Actual length
34 # Duration of pulse train 24892 for RC-5 22205 for RC-6
35 duration
= ticks_diff(self
._times
[lb
- 1], self
._times
[0])
38 for x
, e
in enumerate(burst
):
39 print('{:03d} {:5d}'.format(x
, e
))
41 # Attempt to determine protocol
42 ok
= False # Protocol not yet found
43 if near(burst
[0], 9000) and lb
== 67:
47 if not ok
and near(burst
[0], 2400) and near(burst
[1], 600): # Maybe Sony
49 nbits
= {25:12, 31:15, 41:20}
[lb
]
54 print('Sony {}bit'.format(nbits
))
56 if not ok
and near(burst
[0], 889): # Maybe RC-5
57 if near(duration
, 24892) and near(max(burst
), 1778):
61 if not ok
and near(burst
[0], 2666) and near(burst
[1], 889): # RC-6?
62 if near(duration
, 22205) and near(burst
[1], 889) and near(burst
[2], 444):
63 print('Philips RC-6 mode 0')
66 if not ok
and near(burst
[0], 2056) and near(burst
[1], 945):
67 if near(duration
, 19000):
68 print('Microsoft MCE edition protocol. Not yet supported.')
69 # Constant duration, variable burst length, presumably bi-phase
70 print('Protocol start {} {} Burst length {} duration {}'.format(burst
[0], burst
[1], lb
, duration
))
73 if not ok
and near(burst
[0], 4500) and near(burst
[1], 4500): # Samsung?
74 print('Unsupported protocol. Samsung?')
77 if not ok
and near(burst
[0], 3500) and near(burst
[1], 1680): # Panasonic?
78 print('Unsupported protocol. Panasonic?')
82 print('Unknown protocol start {} {} Burst length {} duration {}'.format(burst
[0], burst
[1], lb
, duration
))
86 # Set up for new data burst. Run null callback
87 self
.do_callback(0, 0, 0)
90 while self
.data
is None:
96 # Define pin according to platform
97 if platform
== 'pyboard':
98 pin
= Pin('X3', Pin
.IN
)
99 elif platform
== 'esp8266':
101 pin
= Pin(13, Pin
.IN
)
102 elif platform
== 'esp32' or platform
== 'esp32_LoBo':
103 pin
= Pin(23, Pin
.IN
)
105 print('Waiting for IR data...')
111 # Samsung Unknown protocol 4576 4472 67 60755
112 # Panasonic Unknown protocol 3526 1679 99 54303
113 # Vista MCE edition Unknown protocol 2056 945 25 18935