Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions subprojects/robotpy-wpilib/semiwrap/LEDPattern.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extra_includes:
- rpy/AddressableLEDBuffer.h
- memory
- pybind11/typing.h

classes:
wpi::LEDPattern:
Expand Down Expand Up @@ -49,6 +51,26 @@ classes:
ignore: true
Rainbow:
MapIndex:
# Use py::int_ so stubs emit Callable[[int, int], int] (issue #168).
# Own the callback like TelemetryRegistry::SetReportWarning so apply_to's
# release_gil() path can safely invoke it with gil_scoped_acquire.
cpp_code: |
[](wpi::LEDPattern& self,
py::typing::Callable<py::int_(py::int_, py::int_)> indexMapper) {
auto callbackOwner = std::shared_ptr<py::function>{
new py::function{std::move(indexMapper)}, [](py::function* callback) {
py::gil_scoped_acquire gil;
delete callback;
}};
return self.MapIndex(
[callbackOwner](size_t length, size_t idx) -> size_t {
py::gil_scoped_acquire gil;
return (*callbackOwner)(length, idx).cast<size_t>();
});
}
param_override:
indexMapper:
disable_none: true
inline_code: |
.def("apply_to", [](const wpi::LEDPattern& self, wpi::AddressableLEDBuffer& data) {
self.ApplyTo(static_cast<std::span<wpi::AddressableLED::LEDData>>(data));
Expand Down