Skip to content

Commit 20b193e

Browse files
committed
Allow input to read cached data without forcing a GPIO read.
1 parent 3d7e2a6 commit 20b193e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mcp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,20 @@ def output_pins(self, pins):
107107
self.write_gpio()
108108

109109

110-
def input(self, pin):
110+
def input(self, pin, read=True):
111111
"""Read the specified pin and return HIGH/True if the pin is pulled
112112
high, or LOW/False if pulled low.
113113
"""
114-
return self.input_pins([pin])[0]
114+
return self.input_pins([pin], read)[0]
115115

116-
def input_pins(self, pins):
116+
def input_pins(self, pins, read=True):
117117
"""Read multiple pins specified in the given list and return list of pin values
118118
HIGH/True if the pin is pulled high, or LOW/False if pulled low.
119119
"""
120120
[self._validate_pin(pin) for pin in pins]
121-
# Get GPIO state.
122-
self.read_gpio()
121+
if read:
122+
# Get GPIO state.
123+
self.read_gpio()
123124
# Return True if pin's bit is set.
124125
return [(self.gpio[int(pin/8)] & 1 << (int(pin%8))) > 0 for pin in pins]
125126

0 commit comments

Comments
 (0)