X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fam230x%2Fpd.py;h=3c5003d129693dd0bb3f42dd968532c9cdbb307f;hp=483dc9be9792497b471c11c46cefa5fc21445b0d;hb=97b874bd0b6913ed52df1b8aac5e7491479fac9a;hpb=92b7b49f6964f57a7d6fc4473645c993cfa4ba52 diff --git a/decoders/am230x/pd.py b/decoders/am230x/pd.py index 483dc9b..3c5003d 100644 --- a/decoders/am230x/pd.py +++ b/decoders/am230x/pd.py @@ -14,8 +14,7 @@ ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## import sigrokdecode as srd @@ -35,7 +34,7 @@ class SamplerateError(Exception): pass class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'am230x' name = 'AM230x/DHTxx/RHTxx' longname = 'Aosong AM230x/DHTxx/RHTxx' @@ -77,7 +76,6 @@ class Decoder(srd.Decoder): def reset(self): self.state = 'WAIT FOR START LOW' - self.samplenum = 0 self.fall = 0 self.rise = 0 self.bits = [] @@ -164,27 +162,24 @@ class Decoder(srd.Decoder): self.state = 'WAIT FOR END' self.bytepos.append(self.samplenum) - def decode(self, ss, es, data): + def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') - for (self.samplenum, (sda,)) in data: + while True: # State machine. if self.state == 'WAIT FOR START LOW': - if sda != 0: - continue + self.wait({0: 'f'}) self.fall = self.samplenum self.state = 'WAIT FOR START HIGH' elif self.state == 'WAIT FOR START HIGH': - if sda != 1: - continue + self.wait({0: 'r'}) if self.is_valid('START LOW'): self.rise = self.samplenum self.state = 'WAIT FOR RESPONSE LOW' else: self.reset() elif self.state == 'WAIT FOR RESPONSE LOW': - if sda != 0: - continue + self.wait({0: 'f'}) if self.is_valid('START HIGH'): self.putfs([0, ['Start', 'S']]) self.fall = self.samplenum @@ -192,16 +187,14 @@ class Decoder(srd.Decoder): else: self.reset() elif self.state == 'WAIT FOR RESPONSE HIGH': - if sda != 1: - continue + self.wait({0: 'r'}) if self.is_valid('RESPONSE LOW'): self.rise = self.samplenum self.state = 'WAIT FOR FIRST BIT' else: self.reset() elif self.state == 'WAIT FOR FIRST BIT': - if sda != 0: - continue + self.wait({0: 'f'}) if self.is_valid('RESPONSE HIGH'): self.putfs([1, ['Response', 'R']]) self.fall = self.samplenum @@ -210,16 +203,14 @@ class Decoder(srd.Decoder): else: self.reset() elif self.state == 'WAIT FOR BIT HIGH': - if sda != 1: - continue + self.wait({0: 'r'}) if self.is_valid('BIT LOW'): self.rise = self.samplenum self.state = 'WAIT FOR BIT LOW' else: self.reset() elif self.state == 'WAIT FOR BIT LOW': - if sda != 0: - continue + self.wait({0: 'f'}) if self.is_valid('BIT 0 HIGH'): bit = 0 elif self.is_valid('BIT 1 HIGH'): @@ -229,7 +220,6 @@ class Decoder(srd.Decoder): continue self.handle_byte(bit) elif self.state == 'WAIT FOR END': - if sda != 1: - continue + self.wait({0: 'r'}) self.putfs([3, ['End', 'E']]) self.reset()