Skip to content

Commit c10c792

Browse files
authored
Merge pull request #69 from robotpy/apply-config
Add Apply overloads to Spark*Config
2 parents daede11 + e9d861a commit c10c792

5 files changed

+68
-3
lines changed

gen/SparkFlexConfig.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22

3+
extra_includes:
4+
- sparkbaseconfig_apply.h
5+
36
classes:
47
SparkFlexConfig:
58
attributes:
@@ -11,3 +14,6 @@ classes:
1114
SparkFlexConfig&:
1215
ExternalEncoderConfig&:
1316
Flatten:
17+
inline_code: |
18+
bind_sparkbaseconfig_apply<SparkFlexConfig, decltype(cls_SparkFlexConfig)>(cls_SparkFlexConfig);
19+

gen/SparkMaxConfig.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22

3+
extra_includes:
4+
- sparkbaseconfig_apply.h
5+
36
classes:
47
SparkMaxConfig:
58
attributes:
@@ -13,3 +16,5 @@ classes:
1316
SparkMaxConfig&:
1417
AlternateEncoderConfig&:
1518
Flatten:
19+
inline_code: |
20+
bind_sparkbaseconfig_apply<SparkMaxConfig, decltype(cls_SparkMaxConfig)>(cls_SparkMaxConfig);

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ author_email = "robotpy@googlegroups.com"
66
url = "https://github.com/robotpy/robotpy-rev"
77
license = "BSD-3-Clause"
88
install_requires = [
9-
"wpilib~=2025.0.0b1",
9+
"wpilib~=2025.0.0b2",
1010
]
1111

1212
[build-system]
1313
requires = [
14-
"robotpy-build<2025.0.0b1,~=2025.0.0a1",
15-
"wpilib~=2025.0.0b1",
14+
"robotpy-build<2025.0.0b1,~=2025.0.0a4",
15+
"wpilib~=2025.0.0b2",
1616
]
1717

1818
[tool.robotpy-build]

rev/sparkbaseconfig_apply.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
template <typename T, typename Cls>
4+
void bind_sparkbaseconfig_apply(Cls &cls) {
5+
using namespace rev::spark;
6+
7+
auto sparkBaseConfigType = py::type::of<SparkBaseConfig>();
8+
9+
cls
10+
.def("apply", [=](T &self, SparkBaseConfig &config) -> T& {
11+
sparkBaseConfigType.attr("apply")(self, config);
12+
return self;
13+
}, py::arg("config"))
14+
.def("apply", [=](T &self, AbsoluteEncoderConfig &config) -> T& {
15+
sparkBaseConfigType.attr("apply")(self, config);
16+
return self;
17+
}, py::arg("config"))
18+
.def("apply", [=](T &self, AnalogSensorConfig &config) -> T& {
19+
sparkBaseConfigType.attr("apply")(self, config);
20+
return self;
21+
}, py::arg("config"))
22+
.def("apply", [=](T &self, EncoderConfig &config) -> T& {
23+
sparkBaseConfigType.attr("apply")(self, config);
24+
return self;
25+
}, py::arg("config"))
26+
.def("apply", [=](T &self, LimitSwitchConfig &config) -> T& {
27+
sparkBaseConfigType.attr("apply")(self, config);
28+
return self;
29+
}, py::arg("config"))
30+
.def("apply", [=](T &self, SoftLimitConfig &config) -> T& {
31+
sparkBaseConfigType.attr("apply")(self, config);
32+
return self;
33+
}, py::arg("config"))
34+
.def("apply", [=](T &self, ClosedLoopConfig &config) -> T& {
35+
sparkBaseConfigType.attr("apply")(self, config);
36+
return self;
37+
}, py::arg("config"))
38+
.def("apply", [=](T &self, SignalsConfig &config) -> T& {
39+
sparkBaseConfigType.attr("apply")(self, config);
40+
return self;
41+
}, py::arg("config"))
42+
;
43+
}

tests/test_config.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import rev
2+
3+
4+
def test_spark_flex_config():
5+
config = rev.SparkFlexConfig()
6+
config.apply(rev.EncoderConfig()).apply(rev.AbsoluteEncoderConfig())
7+
8+
9+
def test_spark_max_config():
10+
config = rev.SparkMaxConfig()
11+
config.apply(rev.EncoderConfig()).apply(rev.AbsoluteEncoderConfig())

0 commit comments

Comments
 (0)