|
2 | 2 | #include <pybind11/stl.h>
|
3 | 3 | #include <pybind11/iostream.h>
|
4 | 4 | #include <pybind11/operators.h>
|
| 5 | +#include <pybind11/numpy.h> |
5 | 6 |
|
6 | 7 | #include <USBKit.h>
|
7 | 8 |
|
@@ -48,7 +49,13 @@ py::class_<BUSBDevice>(m, "BUSBDevice")
|
48 | 49 | .def("Descriptor", &BUSBDevice::Descriptor, "")
|
49 | 50 | .def("GetStringDescriptor", &BUSBDevice::GetStringDescriptor, "", py::arg("index"), py::arg("descriptor"), py::arg("length"))
|
50 | 51 | .def("DecodeStringDescriptor", &BUSBDevice::DecodeStringDescriptor, "", py::arg("index"))
|
51 |
| -.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) |
| 52 | +//.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) //todo: void *data -> in py::bytes |
| 53 | +.def("GetDescriptor", [](const BUSBDevice& self, uint8 type, uint8 index, uint16 languageID, py::bytes data) { |
| 54 | + size_t length = py::len(data); |
| 55 | + std::vector<uint8_t> buffer(length); |
| 56 | + size_t resultLength = self.GetDescriptor(type, index, languageID, buffer.data(), length); |
| 57 | + return py::bytes(reinterpret_cast<const char*>(buffer.data()), resultLength); |
| 58 | +},"", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data")) |
52 | 59 | .def("CountConfigurations", &BUSBDevice::CountConfigurations, "")
|
53 | 60 | .def("ConfigurationAt", &BUSBDevice::ConfigurationAt, "", py::arg("index"))
|
54 | 61 | .def("ActiveConfiguration", &BUSBDevice::ActiveConfiguration, "")
|
@@ -98,10 +105,34 @@ py::class_<BUSBEndpoint, std::unique_ptr<BUSBEndpoint,py::nodelete>>(m, "BUSBEnd
|
98 | 105 | .def("MaxPacketSize", &BUSBEndpoint::MaxPacketSize, "")
|
99 | 106 | .def("Interval", &BUSBEndpoint::Interval, "")
|
100 | 107 | .def("Descriptor", &BUSBEndpoint::Descriptor, "")
|
101 |
| -.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) |
102 |
| -.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) |
103 |
| -.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) |
104 |
| -.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) |
| 108 | +//.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) |
| 109 | +.def("ControlTransfer", [](const BUSBEndpoint& self, uint8 requestType, uint8 request, uint16 value, uint16 index, uint16 length, py::bytes data) { |
| 110 | + size_t dataLength = py::len(data); |
| 111 | + std::vector<uint8_t> buffer(dataLength); |
| 112 | + ssize_t result = self.ControlTransfer(requestType, request, value, index, length, buffer.data()); |
| 113 | + return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); |
| 114 | +},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) .def("InterruptTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data")) .def("BulkTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); ssize_t result = self.BulkTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data")) .def("IsochronousTransfer", [](const MyDevice& self, py::bytes data, py::list packetDescriptors) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); // Converti packetDescriptors da lista Python a un array C++ std::vector<usb_iso_packet_descriptor> descriptors; for (auto item : packetDescriptors) { descriptors.push_back(item.cast<usb_iso_packet_descriptor>()); } ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength, descriptors.data(), descriptors.size()); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data"), py::arg("packetDescriptors")) |
| 115 | +//.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) |
| 116 | +.def("InterruptTransfer", [](const BUSBEndpoint& self, py::bytes data) { |
| 117 | + size_t dataLength = py::len(data); |
| 118 | + std::vector<uint8_t> buffer(dataLength); |
| 119 | + ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); |
| 120 | + return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); |
| 121 | +},"", py::arg("data")) |
| 122 | +//.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) |
| 123 | +.def("BulkTransfer", [](const BUSBEndpoint& self, py::bytes data) { |
| 124 | + size_t dataLength = py::len(data); |
| 125 | + std::vector<uint8_t> buffer(dataLength); |
| 126 | + ssize_t result = self.BulkTransfer(buffer.data(), dataLength); |
| 127 | + return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); |
| 128 | +},"", py::arg("data")) |
| 129 | +//.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) |
| 130 | +.def("IsochronousTransfer", [](const BUSBEndpoint& self, py::bytes data, usb_iso_packet_descriptor *packetDescriptors, uint32 packetCount) { |
| 131 | + size_t dataLength = py::len(data); |
| 132 | + std::vector<uint8_t> buffer(dataLength); |
| 133 | + ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength,packetDescriptors,packetCount); |
| 134 | + return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); |
| 135 | +},"", py::arg("data")) |
105 | 136 | .def("IsStalled", &BUSBEndpoint::IsStalled, "")
|
106 | 137 | .def("ClearStall", &BUSBEndpoint::ClearStall, "")
|
107 | 138 | ;
|
|
0 commit comments