summaryrefslogtreecommitdiff
path: root/decoders/stepper_motor
diff options
context:
space:
mode:
Diffstat (limited to 'decoders/stepper_motor')
-rw-r--r--decoders/stepper_motor/pd.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/decoders/stepper_motor/pd.py b/decoders/stepper_motor/pd.py
index 9ddc645..0546395 100644
--- a/decoders/stepper_motor/pd.py
+++ b/decoders/stepper_motor/pd.py
@@ -19,9 +19,6 @@
import sigrokdecode as srd
-class SamplerateError(Exception):
- pass
-
class Decoder(srd.Decoder):
api_version = 3
id = 'stepper_motor'
@@ -53,6 +50,7 @@ class Decoder(srd.Decoder):
self.reset()
def reset(self):
+ self.samplerate = None
self.oldstep = None
self.ss_prev_step = None
self.pos = 0
@@ -73,13 +71,14 @@ class Decoder(srd.Decoder):
def step(self, ss, direction):
if self.ss_prev_step is not None:
- delta = ss - self.ss_prev_step
- speed = self.samplerate / delta / self.scale
- speed_txt = self.format % speed
+ if self.samplerate:
+ delta = ss - self.ss_prev_step
+ speed = self.samplerate / delta / self.scale
+ speed_txt = self.format % speed
+ self.put(self.ss_prev_step, ss, self.out_ann,
+ [0, [speed_txt + ' ' + self.unit + '/s', speed_txt]])
pos_txt = self.format % (self.pos / self.scale)
self.put(self.ss_prev_step, ss, self.out_ann,
- [0, [speed_txt + ' ' + self.unit + '/s', speed_txt]])
- self.put(self.ss_prev_step, ss, self.out_ann,
[1, [pos_txt + ' ' + self.unit, pos_txt]])
self.pos += (1 if direction else -1)
@@ -90,8 +89,6 @@ class Decoder(srd.Decoder):
self.samplerate = value
def decode(self):
- if not self.samplerate:
- raise SamplerateError('Cannot decode without samplerate.')
while True:
step, direction = self.wait({0: 'r'})
self.step(self.samplenum, direction)