Skip to content
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

Encoder: fix frequency calculation from period #213

Merged
merged 3 commits into from
Dec 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions Adafruit_BBIO/Encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import logging
import itertools
import sysfs
from .sysfs import Node
import platform

(major, minor, patch) = platform.release().split("-")[0].split(".")
Expand Down Expand Up @@ -47,7 +47,7 @@ def fromdict(cls, d):
'''Creates a class instance from a dictionary'''

allowed = ('channel', 'pin_A', 'pin_B', 'sys_path')
df = {k: v for k, v in d.iteritems() if k in allowed}
df = {k: v for k, v in d.items() if k in allowed}
return cls(**df)

def __init__(self, channel, pin_A, pin_B, sys_path):
Expand All @@ -72,7 +72,7 @@ def __init__(self, channel, pin_A, pin_B, sys_path):
self.pin_A = pin_A
self.pin_B = pin_B
self.sys_path = sys_path
self.node = sysfs.Node(sys_path)
self.node = Node(sys_path)


class RotaryEncoder(object):
Expand Down Expand Up @@ -271,12 +271,13 @@ def frequency(self):
new positions.

'''
frequency = self._eqep.node.period / self._NS_FACTOR
frequency = self._NS_FACTOR / int(self._eqep.node.period)

self._logger.debug(
"Set frequency(): Channel {}, frequency: {} Hz, "
"period: {} ns".format(
self._eqep.channel, frequency, period))
self._eqep.channel, frequency,
self._eqep.node.period))

return frequency

Expand Down