]>
vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx/mce.py
218c85918f1c14ec990a15e497032e35f597b3b2
1 # mce.py Decoder for IR remote control using synchronous code
2 # Supports Microsoft MCE edition remote protocol.
5 # Copyright Peter Hinch 2020 Released under the MIT license
7 # WARNING: This is experimental and subject to change.
9 from utime
import ticks_us
, ticks_diff
10 from ir_rx
import IR_RX
13 init_cs
= 4 # http://www.hifi-remote.com/johnsfine/DecodeIR.html#OrtekMCE says 3
14 def __init__(self
, pin
, callback
, *args
):
15 # Block lasts ~19ms and has <= 34 edges
16 super().__init
__(pin
, 34, 25, callback
, *args
)
20 if self
.init_cs
== -1:
31 t0
= ticks_diff(self
._times
[1], self
._times
[0]) # 2000μs mark
32 t1
= ticks_diff(self
._times
[2], self
._times
[1]) # 1000μs space
33 if not ((1800 < t0
< 2200) and (800 < t1
< 1200)):
34 raise RuntimeError(self
.BADSTART
)
35 nedges
= self
.edge
# No. of edges detected
36 if not 14 <= nedges
<= 34:
37 raise RuntimeError(self
.OVERRUN
if nedges
> 28 else self
.BADSTART
)
44 # -1 convert count to index, -1 because we look ahead
46 raise RuntimeError(self
.BADBLOCK
)
47 # width is 500/1000 nominal
48 width
= ticks_diff(self
._times
[x
+ 1], self
._times
[x
])
49 if not 250 < width
< 1350:
50 self
.verbose
and print('Bad block 3 Width', width
, 'x', x
)
51 raise RuntimeError(self
.BADBLOCK
)
52 short
= int(width
< 750)
54 v |
= mask
if bit
else 0
58 self
.verbose
and print(bin(v
))
61 #raise RuntimeError(self.BADDATA)
63 addr
= v
& 0xf # Constant for all buttons on my remote
66 except RuntimeError as e
:
67 val
, addr
, ctrl
= e
.args
[0], 0, 0
68 # Set up for new data burst and run user callback/error function
69 self
.do_callback(val
, addr
, ctrl
)