From: Gerhard Sittig Date: Sun, 17 Dec 2017 22:59:16 +0000 (+0100) Subject: stepper_motor: make samplerate meta data optional X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4d5684067445f49490c338838961a3e7fc6f7396;p=libsigrokdecode.git 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. --- 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,12 +71,13 @@ 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]]) @@ -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)