]> sigrok.org Git - libsigrok.git/commitdiff
python: Add classes for probes and probe groups.
authorMartin Ling <redacted>
Sun, 21 Apr 2013 14:46:48 +0000 (15:46 +0100)
committerUwe Hermann <redacted>
Fri, 8 Nov 2013 00:03:17 +0000 (01:03 +0100)
bindings/python/sigrok/core/classes.py
bindings/swig/libsigrok.i

index 068fd39408c2429c101b7d28ae171ca8033fdc72..4e0123508369ddbec8dad33620e1ef02c9528860 100644 (file)
@@ -24,7 +24,8 @@ from . import lowlevel
 import itertools
 
 __all__ = ['Error', 'Context', 'Driver', 'Device', 'Session', 'Packet', 'Log',
-    'LogLevel', 'PacketType', 'Quantity', 'Unit', 'QuantityFlag', 'ConfigKey']
+    'LogLevel', 'PacketType', 'Quantity', 'Unit', 'QuantityFlag', 'ConfigKey',
+       'ProbeType', 'Probe', 'ProbeGroup']
 
 class Error(Exception):
 
@@ -146,6 +147,8 @@ class Device(object):
     def __init__(self, driver, struct):
         self.driver = driver
         self.struct = struct
+        self._probes = None
+        self._probe_groups = None
 
     def __getattr__(self, name):
         key = getattr(ConfigKey, name.upper())
@@ -182,6 +185,73 @@ class Device(object):
     def version(self):
         return self.struct.version
 
+    @property
+    def probes(self):
+        if self._probes is None:
+            self._probes = {}
+            probe_list = self.struct.probes
+            while (probe_list):
+                probe_ptr = void_ptr_to_sr_probe_ptr(probe_list.data)
+                self._probes[probe_ptr.name] = Probe(self, probe_ptr)
+                probe_list = probe_list.next
+        return self._probes
+
+    @property
+    def probe_groups(self):
+        if self._probe_groups is None:
+            self._probe_groups = {}
+            probe_group_list = self.struct.probe_groups
+            while (probe_group_list):
+                probe_group_ptr = void_ptr_to_sr_probe_group_ptr(
+                    probe_group_list.data)
+                self._probe_groups[probe_group_ptr.name] = ProbeGroup(self,
+                    probe_group_ptr)
+                probe_group_list = probe_group_list.next
+        return self._probe_groups
+
+class Probe(object):
+
+    def __init__(self, device, struct):
+        self.device = device
+        self.struct = struct
+
+    @property
+    def type(self):
+        return ProbeType(self.struct.type)
+
+    @property
+    def enabled(self):
+        return self.struct.enabled
+
+    @property
+    def name(self):
+        return self.struct.name
+
+class ProbeGroup(object):
+
+    def __init__(self, device, struct):
+        self.device = device
+        self.struct = struct
+        self._probes = None
+
+    def __iter__(self):
+        return iter(self.probes)
+
+    @property
+    def name(self):
+        return self.struct.name
+
+    @property
+    def probes(self):
+        if self._probes is None:
+            self._probes = []
+            probe_list = self.struct.probes
+            while (probe_list):
+                probe_ptr = void_ptr_to_sr_probe_ptr(probe_list.data)
+                self._probes.append(Probe(self, probe_ptr))
+                probe_list = probe_list.next
+        return self._probes
+
 class Session(object):
 
     def __init__(self, context):
@@ -235,7 +305,7 @@ class Packet(object):
                     void_ptr_to_sr_datafeed_analog_ptr(pointer))
             else:
                 raise NotImplementedError(
-                    "No Python mapping for packet type %ѕ" % self.struct.type)
+                    "No Python mapping for packet type %s" % self.struct.type)
         return self._payload
 
 class Logic(object):
@@ -337,6 +407,9 @@ class QuantityFlag(EnumValue):
 class ConfigKey(EnumValue):
     pass
 
+class ProbeType(EnumValue):
+    pass
+
 for symbol_name in dir(lowlevel):
     for prefix, cls in [
         ('SR_LOG_', LogLevel),
@@ -344,7 +417,8 @@ for symbol_name in dir(lowlevel):
         ('SR_MQ_', Quantity),
         ('SR_UNIT_', Unit),
         ('SR_MQFLAG_', QuantityFlag),
-        ('SR_CONF_', ConfigKey)]:
+        ('SR_CONF_', ConfigKey),
+        ('SR_PROBE_', ProbeType)]:
         if symbol_name.startswith(prefix):
             name = symbol_name[len(prefix):]
             value = getattr(lowlevel, symbol_name)
index 9bfb779ed716ded9a820ca7aaff01350ad5b2ac0..d18df516bcd6d236d84a8de611f8efe75bfdaea3 100644 (file)
@@ -64,3 +64,5 @@ GVariant *g_variant_get_child_value(GVariant *value, unsigned long index);
 %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)
+%pointer_cast(void *, struct sr_probe *, void_ptr_to_sr_probe_ptr)
+%pointer_cast(void *, struct sr_probe_group *, void_ptr_to_sr_probe_group_ptr)