Skip to content

Raise exceptions instead of using assert checks (fixes #8). #10

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

Merged
merged 1 commit into from
Oct 5, 2018
Merged
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
12 changes: 8 additions & 4 deletions adafruit_drv2605.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def mode(self):

@mode.setter
def mode(self, val):
assert 0 <= val <= 7
if not 0 <= val <= 7:
raise ValueError('Mode must be a value within 0-7!')
self._write_u8(_DRV2605_REG_MODE, val)

@property
Expand All @@ -191,7 +192,8 @@ def library(self):

@library.setter
def library(self, val):
assert 0 <= val <= 6
if not 0 <= val <= 6:
raise ValueError('Library must be a value within 0-6!')
self._write_u8(_DRV2605_REG_LIBRARY, val)

def set_waveform(self, effect_id, slot=0):
Expand All @@ -200,8 +202,10 @@ def set_waveform(self, effect_id, slot=0):
datasheet for a complete table of effect ID values and the associated
waveform / effect.
"""
assert 0 <= effect_id <= 123
assert 0 <= slot <= 6
if not 0 <= effect_id <= 123:
raise ValueError('Effect ID must be a value within 0-123!')
if not 0 <= slot <= 6:
raise ValueError('Slot must be a value within 0-6!')
self._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect_id)

# pylint: disable=invalid-name
Expand Down