X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fpython%2Fsigrok%2Fcore%2Fclasses.i;h=a00efff2536d78911cd7a8b41f2744ad418c8479;hb=62bd644f55b674730957be4e3dcd3d3362148cfc;hp=2afd9cf131ed6ae7f7977dce357ae881fa4b9a66;hpb=c61e208d26325c38c9c928b00890a70f55633ddf;p=libsigrok.git diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 2afd9cf1..a00efff2 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -45,6 +45,8 @@ which provides access to the error code and description." %module(docstring=DOCSTRING) classes %{ +#include "config.h" + #include #include #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 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,42 @@ std::map 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) +} +} + +/* Create logic packet from Python buffer. */ +%extend sigrok::Context +{ + std::shared_ptr _create_logic_packet_buf(PyObject *buf, unsigned int unit_size) + { + Py_buffer view; + PyObject_GetBuffer(buf, &view, PyBUF_SIMPLE); + return $self->create_logic_packet(view.buf, view.len, unit_size); + } +} + +%pythoncode +{ + def _Context_create_logic_packet(self, buf, unit_size): + return self._create_logic_packet_buf(buf, unit_size) + + Context.create_logic_packet = _Context_create_logic_packet +} + %include "doc_end.i"