From: Martin Ling Date: Mon, 16 Dec 2013 01:21:39 +0000 (+0000) Subject: python: Add initial support for input and output formats. X-Git-Tag: libsigrok-0.3.0~440 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a64198c8ea721c3a7867e9a753f1a761b89769c9;p=libsigrok.git python: Add initial support for input and output formats. --- diff --git a/bindings/python/sigrok/core/classes.py b/bindings/python/sigrok/core/classes.py index 2d998ac9..6b55eb3f 100644 --- a/bindings/python/sigrok/core/classes.py +++ b/bindings/python/sigrok/core/classes.py @@ -87,6 +87,8 @@ class Context(object): self.struct = sr_context_ptr_ptr_value(context_ptr_ptr) self._drivers = None self._devices = {} + self._input_formats = None + self._output_formats = None self.session = None def __del__(self): @@ -105,6 +107,32 @@ class Context(object): break return self._drivers + @property + def input_formats(self): + if not self._input_formats: + self._input_formats = {} + input_list = sr_input_list() + for i in itertools.count(): + input_ptr = sr_input_format_ptr_array_getitem(input_list, i) + if input_ptr: + self._input_formats[input_ptr.id] = InputFormat(self, input_ptr) + else: + break + return self._input_formats + + @property + def output_formats(self): + if not self._output_formats: + self._output_formats = {} + output_list = sr_output_list() + for i in itertools.count(): + output_ptr = sr_output_format_ptr_array_getitem(output_list, i) + if output_ptr: + self._output_formats[output_ptr.id] = OutputFormat(self, output_ptr) + else: + break + return self._output_formats + class Driver(object): def __init__(self, context, struct): @@ -392,6 +420,34 @@ class Log(object): def domain(self, d): check(sr_log_logdomain_set(d)) +class InputFormat(object): + + def __init__(self, context, struct): + self.context = context + self.struct = struct + + @property + def id(self): + return self.struct.id + + @property + def description(self): + return self.struct.description + +class OutputFormat(object): + + def __init__(self, context, struct): + self.context = context + self.struct = struct + + @property + def id(self): + return self.struct.id + + @property + def description(self): + return self.struct.description + class EnumValue(object): _enum_values = {} diff --git a/bindings/swig/libsigrok.i b/bindings/swig/libsigrok.i index d18df516..9adb153f 100644 --- a/bindings/swig/libsigrok.i +++ b/bindings/swig/libsigrok.i @@ -61,6 +61,8 @@ GVariant *g_variant_get_child_value(GVariant *value, unsigned long index); %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); +%array_functions(struct sr_input_format *, sr_input_format_ptr_array); +%array_functions(struct sr_output_format *, sr_output_format_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)