Skip to content

Commit

Permalink
Merge pull request #36 from zostay/cleanup-pin_mode_bulk
Browse files Browse the repository at this point in the history
Eliminate duplicated code in pin_mode_bulk*
  • Loading branch information
makermelissa authored Jul 26, 2019
2 parents 060752f + e0fd3df commit a0fcd3f
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ def moisture_read(self):

return ret

def pin_mode_bulk(self, pins, mode):
cmd = struct.pack(">I", pins)
def _pin_mode_bulk_x(self, capacity, offset, pins, mode):
cmd = bytearray(capacity)
cmd[offset:] = struct.pack(">I", pins)
if mode == self.OUTPUT:
self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd)
elif mode == self.INPUT:
Expand All @@ -273,26 +274,11 @@ def pin_mode_bulk(self, pins, mode):
else:
raise ValueError("Invalid pin mode")

def pin_mode_bulk_b(self, pins, mode):
cmd = bytearray(8)
cmd[4:] = struct.pack(">I", pins)
if mode == self.OUTPUT:
self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd)
elif mode == self.INPUT:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)

elif mode == self.INPUT_PULLUP:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd)

elif mode == self.INPUT_PULLDOWN:
self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd)
self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd)
self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd)
def pin_mode_bulk(self, pins, mode):
self._pin_mode_bulk_x(4, 0, pins, mode)

else:
raise ValueError("Invalid pin mode")
def pin_mode_bulk_b(self, pins, mode):
self._pin_mode_bulk_x(8, 4, pins, mode)

def digital_write_bulk(self, pins, value):
cmd = struct.pack(">I", pins)
Expand Down

0 comments on commit a0fcd3f

Please sign in to comment.