Skip to content

Commit

Permalink
Add most of the missing RobotController functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Mar 19, 2024
1 parent a888532 commit 0aaaa30
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/hal/Natives/HalPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,34 @@ public static partial class HalPower
[LibraryImport("wpiHal", EntryPoint = "HAL_GetVinVoltage")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetVinVoltage(out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_GetCPUTemp")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetCPUTemp(out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_GetBrownoutVoltage")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetBrownoutVoltage(out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_SetBrownoutVoltage")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetBrownoutVoltage(double voltage, out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_SetUserRailEnabled3V3")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetUserRailEnabled3V3([MarshalAs(UnmanagedType.I4)] bool enabled, out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_SetUserRailEnabled5V")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetUserRailEnabled5V([MarshalAs(UnmanagedType.I4)] bool enabled, out HalStatus status);

[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)]
[LibraryImport("wpiHal", EntryPoint = "HAL_SetUserRailEnabled6V")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetUserRailEnabled6V([MarshalAs(UnmanagedType.I4)] bool enabled, out HalStatus status);
}
3 changes: 3 additions & 0 deletions src/wpilibsharp/CANStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace WPILib;

public record struct CANStatus(double PercentBusUtilization, int BusOffCount, int TxFullCount, int ReceiveErrorCount, int TransmitErrorCount);
22 changes: 22 additions & 0 deletions src/wpilibsharp/RobotController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using UnitsNet;
using UnitsNet.NumberExtensions.NumberToElectricCurrent;
using UnitsNet.NumberExtensions.NumberToElectricPotential;
using UnitsNet.NumberExtensions.NumberToTemperature;
using WPIHal;
using WPIHal.Natives;
using WPIHal.Natives.Simulation;

namespace WPILib;

Expand All @@ -21,4 +24,23 @@ public static class RobotController
public static bool IsSystemTimeValid => HalBase.GetSystemTimeValid();
public static ElectricPotential InputVoltage => BatteryVoltage;
public static ElectricCurrent InputCurrent => HalPower.GetVinCurrent().Amperes();
public static ElectricPotential BrownoutVoltage
{
get => HalPower.GetBrownoutVoltage().Volts();
set => HalPower.SetBrownoutVoltage(value.Volts);
}
public static Temperature CPUTemp => HalPower.GetCPUTemp().DegreesCelsius();
public static RadioLEDState RadioLED
{
get => HalLEDs.GetRadioLEDState();
set => HalLEDs.SetRadioLEDState(value);
}
public static CANStatus CANStatus
{
get
{
HalCAN.GetCANStatus(out var percentBusUtilization, out var busOffCount, out var txFullCount, out var receiveErrorCount, out var transmitErrorCount);
return new CANStatus(percentBusUtilization, (int)busOffCount, (int)txFullCount, (int)receiveErrorCount, (int)transmitErrorCount);
}
}
}

0 comments on commit 0aaaa30

Please sign in to comment.