diff --git a/RECEIVER.md b/RECEIVER.md index 0ea8a7b..c5fd2ea 100644 --- a/RECEIVER.md +++ b/RECEIVER.md @@ -64,7 +64,9 @@ This script waits for a single burst from the remote and prints the timing of the pulses followed by its best guess at the protocol. It correctly identifies supported protocols, but can wrongly identify unsupported protocols. The report produced by the script exposed to an unknown protocol is unpredictable. -The `test()` function returns a list of the mark and space periods (in μs). +The `test()` function returns a dictionary containing two keys, `raw` and +`protocol`. `raw` is a list of the mark and space periods (in μs). `protocol` +is the protocl as a string # 3. The driver diff --git a/TRANSMITTER.md b/TRANSMITTER.md index 97461d7..12e38bf 100644 --- a/TRANSMITTER.md +++ b/TRANSMITTER.md @@ -341,7 +341,7 @@ import ujson lst = test() # May report unsupported or unknown protocol with open('burst.py', 'w') as f: - ujson.dump(lst, f) + ujson.dump(lst['raw'], f) ``` This replays it: ```python diff --git a/ir_rx/acquire.py b/ir_rx/acquire.py index af3ab38..10f2652 100644 --- a/ir_rx/acquire.py +++ b/ir_rx/acquire.py @@ -17,6 +17,7 @@ def __init__(self, pin, nedges=100, twait=100, display=True): self.display = display super().__init__(pin, nedges, twait, lambda *_ : None) self.data = None + self.protocol = None def decode(self, _): def near(v, target): @@ -33,55 +34,62 @@ def near(v, target): lb = len(burst) # Actual length # Duration of pulse train 24892 for RC-5 22205 for RC-6 duration = ticks_diff(self._times[lb - 1], self._times[0]) - - if self.display: - for x, e in enumerate(burst): - print('{:03d} {:5d}'.format(x, e)) - print() - # Attempt to determine protocol - ok = False # Protocol not yet found - if near(burst[0], 9000) and lb == 67: - print('NEC') + + for x, e in enumerate(burst): + if self.display: print('{:03d} {:5d}'.format(x, e)) + if self.display: print() + # Attempt to determine protocol + ok = False # Protocol not yet found + if near(burst[0], 9000) and lb == 67: + if self.display: print('NEC') + self.protocol = 'NEC' + ok = True + + if not ok and near(burst[0], 2400) and near(burst[1], 600): # Maybe Sony + try: + nbits = {25:12, 31:15, 41:20}[lb] + except KeyError: + pass + else: ok = True + self.protocol = 'Sony' + if self.display: print('Sony {}bit'.format(nbits)) - if not ok and near(burst[0], 2400) and near(burst[1], 600): # Maybe Sony - try: - nbits = {25:12, 31:15, 41:20}[lb] - except KeyError: - pass - else: - ok = True - print('Sony {}bit'.format(nbits)) - - if not ok and near(burst[0], 889): # Maybe RC-5 - if near(duration, 24892) and near(max(burst), 1778): - print('Philps RC-5') - ok = True - - if not ok and near(burst[0], 2666) and near(burst[1], 889): # RC-6? - if near(duration, 22205) and near(burst[1], 889) and near(burst[2], 444): - print('Philips RC-6 mode 0') - ok = True - - if not ok and near(burst[0], 2000) and near(burst[1], 1000): - if near(duration, 19000): - print('Microsoft MCE edition protocol.') - # Constant duration, variable burst length, presumably bi-phase - print('Protocol start {} {} Burst length {} duration {}'.format(burst[0], burst[1], lb, duration)) - ok = True - - if not ok and near(burst[0], 4500) and near(burst[1], 4500) and lb == 67: # Samsung - print('Samsung') + if not ok and near(burst[0], 889): # Maybe RC-5 + if near(duration, 24892) and near(max(burst), 1778): + self.protocol = 'RC-5' + if self.display: print('Philps RC-5') ok = True - if not ok and near(burst[0], 3500) and near(burst[1], 1680): # Panasonic? - print('Unsupported protocol. Panasonic?') + if not ok and near(burst[0], 2666) and near(burst[1], 889): # RC-6? + if near(duration, 22205) and near(burst[1], 889) and near(burst[2], 444): + self.protocol = 'RC-6' + if self.display: print('Philips RC-6 mode 0') ok = True - if not ok: - print('Unknown protocol start {} {} Burst length {} duration {}'.format(burst[0], burst[1], lb, duration)) + if not ok and near(burst[0], 2000) and near(burst[1], 1000): + if near(duration, 19000): + self.protocol = 'MCE' + if self.display: print('Microsoft MCE edition protocol.') + # Constant duration, variable burst length, presumably bi-phase + if self.display: print('Protocol start {} {} Burst length {} duration {}'.format(burst[0], burst[1], lb, duration)) + ok = True - print() + if not ok and near(burst[0], 4500) and near(burst[1], 4500) and lb == 67: # Samsung + self.protocol = 'Samsung' + if self.display: print('Samsung') + ok = True + + if not ok and near(burst[0], 3500) and near(burst[1], 1680): # Panasonic? + self.protocol = 'Panasonic' + if self.display: print('Unsupported protocol. Panasonic?') + ok = True + + if not ok: + self.protocol = 'Unknown' + if self.display: print('Unknown protocol start {} {} Burst length {} duration {}'.format(burst[0], burst[1], lb, duration)) + + if self.display: print() self.data = burst # Set up for new data burst. Run null callback self.do_callback(0, 0, 0) @@ -90,7 +98,7 @@ def acquire(self): while self.data is None: sleep_ms(5) self.close() - return self.data + return {"raw": self.data, "protocol": self.protocol} def test(): # Define pin according to platform