Skip to content

Commit

Permalink
Add Apply overloads to Spark*Config
Browse files Browse the repository at this point in the history
- Fixes #68
  • Loading branch information
virtuald committed Nov 17, 2024
1 parent daede11 commit 0ea5301
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 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);
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 0ea5301

Please sign in to comment.