Skip to content

Return protocol detected with ir_rx/acquire.py acquire function #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RECEIVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion TRANSMITTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 51 additions & 43 deletions ir_rx/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
Expand Down