@@ -267,11 +267,9 @@ def __repr__(self):
267
267
268
268
269
269
class Pause :
270
- """Class for adding a pause to the DRV2605 waveform sequence.
271
- Duration is specified in tens of milliseconds, as per page 35
272
- of the datasheet. I.e. Pause time = 10ms * duration
273
- """
270
+ """DRV2605 waveform sequence timed delay."""
274
271
def __init__ (self , duration ):
272
+ # Bit 7 must be set for a slot to be interpreted as a delay
275
273
self ._duration = 0x80
276
274
self .duration = duration
277
275
@@ -282,15 +280,17 @@ def raw_value(self):
282
280
283
281
@property
284
282
def duration (self ):
285
- """Return the pause duration."""
286
- return self ._duration & 0x7f
283
+ """Pause duration in seconds."""
284
+ # Remove wait time flag bit and convert duration to seconds
285
+ return (self ._duration & 0x7f ) / 100.0
287
286
288
287
@duration .setter
289
288
def duration (self , duration ):
290
- """Set the pause duration."""
291
- if not 0 <= duration <= 127 :
292
- raise ValueError ('Pause duration must be a value within 0-127!' )
293
- self ._duration = 0x80 | duration
289
+ """Set the pause duration in seconds."""
290
+ if not 0.0 <= duration <= 1.27 :
291
+ raise ValueError ('Pause duration must be a value within 0.0-1.27!' )
292
+ # Add wait time flag bit and convert duration to centiseconds
293
+ self ._duration = 0x80 | round (duration * 100.0 )
294
294
295
295
def __repr__ (self ):
296
296
return "{}({})" .format (type (self ).__qualname__ , self .duration )
@@ -318,7 +318,7 @@ def __getitem__(self, slot):
318
318
# pylint: disable=protected-access
319
319
slot_contents = self ._drv2605 ._read_u8 (_DRV2605_REG_WAVESEQ1 + slot )
320
320
if slot_contents & 0x80 :
321
- return Pause (slot_contents & 0x7f )
321
+ return Pause (( slot_contents & 0x7f ) / 100.0 )
322
322
return Effect (slot_contents )
323
323
324
324
def __iter__ (self ):
0 commit comments