diff options
Diffstat (limited to 'decoders/timing')
-rw-r--r-- | decoders/timing/pd.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/decoders/timing/pd.py b/decoders/timing/pd.py index 01e3b01..b694c1d 100644 --- a/decoders/timing/pd.py +++ b/decoders/timing/pd.py @@ -60,13 +60,17 @@ class Decoder(srd.Decoder): annotations = ( ('time', 'Time'), ('average', 'Average'), + ('delta', 'Delta'), ) annotation_rows = ( ('time', 'Time', (0,)), ('average', 'Average', (1,)), + ('delta', 'Delta', (2,)), ) options = ( { 'id': 'avg_period', 'desc': 'Averaging period', 'default': 100 }, + { 'id': 'edge', 'desc': 'Edges to check', 'default': 'any', 'values': ('any', 'rising', 'falling') }, + { 'id': 'delta', 'desc': 'Show delta from last', 'default': 'no', 'values': ('yes', 'no') }, ) def __init__(self): @@ -75,6 +79,8 @@ class Decoder(srd.Decoder): self.last_samplenum = None self.last_n = deque() self.chunks = 0 + self.level_changed = False + self.last_t = None def metadata(self, key, value): if key == srd.SRD_CONF_SAMPLERATE: @@ -82,44 +88,39 @@ class Decoder(srd.Decoder): def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + self.edge = self.options['edge'] self.initial_pins = [0] def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') while True: - pin = self.wait({0: 'e'}) + if self.edge == 'rising': + pin = self.wait({0: 'r'}) + elif self.edge == 'falling': + pin = self.wait({0: 'f'}) + else: + pin = self.wait({0: 'e'}) - if self.oldpin is None: - self.oldpin = pin + if not self.last_samplenum: self.last_samplenum = self.samplenum continue + samples = self.samplenum - self.last_samplenum + t = samples / self.samplerate - if self.oldpin != pin: - samples = self.samplenum - self.last_samplenum - t = samples / self.samplerate - self.chunks += 1 + if t > 0: + self.last_n.append(t) + if len(self.last_n) > self.options['avg_period']: + self.last_n.popleft() - # Don't insert the first chunk into the averaging as it is - # not complete probably. - if self.last_samplenum is None or self.chunks < 2: - # Report the timing normalized. - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [0, [normalize_time(t)]]) - else: - if t > 0: - self.last_n.append(t) + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [0, [normalize_time(t)]]) + if self.options['avg_period'] > 0: + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [1, [normalize_time(sum(self.last_n) / len(self.last_n))]]) + if self.last_t and self.options['delta'] == 'yes': + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [2, [normalize_time(t - self.last_t)]]) - if len(self.last_n) > self.options['avg_period']: - self.last_n.popleft() - - # Report the timing normalized. - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [0, [normalize_time(t)]]) - if self.options['avg_period'] > 0: - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [1, [normalize_time(sum(self.last_n) / len(self.last_n))]]) - - # Store data for next round. - self.last_samplenum = self.samplenum - self.oldpin = pin + self.last_t = t + self.last_samplenum = self.samplenum |