]> sigrok.org Git - libsigrok.git/blobdiff - bindings/python/sigrok/core/classes.i
Python-Binding: Added data array for logic packet payload
[libsigrok.git] / bindings / python / sigrok / core / classes.i
index 2afd9cf131ed6ae7f7977dce357ae881fa4b9a66..63a5143ebc96b8379b14a3fe86035641159719f4 100644 (file)
@@ -45,6 +45,8 @@ which provides access to the error code and description."
 %module(docstring=DOCSTRING) classes
 
 %{
+#include "config.h"
+
 #include <stdio.h>
 #include <pygobject.h>
 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -53,8 +55,6 @@ which provides access to the error code and description."
 PyObject *PyGObject_lib;
 PyObject *GLib;
 
-#include "config.h"
-
 #if PYGOBJECT_FLAGS_SIGNED
 typedef gint pyg_flags_type;
 #else
@@ -390,6 +390,7 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
 
 /* Ignore these methods, we will override them below. */
 %ignore sigrok::Analog::data;
+%ignore sigrok::Logic::data;
 %ignore sigrok::Driver::scan;
 %ignore sigrok::InputFormat::create_input;
 %ignore sigrok::OutputFormat::create_output;
@@ -548,4 +549,24 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
 }
 }
 
+/* Return NumPy array from Logic::data(). */
+%extend sigrok::Logic
+{
+    PyObject * _data()
+    {
+        npy_intp dims[2];
+        dims[0] = $self->data_length() / $self->unit_size();
+        dims[1] = $self->unit_size();
+        int typenum = NPY_UINT8;
+        void *data = $self->data_pointer();
+        return PyArray_SimpleNewFromData(2, dims, typenum, data);
+    }
+
+%pythoncode
+{
+    data = property(_data)
+}
+}
+
+
 %include "doc_end.i"