Skip to content

Encoder: initialize only the given channel #199

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 1 commit into from
Nov 24, 2017
Merged

Encoder: initialize only the given channel #199

merged 1 commit into from
Nov 24, 2017

Conversation

dplanella
Copy link
Contributor

@dplanella dplanella commented Nov 24, 2017

Currently, upon instantiating the RotaryEncoder class, a channel index can be given to initialize and use a particular eQEP channel.

On initializing the class however, all possibe channels are configured as qep, regardless of whether they are available or not. That is, the channel index is ignored and all channels are configured instead of just the given one.

This poses a few issues:

  • All QEP-enabled pins are inadvertently configured as qep, overriding their global setting, or their configuration in other parts of the code
  • Even if a pin is not exposed, the RotaryEncoder class will try to initialize it, resulting in an error
  • If both the eQEP2 and eQEP2b channels are available, they are also both configured in sequence. Given that they are mutually exclusive, if eQEP2 is configured first and eQEP2b is configured afterwards, eQEP2 will be inadvertently disabled.

This change addresses these issues by configuring only the given channel upon initialization of the class. Public module constants have also been added for easy reference to each channel.

A quick example of using the code with the new changes:

import Adafruit_BBIO.Encoder as Encoder

'''
Each channel can be accessed and initialized using its corresponding
channel name constants:

    Encoder.eQEP0
    Encoder.eQEP1
    Encoder.eQEP2
    Encoder.eQEP2b
'''

# Instantiate the class to access channel eQEP2, and only initialize
# that channel
myEncoder = Encoder.RotaryEncoder(Encoder.eQEP2)

@pdp7 pdp7 merged commit 721b063 into adafruit:master Nov 24, 2017
@pdp7
Copy link
Collaborator

pdp7 commented Nov 24, 2017

Thanks @dplanella

pdp7 added a commit that referenced this pull request Dec 1, 2017
Features:
  * Issue #194: Encoder position cannot be set
  * PR #205: Encoder: add support for reading/writing sysfs attributes

Fixes:
  * Issue #198: use https for DEFAULT_URL in distribute_setup.py
  * Issue #197: Fix leak of pwm enable file descriptor
  * Issue #189: Fix seg fault of PWM in Python 3.6
  * Issue #180: Clarify there is no 0 prefix for pin lables
  * PR #201: Encoder: do kernel check, PEP8 cleanup
  * PR #202: Encoder: corrected kernel check logic
  * PR #207: Encoder: improved usage adocumentation
  * PR #210: Encoder: fix sysfs import, make code Python 3 compatible
  * PR #212: Encoder: fix Python 3 compatibility
  * PR #213: Encoder: fix frequency calculation from period

shortlog:

* David Planella (18):
  * Encoder: initialize only the given channel
  * Sync from master
  * Encoder: do kernel check, PEP8 cleanup
  * Encoder: added sysfs module
  * Encoder: use sysfs to write QEP attributes
  * Encoder: corrected kernel check logic
  * Merge pull request #2 from adafruit/master
  * Encoder: convert get/set methods to properties, update apidoc strings
  * Encoder: updated README
  * Encoder: add README apt install clarification
  * Encoder: copyright assignment note, updated comments
  * Encoder: added usage notes
  * Encoder: improved usage documentation
  * Encoder: minor fix to usage example
  * Encoder: added a note about permissions
  * Encoder: switched sysfs to be a relative import compatible with Python 2 and 3
  * Encoder: use items() instead of iteritems() to be Python 3 compatible
  * Encoder: fix frequency getter

* Drew Fustini (18):
  * use https for DEFAULT_URL in distribute_setup.py (#198)
  * fix except syntax for Python 3
  * use dict.items() instead of dict.iteritems() for Python 3
  * fix error in set_brightness()
  * close enable_fd when stopping PWM output (#197)
  * Merge pull request #199 from dplanella/patch-1
  * Fix leak of pwm enable file descriptor (#197)
  * Merge pull request #201 from dplanella/encoder-cleanup
  * remove test_rotary.py as not valid for pytest
  * Fix seg fault of PWM in Python 3.6 (#189)
  * Merge pull request #202 from dplanella/patch-2
  * Clarify there is no 0 prefix for pin lables (#180)
  * Merge pull request #205 from dplanella/encoder-sysfs
  * assign copyright for new file to Adafruit Industries
  * Add bash scripts to help install and test
  * Merge pull request #212 from dplanella/patch-4
  * Merge pull request #207 from dplanella/patch-3
  * Merge pull request #213 from dplanella/fix-encoder-frequency

Signed-off-by: Drew Fustini <[email protected]>
@dplanella dplanella deleted the patch-1 branch December 1, 2017 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants