-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using WPIHal.Handles; | ||
using WPIHal.Natives; | ||
|
||
namespace WPILib; | ||
|
||
public class AddressableLED : IDisposable | ||
{ | ||
private readonly HalDigitalHandle m_pwmHandle; | ||
private readonly HalAddressableLEDHandle m_handle; | ||
|
||
public AddressableLED(int port) | ||
{ | ||
m_pwmHandle = HalPWM.InitializePWMPort(HalBase.GetPort(port), Environment.StackTrace); | ||
m_handle = HalAddressableLED.InitializeAddressableLED(m_pwmHandle); | ||
// TODO report | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
GC.SuppressFinalize(this); | ||
if (m_handle.Handle != 0) | ||
{ | ||
HalAddressableLED.FreeAddressableLED(m_handle); | ||
} | ||
if (m_pwmHandle.Handle != 0) | ||
{ | ||
HalPWM.FreePWMPort(m_pwmHandle); | ||
} | ||
} | ||
|
||
public int Length | ||
{ | ||
set | ||
{ | ||
HalAddressableLED.SetAddressableLEDLength(m_handle, value); | ||
} | ||
} | ||
|
||
public void SetData(ReadOnlySpan<HalAddressableLED.LedData> buffer) | ||
{ | ||
HalAddressableLED.WriteAddressableLEDData(m_handle, buffer); | ||
} | ||
|
||
public void SetBitTiming(TimeSpan highTime0, TimeSpan lowTime0, TimeSpan highTime1, TimeSpan lowTime1) | ||
{ | ||
HalAddressableLED.SetAddressableLEDBitTiming(m_handle, (int)highTime0.TotalNanoseconds, (int)lowTime0.TotalNanoseconds, (int)highTime1.TotalNanoseconds, (int)lowTime1.TotalNanoseconds); | ||
} | ||
|
||
public void SetSyncTime(TimeSpan syncTime) | ||
{ | ||
HalAddressableLED.SetAddressableLEDSyncTime(m_handle, (int)syncTime.TotalMicroseconds); | ||
} | ||
|
||
public void Start() | ||
{ | ||
HalAddressableLED.StartAddressableLEDOutput(m_handle); | ||
} | ||
|
||
public void Stop() | ||
{ | ||
HalAddressableLED.StopAddressableLEDOutput(m_handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters