Skip to content

Commit 6fa6715

Browse files
committed
changes as necessary for multiple HATs
1 parent fc4b4bd commit 6fa6715

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

inventorhatmini/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@ class InventorHATMini():
9898
def __init__(self, address=IOE_ADDRESS, motor_gear_ratio=50, init_motors=True, init_servos=True, init_leds=True, start_muted=False):
9999
""" Initialise inventor hat mini's hardware functions
100100
"""
101-
self.address = address
101+
self.ioe = None
102102

103103
gpiodevice.friendly_errors = True
104104

105-
# Setup user button
106-
self._pin_user_sw = gpiodevice.get_pin(self.PI_USER_SW_PIN, "IHM-SW", INPD)
105+
self.address = address
106+
107+
if ( address == self.IOE_ADDRESS ): # only if using default address, for use with multiple HATs
108+
# Setup user button
109+
self._pin_user_sw = gpiodevice.get_pin(self.PI_USER_SW_PIN, "IHM-SW", INPD)
107110

108-
# Setup amplifier enable. This mutes the audio by default
109-
self._pin_amp_en = gpiodevice.get_pin(self.PI_AMP_EN_PIN, "IHM-AMP-En", OUTL if start_muted else OUTH)
111+
# Setup amplifier enable. This mutes the audio by default
112+
self._pin_amp_en = gpiodevice.get_pin(self.PI_AMP_EN_PIN, "IHM-AMP-En", OUTL if start_muted else OUTH)
110113

111114
self.__cpr = MMME_CPR * motor_gear_ratio
112115
self.__init_motors = init_motors
@@ -159,7 +162,8 @@ def reinit(self):
159162
self.ioe.set_mode(self.IOE_CURRENT_SENSES[1], ADC)
160163

161164
def __del__(self):
162-
self.ioe.reset()
165+
if self.ioe:
166+
self.ioe.reset()
163167

164168
def switch_pressed(self):
165169
return self._read_pin(self._pin_user_sw)

0 commit comments

Comments
 (0)