From 0ea5301caa3d11dcbf96eea53d32515f69025074 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sat, 16 Nov 2024 23:47:18 -0500 Subject: [PATCH 1/2] Add Apply overloads to Spark*Config - Fixes #68 --- gen/SparkFlexConfig.yml | 6 ++++++ gen/SparkMaxConfig.yml | 5 +++++ rev/sparkbaseconfig_apply.h | 43 +++++++++++++++++++++++++++++++++++++ tests/test_config.py | 11 ++++++++++ 4 files changed, 65 insertions(+) create mode 100644 rev/sparkbaseconfig_apply.h create mode 100644 tests/test_config.py diff --git a/gen/SparkFlexConfig.yml b/gen/SparkFlexConfig.yml index e7b0a5e..9cc49a7 100644 --- a/gen/SparkFlexConfig.yml +++ b/gen/SparkFlexConfig.yml @@ -1,5 +1,8 @@ --- +extra_includes: +- sparkbaseconfig_apply.h + classes: SparkFlexConfig: attributes: @@ -11,3 +14,6 @@ classes: SparkFlexConfig&: ExternalEncoderConfig&: Flatten: +inline_code: | + bind_sparkbaseconfig_apply(cls_SparkFlexConfig); + diff --git a/gen/SparkMaxConfig.yml b/gen/SparkMaxConfig.yml index 9ecd1b5..db7b596 100644 --- a/gen/SparkMaxConfig.yml +++ b/gen/SparkMaxConfig.yml @@ -1,5 +1,8 @@ --- +extra_includes: +- sparkbaseconfig_apply.h + classes: SparkMaxConfig: attributes: @@ -13,3 +16,5 @@ classes: SparkMaxConfig&: AlternateEncoderConfig&: Flatten: +inline_code: | + bind_sparkbaseconfig_apply(cls_SparkMaxConfig); diff --git a/rev/sparkbaseconfig_apply.h b/rev/sparkbaseconfig_apply.h new file mode 100644 index 0000000..890cfa1 --- /dev/null +++ b/rev/sparkbaseconfig_apply.h @@ -0,0 +1,43 @@ +#pragma once + +template +void bind_sparkbaseconfig_apply(Cls &cls) { + using namespace rev::spark; + + auto sparkBaseConfigType = py::type::of(); + + cls + .def("apply", [=](T &self, SparkBaseConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, AbsoluteEncoderConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, AnalogSensorConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, EncoderConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, LimitSwitchConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, SoftLimitConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, ClosedLoopConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + .def("apply", [=](T &self, SignalsConfig &config) -> T& { + sparkBaseConfigType.attr("apply")(self, config); + return self; + }, py::arg("config")) + ; +} \ No newline at end of file diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..ca3115e --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,11 @@ +import rev + + +def test_spark_flex_config(): + config = rev.SparkFlexConfig() + config.apply(rev.EncoderConfig()).apply(rev.AbsoluteEncoderConfig()) + + +def test_spark_max_config(): + config = rev.SparkMaxConfig() + config.apply(rev.EncoderConfig()).apply(rev.AbsoluteEncoderConfig()) From e9d861a6d70838264310ee9ef991386e8cdb0ea3 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Fri, 22 Nov 2024 20:56:29 -0500 Subject: [PATCH 2/2] Update dependencies --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3de5ab8..9e47300 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,13 +6,13 @@ author_email = "robotpy@googlegroups.com" url = "https://github.com/robotpy/robotpy-rev" license = "BSD-3-Clause" install_requires = [ - "wpilib~=2025.0.0b1", + "wpilib~=2025.0.0b2", ] [build-system] requires = [ - "robotpy-build<2025.0.0b1,~=2025.0.0a1", - "wpilib~=2025.0.0b1", + "robotpy-build<2025.0.0b1,~=2025.0.0a4", + "wpilib~=2025.0.0b2", ] [tool.robotpy-build]