Python-Binding: Added data array for logic packet payload

This commit is contained in:
Sven Bursch-Osewold 2018-10-19 09:11:36 +02:00 committed by Uwe Hermann
parent 3cdad416e4
commit 4905215909
1 changed files with 21 additions and 0 deletions

View File

@ -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"