-
Notifications
You must be signed in to change notification settings - Fork 33
Implement nonblocking decoder #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c555ad4
Refactor methods into functions that can be shared.
danielballan 10f17e1
Implement NonblockinGenericDecoder and example.
danielballan 0f597ca
Refactor to use namedtuple instead of custom classes.
danielballan 48ca809
Address pylint failures.
danielballan 96403ae
Fix import order.
danielballan e7e66c5
Tweak import order again.
danielballan 701aeb1
Whitespace change to satisfy sphinx.
danielballan 8ab59ce
Use pylint name instead of code for readability.
danielballan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ bundles | |
.eggs | ||
dist | ||
**/*.egg-info | ||
*.swp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
# Circuit Playground Express Demo Code | ||
# Adjust the pulseio 'board.PIN' if using something else | ||
import time | ||
|
||
import board | ||
import pulseio | ||
|
||
import adafruit_irremote | ||
|
||
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) | ||
decoder = adafruit_irremote.NonblockingGenericDecode(pulsein) | ||
|
||
|
||
t0 = next_heartbeat = time.monotonic() | ||
|
||
while True: | ||
for message in decoder.read(): | ||
print(f"t={time.monotonic() - t0:.3} New Message") | ||
print("Heard", len(message.pulses), "Pulses:", message.pulses) | ||
if isinstance(message, adafruit_irremote.IRMessage): | ||
print("Decoded:", message.code) | ||
elif isinstance(message, adafruit_irremote.NECRepeatIRMessage): | ||
print("NEC repeat!") | ||
elif isinstance(message, adafruit_irremote.UnparseableIRMessage): | ||
print("Failed to decode", message.reason) | ||
print("----------------------------") | ||
|
||
# This heartbeat confirms that we are not blocked somewhere above. | ||
t = time.monotonic() | ||
if t > next_heartbeat: | ||
print(f"t={time.monotonic() - t0:.3} Heartbeat") | ||
next_heartbeat = t + 0.1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.