File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,35 @@ def input(self, pin):
126126 value |= temp
127127 return value & (1 << pin )
128128
129-
129+ def readU8 (self ):
130+ result = self .i2c .readU8 (MCP23017_OLATA )
131+ return (result )
132+
133+ def readS8 (self ):
134+ result = self .i2c .readU8 (MCP23017_OLATA )
135+ if (result > 127 ): result -= 256
136+ return result
137+
138+ def readU16 (self ):
139+ assert self .num_gpios >= 16 , "16bits required"
140+ lo = self .i2c .readU8 (MCP23017_OLATA )
141+ hi = self .i2c .readU8 (MCP23017_OLATB )
142+ return ((hi << 8 ) | lo )
143+
144+ def readS16 (self ):
145+ assert self .num_gpios >= 16 , "16bits required"
146+ lo = self .i2c .readU8 (MCP23017_OLATA )
147+ hi = self .i2c .readU8 (MCP23017_OLATB )
148+ if (hi > 127 ): hi -= 256
149+ return ((hi << 8 ) | lo )
150+
151+ def write8 (self , value ):
152+ self .i2c .write8 (MCP23017_OLATA , value )
153+
154+ def write16 (self , value ):
155+ assert self .num_gpios >= 16 , "16bits required"
156+ self .i2c .write8 (MCP23017_OLATA , value & 0xFF )
157+ self .i2c .write8 (MCP23017_OLATB , (value >> 8 ) & 0xFF )
130158
131159# RPi.GPIO compatible interface for MCP23017 and MCP23008
132160
You can’t perform that action at this time.
0 commit comments