summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2017-06-18 13:50:48 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2017-06-20 23:10:09 +0200
commit73dc48310c47f4e3ebb6ee6de67983603ddd3ea3 (patch)
tree7e2c54c5fdfa7a0eed98793051bdbdfa8dc39178
parenteff37627aa217defa784337c4f4aa309477311fc (diff)
downloadlibsigrokdecode-73dc48310c47f4e3ebb6ee6de67983603ddd3ea3.tar.gz
libsigrokdecode-73dc48310c47f4e3ebb6ee6de67983603ddd3ea3.zip
pwm: Fixup sample numbers for binary output
Do reference the period's start and end sample numbers when the duty cycle is written to the binary output stream. The previous implementation inappropriately used the period counter instead.
-rw-r--r--decoders/pwm/pd.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/decoders/pwm/pd.py b/decoders/pwm/pd.py
index d6411ae..0cd0a54 100644
--- a/decoders/pwm/pd.py
+++ b/decoders/pwm/pd.py
@@ -50,7 +50,6 @@ class Decoder(srd.Decoder):
def __init__(self):
self.ss_block = self.es_block = None
- self.num_cycles = 0
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
@@ -84,13 +83,10 @@ class Decoder(srd.Decoder):
self.put(self.ss_block, self.es_block, self.out_ann, [1, [period_s]])
def putb(self, data):
- # TODO Are these ss/es specs appropriate? It's the same value,
- # which represents a mere period counter, not sample numbers.
- # Probably should be:
- # self.put(self.ss_block, self.es_block, self.out_binary, data)
- self.put(self.num_cycles, self.num_cycles, self.out_binary, data)
+ self.put(self.ss_block, self.es_block, self.out_binary, data)
def decode(self):
+ num_cycles = 0
average = 0
# Wait for an "active" edge (depends on config). This starts
@@ -128,7 +124,7 @@ class Decoder(srd.Decoder):
self.putp(period_t)
# Update and report the new duty cycle average.
- self.num_cycles += 1
+ num_cycles += 1
average += percent
self.put(self.first_samplenum, self.es_block, self.out_average,
- float(average / self.num_cycles))
+ float(average / num_cycles))