summaryrefslogtreecommitdiff
path: root/decoders/stepper_motor/pd.py
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2017-12-17 23:59:16 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2018-02-13 18:50:54 +0100
commit4d5684067445f49490c338838961a3e7fc6f7396 (patch)
tree53db9773ba43986406367b83eade9572bae17529 /decoders/stepper_motor/pd.py
parent72cced49a72d334640af832344ea917da46b8548 (diff)
downloadlibsigrokdecode-4d5684067445f49490c338838961a3e7fc6f7396.tar.gz
libsigrokdecode-4d5684067445f49490c338838961a3e7fc6f7396.zip
stepper_motor: make samplerate meta data optional
Only emit the speed annotations when a sample rate was specified. Cope with the absence of a sample rate for the input stream. Decoding is still possible, it's just that no timing information is available.
Diffstat (limited to 'decoders/stepper_motor/pd.py')
-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)