Skip to content

Add Apply overloads to Spark*Config #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions gen/SparkFlexConfig.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- sparkbaseconfig_apply.h

classes:
SparkFlexConfig:
attributes:
Expand All @@ -11,3 +14,6 @@ classes:
SparkFlexConfig&:
ExternalEncoderConfig&:
Flatten:
inline_code: |
bind_sparkbaseconfig_apply<SparkFlexConfig, decltype(cls_SparkFlexConfig)>(cls_SparkFlexConfig);

5 changes: 5 additions & 0 deletions gen/SparkMaxConfig.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- sparkbaseconfig_apply.h

classes:
SparkMaxConfig:
attributes:
Expand All @@ -13,3 +16,5 @@ classes:
SparkMaxConfig&:
AlternateEncoderConfig&:
Flatten:
inline_code: |
bind_sparkbaseconfig_apply<SparkMaxConfig, decltype(cls_SparkMaxConfig)>(cls_SparkMaxConfig);
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ author_email = "[email protected]"
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]
Expand Down
43 changes: 43 additions & 0 deletions rev/sparkbaseconfig_apply.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

template <typename T, typename Cls>
void bind_sparkbaseconfig_apply(Cls &cls) {
using namespace rev::spark;

auto sparkBaseConfigType = py::type::of<SparkBaseConfig>();

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"))
;
}
11 changes: 11 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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())
Loading