From: Martin Ling Date: Wed, 17 Apr 2013 16:48:39 +0000 (+0100) Subject: python: Add Analog class. X-Git-Tag: dsupstream~106 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=15574a3cecc14dcbed38464317e37ac9cfe2d220;p=libsigrok.git python: Add Analog class. --- diff --git a/bindings/python/sigrok/core/classes.py b/bindings/python/sigrok/core/classes.py index 4bbda25d..52a11c40 100644 --- a/bindings/python/sigrok/core/classes.py +++ b/bindings/python/sigrok/core/classes.py @@ -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): diff --git a/bindings/swig/libsigrok.i b/bindings/swig/libsigrok.i index bbabdf2e..38e2e189 100644 --- a/bindings/swig/libsigrok.i +++ b/bindings/swig/libsigrok.i @@ -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)