]> vault307.fbx.one Git - micorpython_ir.git/blob - ir_rx/samsung.py
Fix issue 14 NEC transmit error on RP2.
[micorpython_ir.git] / ir_rx / samsung.py
1 # samsung.py Decoder for IR remote control using synchronous code
2 # Supports Samsung TV remote protocols.
3
4 # Author: J.E. Tannenbaum
5 # Copyright J.E.Tannenbaum 2021 Released under the MIT license
6
7 from utime import ticks_us, ticks_diff
8 from ir_rx import IR_RX
9
10 class SAMSUNG(IR_RX):
11 def __init__(self, pin, callback, *args):
12 super().__init__(pin, 68, 80, callback, *args)
13
14 def decode(self, _):
15 def near(v, target):
16 return target * 0.8 < v < target * 1.2
17
18 lb = self.edge - 1 # Possible length of burst
19 burst = []
20 for x in range(lb):
21 dt = ticks_diff(self._times[x + 1], self._times[x])
22 if x > 0 and dt > 10000: # Reached gap between repeats
23 break
24 burst.append(dt)
25
26 lb = len(burst) # Actual length
27 cmd = 0
28 if near(burst[0], 4500) and near(burst[1], 4500) and lb == 67:
29 # Skip the starting bits and the checksum at the end of the sequence
30 for x in range(2, lb - 1, 2):
31 cmd *= 2
32 # Test for logical 1 (One byte low, next byte high)
33 if burst[x] < 1000 and burst[x + 1] > 1000:
34 cmd += 1
35
36 # Set up for new data burst and run user callback
37 self.do_callback(cmd, 0, 0)