Skip to content

Commit 9a53ac3

Browse files
committed
Try fixing type casters
1 parent 8239995 commit 9a53ac3

5 files changed

Lines changed: 13 additions & 18 deletions

File tree

wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PeriodicPriorityQueue::Callback::Callback(std::function<void()> func,
4747
PeriodicPriorityQueue::Callback::Callback(std::function<void()> func,
4848
std::chrono::nanoseconds startTime,
4949
wpi::units::seconds<> period)
50-
: Callback{std::move(func), startTime, period, wpi::units::second_t{0}} {}
50+
: Callback{std::move(func), startTime, period, 0_s} {}
5151

5252
void PeriodicPriorityQueue::Add(std::function<void()> func,
5353
std::chrono::nanoseconds startTime,

wpilibc/src/main/python/wpilib/src/rpy/Notifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ void PyNotifier::SetCallback(std::function<void()> handler) {
129129
void PyNotifier::StartSingle(wpi::units::seconds<> delay) {
130130
int32_t status = 0;
131131
HAL_SetNotifierAlarm(m_notifier,
132-
wpi::units::nanosecond_t{delay}.to<int64_t>(), 0, false,
132+
wpi::units::nanoseconds<>{delay}.to<int64_t>(), 0, false,
133133
false, &status);
134134
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
135135
}
136136

137137
void PyNotifier::StartPeriodic(wpi::units::seconds<> period) {
138138
int32_t status = 0;
139-
auto periodNs = wpi::units::nanosecond_t{period}.to<int64_t>();
139+
auto periodNs = wpi::units::nanoseconds<>{period}.to<int64_t>();
140140
HAL_SetNotifierAlarm(m_notifier, periodNs, periodNs, false, false, &status);
141141
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
142142
}

wpilibc/src/test/native/cpp/LEDPatternTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ TEST_CASE("LEDPatternTest Breathe", "[wpilibc]") {
693693
wpi::util::Color midGray{0.5, 0.5, 0.5};
694694
std::array<AddressableLED::LEDData, 1> buffer;
695695
auto white = LEDPattern::Solid(wpi::util::Color::WHITE);
696-
auto pattern = white.Breathe(wpi::units::nanosecond_t{4});
696+
auto pattern = white.Breathe(4_ns);
697697

698698
static int64_t now = 0;
699699
WPI_SetNowImpl([] { return now; });

wpimath/src/main/python/wpimath/_impl/src/type_casters/_units_base_type_caster.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <pybind11/pybind11.h>
4+
#include <wpi/units/core.hpp>
45

56
namespace pybind11 {
67
namespace detail {
@@ -26,14 +27,10 @@ namespace detail {
2627
foo(wpi::units::seconds<> tm = 10_ms); // if not careful, pybind11 will
2728
// store as 10 seconds
2829
*/
29-
template <wpi::units::ConversionFactorType ConversionFactor,
30-
wpi::units::ArithmeticType T,
31-
wpi::units::NumericalScaleType<T> NumericalScale>
32-
struct type_caster<wpi::units::unit<ConversionFactor, T, NumericalScale>> {
33-
using value_type = wpi::units::unit<ConversionFactor, T, NumericalScale>;
34-
30+
template <wpi::units::UnitType Unit>
31+
struct type_caster<Unit> {
3532
// TODO: there should be a way to include the type with this
36-
PYBIND11_TYPE_CASTER(value_type, handle_type_name<value_type>::name);
33+
PYBIND11_TYPE_CASTER(Unit, handle_type_name<Unit>::name);
3734

3835
// Python -> C++
3936
bool load(handle src, bool convert) {
@@ -42,12 +39,12 @@ struct type_caster<wpi::units::unit<ConversionFactor, T, NumericalScale>> {
4239
if (!convert && !PyFloat_Check(src.ptr()))
4340
return false;
4441
auto cvted = PyFloat_AsDouble(src.ptr());
45-
value = value_type(cvted);
42+
value = Unit(cvted);
4643
return !(cvted == -1 && PyErr_Occurred());
4744
}
4845

4946
// C++ -> Python
50-
static handle cast(const value_type &src, return_value_policy /* policy */,
47+
static handle cast(const Unit& src, return_value_policy /* policy */,
5148
handle /* parent */) {
5249
return PyFloat_FromDouble(src.raw());
5350
}

wpimath/src/main/python/wpimath/_impl/src/type_casters/units_numpy_type_caster.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#pragma once
22

33
#include <pybind11/numpy.h>
4+
#include <wpi/units/core.hpp>
45

56
namespace pybind11 {
67
namespace detail {
78

8-
template <wpi::units::ConversionFactorType ConversionFactor,
9-
wpi::units::ArithmeticType T,
10-
wpi::units::NumericalScaleType<T> NumericalScale>
11-
struct npy_format_descriptor<
12-
wpi::units::unit<ConversionFactor, T, NumericalScale>> {
9+
template <wpi::units::UnitType Unit>
10+
struct npy_format_descriptor<Unit> {
1311
static constexpr auto name = const_name("numpy.float64");
1412
static constexpr int value = npy_api::NPY_DOUBLE_;
1513

0 commit comments

Comments
 (0)