else:
return '%f' % t
+class Pin:
+ (DATA,) = range(1)
+
+class Ann:
+ (TIME, AVG, DELTA,) = range(3)
+
class Decoder(srd.Decoder):
api_version = 3
id = 'timing'
('delta', 'Delta'),
)
annotation_rows = (
- ('times', 'Times', (0,)),
- ('averages', 'Averages', (1,)),
- ('deltas', 'Deltas', (2,)),
+ ('times', 'Times', (Ann.TIME,)),
+ ('averages', 'Averages', (Ann.AVG,)),
+ ('deltas', 'Deltas', (Ann.DELTA,)),
)
options = (
{ 'id': 'avg_period', 'desc': 'Averaging period', 'default': 100 },
self.samplerate = None
self.last_samplenum = None
self.last_n = deque()
- self.chunks = 0
- self.level_changed = False
self.last_t = None
def metadata(self, key, value):
raise SamplerateError('Cannot decode without samplerate.')
while True:
if self.edge == 'rising':
- pin = self.wait({0: 'r'})
+ pin = self.wait({Pin.DATA: 'r'})
elif self.edge == 'falling':
- pin = self.wait({0: 'f'})
+ pin = self.wait({Pin.DATA: 'f'})
else:
- pin = self.wait({0: 'e'})
+ pin = self.wait({Pin.DATA: 'e'})
if not self.last_samplenum:
self.last_samplenum = self.samplenum
self.last_n.popleft()
self.put(self.last_samplenum, self.samplenum, self.out_ann,
- [0, [normalize_time(t)]])
+ [Ann.TIME, [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))]])
+ [Ann.AVG, [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)]])
+ [Ann.DELTA, [normalize_time(t - self.last_t)]])
self.last_t = t
self.last_samplenum = self.samplenum