Skip to content

Commit

Permalink
Switch start to play, add LRM and ERM configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdicola committed Dec 27, 2017
1 parent 0f1b0b6 commit 8c0d35e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 14 additions & 6 deletions adafruit_drv2605.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def __init__(self, i2c, address=_DRV2605_ADDR):
self._write_u8(_DRV2605_REG_BREAK, 0)
self._write_u8(_DRV2605_REG_AUDIOMAX, 0x64)
# Set ERM open-loop mode.
# turn off N_ERM_LRA
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
self._write_u8(_DRV2605_REG_FEEDBACK, feedback & 0x7F)
self.use_ERM()
# turn on ERM_OPEN_LOOP
control3 = self._read_u8(_DRV2605_REG_CONTROL3)
self._write_u8(_DRV2605_REG_CONTROL3, control3 | 0x20)
Expand All @@ -140,8 +138,8 @@ def _write_u8(self, address, val):
self._BUFFER[1] = val & 0xFF
i2c.write(self._BUFFER, end=2)

def start(self):
"""Start vibrating the motor."""
def play(self):
"""Play back the select effect(s) on the motor."""
self._write_u8(_DRV2605_REG_GO, 1)

def stop(self):
Expand All @@ -152,7 +150,7 @@ def stop(self):
def mode(self):
"""Get and set the mode of the chip. Should be a value of:
- MODE_INTTRIG: Internal triggering, vibrates as soon as you call
start() and stops after calling stop(). Default mode.
play(). Default mode.
- MODE_EXTTRIGEDGE: External triggering, edge mode.
- MODE_EXTTRIGLVL: External triggering, level mode.
- MODE_PWMANALOG: PWM/analog input mode.
Expand Down Expand Up @@ -199,3 +197,13 @@ def set_waveform(self, effect_id, slot=0):
assert 0 <= effect_id <= 123
assert 0 <= slot <= 6
self._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect_id)

def use_ERM(self):
"""Use an eccentric rotating mass motor (the default)."""
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
self._write_u8(_DRV2605_REG_FEEDBACK, feedback & 0x7F)

def use_LRM(self):
"""Use a linear resonance actuator motor."""
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
self._write_u8(_DRV2605_REG_FEEDBACK, feedback | 0x80)
4 changes: 1 addition & 3 deletions examples/simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
# them in interesting ways. Use the slot keyword and specify a slot 0 to 6
# (0 is the default).
#drv.set_waveform(effect, slot=1)
drv.start() # Start the playback.
drv.play() # Play the effect.
time.sleep(0.5)
# You can stop playback with stop, although not necessary here it looks like:
#drv.stop() # Stop the playback.
# Increment effect ID and wrap back around to 1.
effect += 1
if effect > 117:
Expand Down

0 comments on commit 8c0d35e

Please sign in to comment.