Skip to content

Commit 8c0d35e

Browse files
committed
Switch start to play, add LRM and ERM configuration.
1 parent 0f1b0b6 commit 8c0d35e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

adafruit_drv2605.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def __init__(self, i2c, address=_DRV2605_ADDR):
115115
self._write_u8(_DRV2605_REG_BREAK, 0)
116116
self._write_u8(_DRV2605_REG_AUDIOMAX, 0x64)
117117
# Set ERM open-loop mode.
118-
# turn off N_ERM_LRA
119-
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
120-
self._write_u8(_DRV2605_REG_FEEDBACK, feedback & 0x7F)
118+
self.use_ERM()
121119
# turn on ERM_OPEN_LOOP
122120
control3 = self._read_u8(_DRV2605_REG_CONTROL3)
123121
self._write_u8(_DRV2605_REG_CONTROL3, control3 | 0x20)
@@ -140,8 +138,8 @@ def _write_u8(self, address, val):
140138
self._BUFFER[1] = val & 0xFF
141139
i2c.write(self._BUFFER, end=2)
142140

143-
def start(self):
144-
"""Start vibrating the motor."""
141+
def play(self):
142+
"""Play back the select effect(s) on the motor."""
145143
self._write_u8(_DRV2605_REG_GO, 1)
146144

147145
def stop(self):
@@ -152,7 +150,7 @@ def stop(self):
152150
def mode(self):
153151
"""Get and set the mode of the chip. Should be a value of:
154152
- MODE_INTTRIG: Internal triggering, vibrates as soon as you call
155-
start() and stops after calling stop(). Default mode.
153+
play(). Default mode.
156154
- MODE_EXTTRIGEDGE: External triggering, edge mode.
157155
- MODE_EXTTRIGLVL: External triggering, level mode.
158156
- MODE_PWMANALOG: PWM/analog input mode.
@@ -199,3 +197,13 @@ def set_waveform(self, effect_id, slot=0):
199197
assert 0 <= effect_id <= 123
200198
assert 0 <= slot <= 6
201199
self._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect_id)
200+
201+
def use_ERM(self):
202+
"""Use an eccentric rotating mass motor (the default)."""
203+
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
204+
self._write_u8(_DRV2605_REG_FEEDBACK, feedback & 0x7F)
205+
206+
def use_LRM(self):
207+
"""Use a linear resonance actuator motor."""
208+
feedback = self._read_u8(_DRV2605_REG_FEEDBACK)
209+
self._write_u8(_DRV2605_REG_FEEDBACK, feedback | 0x80)

examples/simpletest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
# them in interesting ways. Use the slot keyword and specify a slot 0 to 6
2525
# (0 is the default).
2626
#drv.set_waveform(effect, slot=1)
27-
drv.start() # Start the playback.
27+
drv.play() # Play the effect.
2828
time.sleep(0.5)
29-
# You can stop playback with stop, although not necessary here it looks like:
30-
#drv.stop() # Stop the playback.
3129
# Increment effect ID and wrap back around to 1.
3230
effect += 1
3331
if effect > 117:

0 commit comments

Comments
 (0)