Skip to content

Commit 341ceb7

Browse files
committed
Add skeleton for Encoder module to read eQEP
related to feature request in issue #122
1 parent a5a6a4e commit 341ceb7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Adafruit_BBIO/Encoder.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python
2+
3+
# ===========================================================================
4+
# Adafruit_BBIO.Encoder.QEP Class
5+
# ===========================================================================
6+
7+
class QEP :
8+
9+
def __init__(self, channel=1, debug=False):
10+
self.channel = channel
11+
self.debug = debug
12+
13+
def errMsg(self):
14+
print("Error accessing 0x%02X: Check your QEP channel" % self.address)
15+
return -1
16+
17+
# example method from Adafruit_I2C
18+
# TODO: delete this
19+
def write8(self, reg, value):
20+
"Writes an 8-bit value to the specified register/address"
21+
try:
22+
self.bus.write_byte_data(self.address, reg, value)
23+
if self.debug:
24+
print("Rotary: Wrote 0x%02X to register 0x%02X" % (value, reg))
25+
except IOError as err:
26+
return self.errMsg()
27+
28+
29+
if __name__ == '__main__':
30+
try:
31+
qep = Adafruit_BBIO.Encoder.QEP()
32+
print("Default QEP channel is accessible")
33+
except:
34+
print("Error accessing default Rotary bus")

0 commit comments

Comments
 (0)