Skip to content

Commit

Permalink
Merge pull request #69 from robotpy/apply-config
Browse files Browse the repository at this point in the history
Add Apply overloads to Spark*Config
  • Loading branch information
virtuald authored Nov 23, 2024
2 parents daede11 + e9d861a commit c10c792
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
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())

0 comments on commit c10c792

Please sign in to comment.