Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes as necessary for multiple HATs #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions inventorhatmini/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ class InventorHATMini():
def __init__(self, address=IOE_ADDRESS, motor_gear_ratio=50, init_motors=True, init_servos=True, init_leds=True, start_muted=False):
""" Initialise inventor hat mini's hardware functions
"""
self.address = address
self.ioe = None

gpiodevice.friendly_errors = True

# Setup user button
self._pin_user_sw = gpiodevice.get_pin(self.PI_USER_SW_PIN, "IHM-SW", INPD)
self.address = address

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

# Setup amplifier enable. This mutes the audio by default
self._pin_amp_en = gpiodevice.get_pin(self.PI_AMP_EN_PIN, "IHM-AMP-En", OUTL if start_muted else OUTH)
# Setup amplifier enable. This mutes the audio by default
self._pin_amp_en = gpiodevice.get_pin(self.PI_AMP_EN_PIN, "IHM-AMP-En", OUTL if start_muted else OUTH)
Comment on lines +109 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are not assigned for the second IHM, I assume that switch_pressed(), mute_audio(), and unmute_audio() will fail if called? Can you include some handling for this? E.g. set self._pin_user_sw and self._pin_amp_en to None then check for that in all relevant places?


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

def __del__(self):
self.ioe.reset()
if self.ioe:
self.ioe.reset()

def switch_pressed(self):
return self._read_pin(self._pin_user_sw)
Expand Down
Loading