Skip to content

Commit b82abfe

Browse files
committed
update unused USBKit
1 parent 267e21f commit b82abfe

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

bindings/device/USBKit.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <pybind11/stl.h>
33
#include <pybind11/iostream.h>
44
#include <pybind11/operators.h>
5+
#include <pybind11/numpy.h>
56

67
#include <USBKit.h>
78

@@ -48,7 +49,13 @@ py::class_<BUSBDevice>(m, "BUSBDevice")
4849
.def("Descriptor", &BUSBDevice::Descriptor, "")
4950
.def("GetStringDescriptor", &BUSBDevice::GetStringDescriptor, "", py::arg("index"), py::arg("descriptor"), py::arg("length"))
5051
.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"))
5259
.def("CountConfigurations", &BUSBDevice::CountConfigurations, "")
5360
.def("ConfigurationAt", &BUSBDevice::ConfigurationAt, "", py::arg("index"))
5461
.def("ActiveConfiguration", &BUSBDevice::ActiveConfiguration, "")
@@ -98,10 +105,34 @@ py::class_<BUSBEndpoint, std::unique_ptr<BUSBEndpoint,py::nodelete>>(m, "BUSBEnd
98105
.def("MaxPacketSize", &BUSBEndpoint::MaxPacketSize, "")
99106
.def("Interval", &BUSBEndpoint::Interval, "")
100107
.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"))
105136
.def("IsStalled", &BUSBEndpoint::IsStalled, "")
106137
.def("ClearStall", &BUSBEndpoint::ClearStall, "")
107138
;

0 commit comments

Comments
 (0)