diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-07-21 21:31:04 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-07-21 21:47:55 +0200 |
commit | 500560a16ed5ea35def72714d1e38a92dd74f5be (patch) | |
tree | be2e6503e5d9ab41257542bef807ad638c215f0e /decoders/maxim_ds28ea00 | |
parent | c07cbb92b129bef7a279169e1d7312811ee5e83f (diff) | |
download | libsigrokdecode-500560a16ed5ea35def72714d1e38a92dd74f5be.tar.gz libsigrokdecode-500560a16ed5ea35def72714d1e38a92dd74f5be.zip |
srd: maxim_ds28ea00: Factor out putx(), small fixes.
Diffstat (limited to 'decoders/maxim_ds28ea00')
-rw-r--r-- | decoders/maxim_ds28ea00/maxim_ds28ea00.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/decoders/maxim_ds28ea00/maxim_ds28ea00.py b/decoders/maxim_ds28ea00/maxim_ds28ea00.py index 6e19115..026457e 100644 --- a/decoders/maxim_ds28ea00/maxim_ds28ea00.py +++ b/decoders/maxim_ds28ea00/maxim_ds28ea00.py @@ -70,42 +70,37 @@ class Decoder(srd.Decoder): def report(self): pass + def putx(self, data): + self.put(self.ss, self.es, self.out_ann, data) + def decode(self, ss, es, data): code, val = data + self.ss, self.es = ss, es + # State machine. if code == 'RESET/PRESENCE': - self.put(ss, es, self.out_ann, - [0, ['Reset/presence: %s' % ('true' if val else 'false')]]) + self.putx([0, ['Reset/presence: %s' + % ('true' if val else 'false')]]) self.state = 'ROM' elif code == 'ROM': self.rom = val - self.put(ss, es, self.out_ann, [0, ['ROM: 0x%016x' % (val)]]) + self.putx([0, ['ROM: 0x%016x' % (val)]]) self.state = 'COMMAND' elif code == 'DATA': if self.state == 'COMMAND': - if val in command: - self.put(ss, es, self.out_ann, - [0, ['Function command: 0x%02x \'%s\'' - % (val, command[val])]]) - self.state = command[val].upper() - else: - self.put(ss, es, self.out_ann, - [0, ['Function command: 0x%02x \'%s\'' - % (val, 'unrecognized')]]) - self.state = 'UNRECOGNIZED' + if val not in command: + self.putx([0, ['Unrecognized command: 0x%02x' % val]]) + return + self.putx([0, ['Function command: 0x%02x \'%s\'' + % (val, command[val])]]) + self.state = command[val].upper() elif self.state == 'READ SCRATCHPAD': - self.put(ss, es, self.out_ann, - [0, ['Scratchpad data: 0x%02x' % val]]) + self.putx([0, ['Scratchpad data: 0x%02x' % val]]) elif self.state == 'CONVERT TEMPERATURE': - self.put(ss, es, self.out_ann, - [0, ['Temperature conversion status: 0x%02x' % val]]) + self.putx([0, ['Temperature conversion status: 0x%02x' % val]]) elif self.state in [s.upper() for s in command.values()]: - self.put(ss, es, self.out_ann, - [0, ['TODO \'%s\': 0x%02x' % (self.state, val)]]) - elif self.state == 'UNRECOGNIZED': - self.put(ss, es, self.out_ann, - [0, ['Unrecognized command: 0x%02x' % val]]) + self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]]) else: raise Exception('Invalid state: %s' % self.state) |