Skip to content

Commit

Permalink
Switch everything to Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Mar 19, 2024
1 parent 7e22e01 commit a888532
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/cscore/Raw/RawSink.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using CsCore.Handles;
using CsCore.Natives;
using UnitsNet;
using UnitsNet.NumberExtensions.NumberToDuration;
using WPIUtil;

namespace CsCore.Raw;
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions src/ntcore/NetworkTableInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CommunityToolkit.Diagnostics;
using NetworkTables.Handles;
using NetworkTables.Natives;
using UnitsNet;
using WPIUtil.Concurrent;
using WPIUtil.Handles;
using WPIUtil.Logging;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -389,7 +390,7 @@ private void StartThread()
m_thread.Start();
}

public bool WaitForQueue(TimeSpan? timeout)
public bool WaitForQueue(Duration? timeout)
{
lock (m_lock)
{
Expand All @@ -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());
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/wpilibsharp/AddressableLED.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using UnitsNet;
using WPIHal.Handles;
using WPIHal.Natives;

Expand Down Expand Up @@ -41,14 +42,14 @@ public void SetData(ReadOnlySpan<HalAddressableLED.LedData> 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()
Expand Down

0 comments on commit a888532

Please sign in to comment.