]> sigrok.org Git - libsigrok.git/commitdiff
python: Add Analog class.
authorMartin Ling <redacted>
Wed, 17 Apr 2013 16:48:39 +0000 (17:48 +0100)
committerUwe Hermann <redacted>
Thu, 18 Apr 2013 15:45:38 +0000 (17:45 +0200)
bindings/python/sigrok/core/classes.py
bindings/swig/libsigrok.i

index 4bbda25d6f5369214eca0fd3cfa6f8ece59551b2..52a11c4086bbfdf048663f7c5d79333efa343a06 100644 (file)
@@ -225,6 +225,9 @@ class Packet(object):
             if self.struct.type == SR_DF_LOGIC:
                 self._payload = Logic(self,
                     void_ptr_to_sr_datafeed_logic_ptr(pointer))
+            elif self.struct.type == SR_DF_ANALOG:
+                self._payload = Analog(self,
+                    void_ptr_to_sr_datafeed_analog_ptr(pointer))
             else:
                 raise NotImplementedError(
                     "No Python mapping for packet type %ѕ" % self.struct.type)
@@ -243,6 +246,23 @@ class Logic(object):
             self._data = cdata(self.struct.data, self.struct.length)
         return self._data
 
+class Analog(object):
+
+    def __init__(self, packet, struct):
+        self.packet = packet
+        self.struct = struct
+        self._data = None
+
+    @property
+    def num_samples(self):
+        return self.struct.num_samples
+
+    @property
+    def data(self):
+        if self._data is None:
+            self._data = float_array.frompointer(self.struct.data)
+        return self._data
+
 for symbol_name in dir(lowlevel):
     prefix = 'SR_DF_'
     if symbol_name.startswith(prefix):
index bbabdf2e3cd5bb184e98849a876df17467842c22..38e2e189784611124181f371ed44ee0149ec1f2a 100644 (file)
@@ -56,9 +56,11 @@ GVariant *g_variant_get_child_value(GVariant *value, unsigned long index);
 %include "libsigrok/proto.h"
 %include "libsigrok/version.h"
 
+%array_class(float, float_array);
 %pointer_functions(GVariant *, gvariant_ptr_ptr);
 %array_functions(GVariant *, gvariant_ptr_array);
 %pointer_functions(struct sr_context *, sr_context_ptr_ptr);
 %array_functions(struct sr_dev_driver *, sr_dev_driver_ptr_array);
 %pointer_cast(gpointer, struct sr_dev_inst *, gpointer_to_sr_dev_inst_ptr);
 %pointer_cast(void *, struct sr_datafeed_logic *, void_ptr_to_sr_datafeed_logic_ptr)
+%pointer_cast(void *, struct sr_datafeed_analog *, void_ptr_to_sr_datafeed_analog_ptr)