From a8885321d8e9a90ca7c93646a3f48360c2bd16c0 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 19 Mar 2024 16:10:34 -0400 Subject: [PATCH] Switch everything to Duration --- src/cscore/Raw/RawSink.cs | 8 +++++--- src/ntcore/NetworkTableInstance.cs | 7 ++++--- src/wpilibsharp/AddressableLED.cs | 9 +++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cscore/Raw/RawSink.cs b/src/cscore/Raw/RawSink.cs index ffc27fef..9c6a997b 100644 --- a/src/cscore/Raw/RawSink.cs +++ b/src/cscore/Raw/RawSink.cs @@ -1,5 +1,7 @@ using CsCore.Handles; using CsCore.Natives; +using UnitsNet; +using UnitsNet.NumberExtensions.NumberToDuration; using WPIUtil; namespace CsCore.Raw; @@ -15,12 +17,12 @@ private static CsSink CreateRawSink(string name) public long GrabFrame(RawFrameReader frame) { - return GrabFrame(frame, TimeSpan.FromSeconds(0.225)); + return GrabFrame(frame, 0.225.Seconds()); } - public long GrabFrame(RawFrameReader frame, TimeSpan timeout) + public long GrabFrame(RawFrameReader frame, Duration timeout) { - var time = CsNative.GrabRawSinkFrame(Handle, frame, timeout.TotalSeconds); + var time = CsNative.GrabRawSinkFrame(Handle, frame, timeout.Seconds); return (long)time; } diff --git a/src/ntcore/NetworkTableInstance.cs b/src/ntcore/NetworkTableInstance.cs index 55bde863..b6a92c02 100644 --- a/src/ntcore/NetworkTableInstance.cs +++ b/src/ntcore/NetworkTableInstance.cs @@ -12,6 +12,7 @@ using CommunityToolkit.Diagnostics; using NetworkTables.Handles; using NetworkTables.Natives; +using UnitsNet; using WPIUtil.Concurrent; using WPIUtil.Handles; using WPIUtil.Logging; @@ -198,7 +199,7 @@ public void RemoveListener(NtListener listener) m_listeners.Remove(listener); } - public bool WaitForListenerQueue(TimeSpan? timeout) + public bool WaitForListenerQueue(Duration? timeout) { return m_listeners.WaitForQueue(timeout); } @@ -389,7 +390,7 @@ private void StartThread() m_thread.Start(); } - public bool WaitForQueue(TimeSpan? timeout) + public bool WaitForQueue(Duration? timeout) { lock (m_lock) { @@ -406,7 +407,7 @@ public bool WaitForQueue(TimeSpan? timeout) } else { - return Monitor.Wait(m_lock, timeout.Value); + return Monitor.Wait(m_lock, timeout.Value.ToTimeSpan()); } } } diff --git a/src/wpilibsharp/AddressableLED.cs b/src/wpilibsharp/AddressableLED.cs index c60b8255..51dc9418 100644 --- a/src/wpilibsharp/AddressableLED.cs +++ b/src/wpilibsharp/AddressableLED.cs @@ -1,3 +1,4 @@ +using UnitsNet; using WPIHal.Handles; using WPIHal.Natives; @@ -41,14 +42,14 @@ public void SetData(ReadOnlySpan buffer) HalAddressableLED.WriteAddressableLEDData(m_handle, buffer); } - public void SetBitTiming(TimeSpan highTime0, TimeSpan lowTime0, TimeSpan highTime1, TimeSpan lowTime1) + public void SetBitTiming(Duration highTime0, Duration lowTime0, Duration highTime1, Duration lowTime1) { - HalAddressableLED.SetAddressableLEDBitTiming(m_handle, (int)highTime0.TotalNanoseconds, (int)lowTime0.TotalNanoseconds, (int)highTime1.TotalNanoseconds, (int)lowTime1.TotalNanoseconds); + HalAddressableLED.SetAddressableLEDBitTiming(m_handle, (int)highTime0.Nanoseconds, (int)lowTime0.Nanoseconds, (int)highTime1.Nanoseconds, (int)lowTime1.Nanoseconds); } - public void SetSyncTime(TimeSpan syncTime) + public void SetSyncTime(Duration syncTime) { - HalAddressableLED.SetAddressableLEDSyncTime(m_handle, (int)syncTime.TotalMicroseconds); + HalAddressableLED.SetAddressableLEDSyncTime(m_handle, (int)syncTime.Microseconds); } public void Start()