summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2017-06-15 21:35:25 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2017-06-15 21:35:25 +0200
commit06ca8df7b2994a4dcd480d11b5c30fc8085b0e7d (patch)
treeb02dfaa444eea8fd5675ae6d5c8ac3200b3e9fa1
parent2dda726be82e97887b8c3958d5a54dd9125265ad (diff)
downloadlibsigrokdecode-06ca8df7b2994a4dcd480d11b5c30fc8085b0e7d.tar.gz
libsigrokdecode-06ca8df7b2994a4dcd480d11b5c30fc8085b0e7d.zip
pwm: Reduce indentation level.
-rw-r--r--decoders/pwm/pd.py63
1 files changed, 32 insertions, 31 deletions
diff --git a/decoders/pwm/pd.py b/decoders/pwm/pd.py
index 5822f32..5d0b4a5 100644
--- a/decoders/pwm/pd.py
+++ b/decoders/pwm/pd.py
@@ -102,36 +102,37 @@ class Decoder(srd.Decoder):
while True:
pin, = self.wait({0: 'e'})
- if pin == self.startedge:
- # Active edge
- # We are on a full cycle we can calculate
- # the period, the duty cycle and its ratio.
- period = self.samplenum - self.start_samplenum
- duty = self.end_samplenum - self.start_samplenum
- ratio = float(duty / period)
-
- # This interval starts at this edge.
- self.ss_block = self.start_samplenum
- # Store the new rising edge position and the ending
- # edge interval.
- self.start_samplenum = self.es_block = self.samplenum
-
- # Report the duty cycle in percent.
- percent = float(ratio * 100)
- self.putx([0, ['%f%%' % percent]])
-
- # Report the duty cycle in the binary output.
- self.putb([0, bytes([int(ratio * 256)])])
-
- # Report the period in units of time.
- period_t = float(period / self.samplerate)
- self.putp(period_t)
-
- # Update and report the new duty cycle average.
- self.num_cycles += 1
- self.average += percent
- self.put(self.first_samplenum, self.es_block, self.out_average,
- float(self.average / self.num_cycles))
- else:
+ if pin != self.startedge:
# Non-active edge
self.end_samplenum = self.ss_block = self.samplenum
+ continue
+
+ # Active edge
+ # We are on a full cycle we can calculate
+ # the period, the duty cycle and its ratio.
+ period = self.samplenum - self.start_samplenum
+ duty = self.end_samplenum - self.start_samplenum
+ ratio = float(duty / period)
+
+ # This interval starts at this edge.
+ self.ss_block = self.start_samplenum
+ # Store the new rising edge position and the ending
+ # edge interval.
+ self.start_samplenum = self.es_block = self.samplenum
+
+ # Report the duty cycle in percent.
+ percent = float(ratio * 100)
+ self.putx([0, ['%f%%' % percent]])
+
+ # Report the duty cycle in the binary output.
+ self.putb([0, bytes([int(ratio * 256)])])
+
+ # Report the period in units of time.
+ period_t = float(period / self.samplerate)
+ self.putp(period_t)
+
+ # Update and report the new duty cycle average.
+ self.num_cycles += 1
+ self.average += percent
+ self.put(self.first_samplenum, self.es_block, self.out_average,
+ float(self.average / self.num_cycles))