From a86d8dd59bd698df72a53730f3ac2ef3868b0acc Mon Sep 17 00:00:00 2001 From: cymplecy Date: Sun, 25 Jan 2015 22:35:36 +0000 Subject: [PATCH] Fix bug in config with pin values < 8 I think original code used to truncate the self.direction variable down to 8bits when a pin < 8 mode was changed. The change keeps the upper 8 bits unchanged when pin < 8 and lower bits unchanged when pin >=8 My change is very explicit and could be made more pythonic :) --- Adafruit_MCP230xx/Adafruit_MCP230xx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_MCP230xx/Adafruit_MCP230xx.py b/Adafruit_MCP230xx/Adafruit_MCP230xx.py index dc1b9c27..2f915ac0 100755 --- a/Adafruit_MCP230xx/Adafruit_MCP230xx.py +++ b/Adafruit_MCP230xx/Adafruit_MCP230xx.py @@ -92,9 +92,9 @@ def config(self, pin, mode): self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode) if self.num_gpios <= 16: if (pin < 8): - self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode) + self.direction = (self.direction & 0b1111111100000000) + self._readandchangepin(MCP23017_IODIRA, pin, mode) else: - self.direction |= self._readandchangepin(MCP23017_IODIRB, pin-8, mode) << 8 + self.direction = (self.direction & 0b0000000011111111) + (self._readandchangepin(MCP23017_IODIRB, pin-8, mode) << 8) return self.direction