Skip to content

Commit 131ea88

Browse files
add fixes for old examples to work on MicroPython. Relies on the following commit to Qwiic_I2C_Py: e16d59dc806ff5ccd2a894f049c48d80b1998bf0
1 parent 7536711 commit 131ea88

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

examples/ex1_enable_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
This example enables channels 0 and 4, pauses, and then enables channel 7.
4747
"""
4848

49-
import qwiic
49+
import qwiic_tca9548a
5050
import time
5151

5252
# Initialize Constructor
53-
test = qwiic.QwiicTCA9548A()
53+
test = qwiic_tca9548a.QwiicTCA9548A()
5454

5555
# Test Run
5656
#########################################

examples/ex2_disable_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
This example disables channels 0 and 4.
4747
"""
4848

49-
import qwiic
49+
import qwiic_tca9548a
5050
import time
5151

5252
# Initialize Constructor
53-
test = qwiic.QwiicTCA9548A()
53+
test = qwiic_tca9548a.QwiicTCA9548A()
5454

5555
# Test Run
5656
#########################################

qwiic_tca9548a.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
# Some devices have multiple availabel addresses - this is a list of these addresses (0x70 - 0x77).
6868
# NOTE: The first address in this list is considered the default I2C address for the
6969
# device (0x70).
70-
_AVAILABLE_I2C_ADDRESS = [*range(0x70,0x77 + 1)]
70+
_AVAILABLE_I2C_ADDRESS = range(0x70,0x77 + 1)
7171

7272
class QwiicTCA9548A(object):
7373
"""
@@ -94,7 +94,7 @@ class QwiicTCA9548A(object):
9494

9595
#----------------------------------------------
9696
# Available Channels:
97-
available_channels = [*range(0,7+1)]
97+
available_channels = range(0,7+1)
9898

9999
#----------------------------------------------
100100
# Constructor
@@ -150,6 +150,15 @@ def is_connected(self):
150150

151151
connected = property(is_connected)
152152

153+
def get_enabled_channels(self):
154+
"""
155+
This method returns the enabled channels on the Qwiic Mux.
156+
:return: Enabled channels on the Qwiic Mux
157+
:rtype: Integer
158+
"""
159+
160+
# Return enabled channels
161+
return self._i2c.readByte(self.address, None) # Note, passing "None" will simply read from device rather than targetting a specific register
153162

154163
def enable_channels(self, enable):
155164
"""
@@ -161,8 +170,7 @@ def enable_channels(self, enable):
161170
an individual integer into a list.
162171
Range- 0 to 7
163172
"""
164-
command = self._i2c.readByte(self.address)
165-
173+
command = self.get_enabled_channels()
166174
# If entry is an integer and not a list; turn it into a list of (1)
167175
if type(enable) is not list: enable = [ enable ]
168176

@@ -188,7 +196,7 @@ def disable_channels(self, disable):
188196
convert an individual integer into a list.
189197
Range- 0 to 7
190198
"""
191-
command = self._i2c.readByte(self.address)
199+
command = self.get_enabled_channels()
192200

193201
# If entry is an integer and not a list; turn it into a list of (1)
194202
if type(disable) is not list: disable = [ disable ]
@@ -229,7 +237,7 @@ def list_channels(self):
229237
configuration (enabled or disabled) on the Qwiic Mux.
230238
"""
231239

232-
enabled_channels = self._i2c.readByte(self.address)
240+
enabled_channels = self.get_enabled_channels()
233241

234242
for x in self.available_channels:
235243
if (enabled_channels & (1 << x)) >> x == 0:

0 commit comments

Comments
 (0)