Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit b2f67b8

Browse files
committed
Force array access to be an integer to fix bug with odd GPIO number access.
1 parent 6c35a53 commit b2f67b8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Adafruit_GPIO/MCP230xx.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def setup(self, pin, value):
5858
self._validate_pin(pin)
5959
# Set bit to 1 for input or 0 for output.
6060
if value == GPIO.IN:
61-
self.iodir[pin/8] |= 1 << (pin%8)
61+
self.iodir[int(pin/8)] |= 1 << (int(pin%8))
6262
elif value == GPIO.OUT:
63-
self.iodir[pin/8] &= ~(1 << (pin%8))
63+
self.iodir[int(pin/8)] &= ~(1 << (int(pin%8)))
6464
else:
6565
raise ValueError('Unexpected value. Must be GPIO.IN or GPIO.OUT.')
6666
self.write_iodir()
@@ -72,9 +72,9 @@ def output(self, pin, value):
7272
self._validate_pin(pin)
7373
# Set bit on or off.
7474
if value:
75-
self.gpio[pin/8] |= 1 << (pin%8)
75+
self.gpio[int(pin/8)] |= 1 << (int(pin%8))
7676
else:
77-
self.gpio[pin/8] &= ~(1 << (pin%8))
77+
self.gpio[int(pin/8)] &= ~(1 << (int(pin%8)))
7878
# Write GPIO state.
7979
self.write_gpio()
8080

@@ -86,9 +86,9 @@ def output_pins(self, pins):
8686
# Set each changed pin's bit.
8787
for pin, value in pins.iteritems():
8888
if value:
89-
self.gpio[pin/8] |= 1 << (pin%8)
89+
self.gpio[int(pin/8)] |= 1 << (int(pin%8))
9090
else:
91-
self.gpio[pin/8] &= ~(1 << (pin%8))
91+
self.gpio[int(pin/8)] &= ~(1 << (int(pin%8)))
9292
# Write GPIO state.
9393
self.write_gpio()
9494

@@ -100,17 +100,17 @@ def input(self, pin):
100100
# Get GPIO state.
101101
gpio = self._i2c.readList(self.GPIO, self.gpio_bytes)
102102
# Return True if pin's bit is set.
103-
return (gpio[pin/8] & 1 << (pin%8)) > 0
103+
return (gpio[int(pin/8)] & 1 << (int(pin%8))) > 0
104104

105105
def pullup(self, pin, enabled):
106106
"""Turn on the pull-up resistor for the specified pin if enabled is True,
107107
otherwise turn off the pull-up resistor.
108108
"""
109109
self._validate_pin(pin)
110110
if enabled:
111-
self.gppu[pin/8] |= 1 << (pin%8)
111+
self.gppu[int(pin/8)] |= 1 << (int(pin%8))
112112
else:
113-
self.gppu[pin/8] &= ~(1 << (pin%8))
113+
self.gppu[int(pin/8)] &= ~(1 << (int(pin%8)))
114114
self.write_gppu()
115115

116116
def write_gpio(self, gpio=None):

0 commit comments

Comments
 (0)