Skip to content

Commit

Permalink
Sim data
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Mar 4, 2024
1 parent 0457cef commit 5e4965e
Show file tree
Hide file tree
Showing 29 changed files with 2,804 additions and 0 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/hal/JoystickDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace WPIHal;
public readonly record struct JoystickDescriptor(bool IsXbox, int Type, string Name, int[] AxisTypes, int ButtonCount, int PovCount);

[CustomMarshaller(typeof(JoystickDescriptor), MarshalMode.ManagedToUnmanagedOut, typeof(JoystickDescriptorMarshaller))]
[CustomMarshaller(typeof(JoystickDescriptor), MarshalMode.ManagedToUnmanagedIn, typeof(JoystickDescriptorMarshaller))]
public static class JoystickDescriptorMarshaller
{
public static JoystickDescriptor ConvertToManaged(NativeJoystickDescriptor unmanaged)
Expand All @@ -22,6 +23,11 @@ public static JoystickDescriptor ConvertToManaged(NativeJoystickDescriptor unman
};
}

public static NativeJoystickDescriptor ConvertToUnmanaged(JoystickDescriptor managed)
{
throw new NotImplementedException();
}

[StructLayout(LayoutKind.Sequential)]
public struct NativeJoystickDescriptor
{
Expand Down
6 changes: 6 additions & 0 deletions src/hal/MatchInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace WPIHal;
public record struct MatchInfo(string EventName, MatchType MatchType, int MatchNumber, int ReplayNumber, byte[] GameSpecificMessage);

[CustomMarshaller(typeof(MatchInfo), MarshalMode.ManagedToUnmanagedOut, typeof(MatchInfoMarshaller))]
[CustomMarshaller(typeof(MatchInfo), MarshalMode.ManagedToUnmanagedIn, typeof(MatchInfoMarshaller))]
public static class MatchInfoMarshaller
{
public static unsafe MatchInfo ConvertToManaged(NativeMatchInfo unmanaged)
Expand All @@ -22,6 +23,11 @@ public static unsafe MatchInfo ConvertToManaged(NativeMatchInfo unmanaged)
};
}

public static NativeMatchInfo ConvertToUnmanaged(in MatchInfo managed)
{
throw new NotImplementedException();
}

[StructLayout(LayoutKind.Sequential)]
public struct NativeMatchInfo
{
Expand Down
99 changes: 99 additions & 0 deletions src/hal/Natives/Simulation/AccelerometerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]<byte*, void*, byte*, uint, void>;
using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]<byte*, void*, WPIHal.HalValue*, void>;

namespace WPIHal.Natives.Simulation;

