]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/onewire_link/pd.py
onewire_link: Provide short/long annotations.
[libsigrokdecode.git] / decoders / onewire_link / pd.py
index e7bf8b3b034e128e7588d16143b9d861d06a0f15..a309cc3229f157bb64f8f2fb5a862908559790bf 100644 (file)
@@ -38,7 +38,7 @@ class Decoder(srd.Decoder):
         {'id': 'pwr', 'name': 'PWR', 'desc': '1-Wire power supply pin'},
     ]
     options = {
-        'overdrive': ['Overdrive', 1],
+        'overdrive': ['Overdrive mode', 'no'],
         # Time options (specified in microseconds):
         'cnt_normal_bit': ['Normal mode sample bit time (us)', 15],
         'cnt_normal_slot': ['Normal mode data slot time (us)', 60],
@@ -53,7 +53,8 @@ class Decoder(srd.Decoder):
     annotations = [
         ['bit', 'Bit'],
         ['warnings', 'Warnings'],
-        ['reset', 'Reset/presence'],
+        ['reset', 'Reset'],
+        ['presence', 'Presence'],
         ['overdrive', 'Overdrive mode notifications'],
     ]
 
@@ -69,6 +70,15 @@ class Decoder(srd.Decoder):
     def putx(self, data):
         self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, data)
 
+    def putfr(self, data):
+        self.put(self.fall, self.rise, self.out_ann, data)
+
+    def putprs(self, data):
+        self.put(self.rise, self.samplenum, self.out_proto, data)
+
+    def putrs(self, data):
+        self.put(self.rise, self.samplenum, self.out_ann, data)
+
     def __init__(self, **kwargs):
         self.samplenum = 0
         self.state = 'WAIT FOR FALLING EDGE'
@@ -87,7 +97,7 @@ class Decoder(srd.Decoder):
         self.samplerate = metadata['samplerate']
 
         # Check if samplerate is appropriate.
-        if self.options['overdrive']:
+        if self.options['overdrive'] == 'yes':
             if self.samplerate < 2000000:
                 self.putm([1, ['Sampling rate is too low. Must be above ' +
                                '2MHz for proper overdrive mode decoding.']])
@@ -191,7 +201,7 @@ class Decoder(srd.Decoder):
                     self.state = 'WAIT FOR RISING EDGE'
                     continue
 
-                self.putb([0, ['Bit: %d' % self.bit]])
+                self.putb([0, ['Bit: %d' % self.bit, '%d' % self.bit]])
                 self.putpb(['BIT', self.bit])
 
                 # Checking the first command to see if overdrive mode
@@ -199,7 +209,7 @@ class Decoder(srd.Decoder):
                 if self.bit_cnt <= 8:
                     self.command |= (self.bit << self.bit_cnt)
                 elif self.bit_cnt == 8 and self.command in [0x3c, 0x69]:
-                    self.putx([3, ['Entering overdrive mode']])
+                    self.putx([4, ['Entering overdrive mode', 'Overdrive on']])
                 # Increment the bit counter.
                 self.bit_cnt += 1
                 # Wait for next slot.
@@ -212,19 +222,21 @@ class Decoder(srd.Decoder):
                 # Check if this was a reset cycle.
                 t = self.samplenum - self.fall
                 if t > self.cnt_normal_reset:
-                    # Save the sample number for the falling edge.
+                    # Save the sample number for the rising edge.
                     self.rise = self.samplenum
+                    self.putfr([2, ['Reset', 'Rst', 'R']])
                     self.state = 'WAIT FOR PRESENCE DETECT'
                     # Exit overdrive mode.
                     if self.overdrive:
-                        self.putx([3, ['Exiting overdrive mode']])
+                        self.putx([4, ['Exiting overdrive mode', 'Overdrive off']])
                         self.overdrive = 0
                     # Clear command bit counter and data register.
                     self.bit_cnt = 0
                     self.command = 0
                 elif (t > self.cnt_overdrive_reset) and self.overdrive:
-                    # Save the sample number for the falling edge.
+                    # Save the sample number for the rising edge.
                     self.rise = self.samplenum
+                    self.putfr([2, ['Reset', 'Rst', 'R']])
                     self.state = "WAIT FOR PRESENCE DETECT"
                 # Otherwise this is assumed to be a data bit.
                 else:
@@ -247,8 +259,8 @@ class Decoder(srd.Decoder):
                     continue
 
                 p = 'false' if self.present else 'true'
-                self.putb([2, ['Reset/presence: %s' % p]])
-                self.putpb(['RESET/PRESENCE', not self.present])
+                self.putrs([3, ['Presence: %s' % p, 'Presence', 'Pres', 'P']])
+                self.putprs(['RESET/PRESENCE', not self.present])
 
                 # Wait for next slot.
                 self.state = 'WAIT FOR FALLING EDGE'