public static unsafe partial class HalAccelerometerData
{
[LibraryImport("wpiHal", EntryPoint = "HALSIM_ResetAccelerometerData")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void ResetAccelerometerData(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerActiveCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAccelerometerActiveCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAccelerometerActiveCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAccelerometerActiveCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAccelerometerActive")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[return: MarshalAs(UnmanagedType.I4)]
public static partial bool GetAccelerometerActive(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAccelerometerActive")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAccelerometerActive(int index, [MarshalAs(UnmanagedType.I4)] bool active);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerRangeCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAccelerometerRangeCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAccelerometerRangeCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAccelerometerRangeCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAccelerometerRange")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial HalAccelerometer.Range GetAccelerometerRange(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAccelerometerRange")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAccelerometerRange(int index, HalAccelerometer.Range range);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerXCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAccelerometerXCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAccelerometerXCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAccelerometerXCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAccelerometerX")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetAccelerometerX(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAccelerometerX")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAccelerometerX(int index, double x);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerYCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAccelerometerYCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAccelerometerYCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAccelerometerYCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAccelerometerY")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetAccelerometerY(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAccelerometerY")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAccelerometerY(int index, double y);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerZCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAccelerometerZCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAccelerometerZCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAccelerometerZCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAccelerometerZ")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetAccelerometerZ(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAccelerometerZ")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAccelerometerZ(int index, double z);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAccelerometerAllCallbacks")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void RegisterAccelerometerAllCallbacks(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

}
105 changes: 105 additions & 0 deletions src/hal/Natives/Simulation/AddressableLEDData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]<byte*, void*, byte*, uint, void>;
using unsafe HAL_ConstBufferCallback = delegate* unmanaged[Cdecl]<byte*, void*, byte*, uint, void>;
using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]<byte*, void*, WPIHal.HalValue*, void>;

namespace WPIHal.Natives.Simulation;

public static unsafe partial class HalAddressableLEDData
{
[LibraryImport("wpiHal", EntryPoint = "HALSIM_FindAddressableLEDForChannel")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int FindAddressableLEDForChannel(int channel);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_ResetAddressableLEDData")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void ResetAddressableLEDData(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDInitializedCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAddressableLEDInitializedCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAddressableLEDInitializedCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAddressableLEDInitializedCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAddressableLEDInitialized")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[return: MarshalAs(UnmanagedType.I4)]
public static partial bool GetAddressableLEDInitialized(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAddressableLEDInitialized")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAddressableLEDInitialized(int index, [MarshalAs(UnmanagedType.I4)] bool initialized);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDOutputPortCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAddressableLEDOutputPortCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAddressableLEDOutputPortCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAddressableLEDOutputPortCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAddressableLEDOutputPort")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int GetAddressableLEDOutputPort(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAddressableLEDOutputPort")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAddressableLEDOutputPort(int index, int outputPort);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDLengthCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAddressableLEDLengthCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAddressableLEDLengthCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAddressableLEDLengthCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAddressableLEDLength")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int GetAddressableLEDLength(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAddressableLEDLength")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAddressableLEDLength(int index, int length);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDRunningCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAddressableLEDRunningCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAddressableLEDRunningCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAddressableLEDRunningCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAddressableLEDRunning")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[return: MarshalAs(UnmanagedType.I4)]
public static partial bool GetAddressableLEDRunning(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAddressableLEDRunning")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAddressableLEDRunning(int index, [MarshalAs(UnmanagedType.I4)] bool running);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDDataCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAddressableLEDDataCallback(int index, HAL_ConstBufferCallback callback, void* param);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAddressableLEDDataCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAddressableLEDDataCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAddressableLEDData")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int GetAddressableLEDData(int index, HalAddressableLED.LedData* data);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAddressableLEDData")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAddressableLEDData(int index, HalAddressableLED.LedData* data, int length);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAddressableLEDAllCallbacks")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void RegisterAddressableLEDAllCallbacks(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

}
67 changes: 67 additions & 0 deletions src/hal/Natives/Simulation/AnalogGyroData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]<byte*, void*, byte*, uint, void>;
using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]<byte*, void*, WPIHal.HalValue*, void>;

namespace WPIHal.Natives.Simulation;

public static unsafe partial class HalAnalogGyroData
{
[LibraryImport("wpiHal", EntryPoint = "HALSIM_ResetAnalogGyroData")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void ResetAnalogGyroData(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAnalogGyroAngleCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAnalogGyroAngleCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAnalogGyroAngleCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAnalogGyroAngleCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAnalogGyroAngle")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetAnalogGyroAngle(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAnalogGyroAngle")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAnalogGyroAngle(int index, double angle);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAnalogGyroRateCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAnalogGyroRateCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAnalogGyroRateCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAnalogGyroRateCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAnalogGyroRate")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial double GetAnalogGyroRate(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAnalogGyroRate")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAnalogGyroRate(int index, double rate);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAnalogGyroInitializedCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int RegisterAnalogGyroInitializedCallback(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_CancelAnalogGyroInitializedCallback")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void CancelAnalogGyroInitializedCallback(int index, int uid);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_GetAnalogGyroInitialized")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[return: MarshalAs(UnmanagedType.I4)]
public static partial bool GetAnalogGyroInitialized(int index);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_SetAnalogGyroInitialized")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetAnalogGyroInitialized(int index, [MarshalAs(UnmanagedType.I4)] bool initialized);

[LibraryImport("wpiHal", EntryPoint = "HALSIM_RegisterAnalogGyroAllCallbacks")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void RegisterAnalogGyroAllCallbacks(int index, HAL_NotifyCallback callback, void* param, [MarshalAs(UnmanagedType.I4)] bool initialNotify);

}
Loading

0 comments on commit 5e4965e

Please sign in to comment.