mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[sim] Add callbacks for joysticks and match info (#2628)
This commit is contained in:
@@ -12,10 +12,10 @@
|
||||
#include <wpi/spinlock.h>
|
||||
|
||||
#include "hal/simulation/DriverStationData.h"
|
||||
#include "hal/simulation/SimCallbackRegistry.h"
|
||||
#include "hal/simulation/SimDataValue.h"
|
||||
|
||||
namespace hal {
|
||||
struct JoystickOutputStore;
|
||||
|
||||
class DriverStationData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Enabled)
|
||||
@@ -26,6 +26,12 @@ class DriverStationData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(DsAttached)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(AllianceStationId)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(MatchTime)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickAxes)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickPOVs)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickButtons)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickDescriptor)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickOutputs)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(MatchInfo)
|
||||
|
||||
static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value
|
||||
MakeAllianceStationIdValue(HAL_AllianceStationID value) {
|
||||
@@ -36,26 +42,54 @@ class DriverStationData {
|
||||
DriverStationData();
|
||||
void ResetData();
|
||||
|
||||
int32_t RegisterJoystickAxesCallback(int32_t joystickNum,
|
||||
HAL_JoystickAxesCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickAxesCallback(int32_t uid);
|
||||
void GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
|
||||
void GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
|
||||
void GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons* buttons);
|
||||
void GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* descriptor);
|
||||
void GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble);
|
||||
void GetMatchInfo(HAL_MatchInfo* info);
|
||||
void FreeMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
void SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes);
|
||||
|
||||
int32_t RegisterJoystickPOVsCallback(int32_t joystickNum,
|
||||
HAL_JoystickPOVsCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickPOVsCallback(int32_t uid);
|
||||
void GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
|
||||
void SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs);
|
||||
|
||||
int32_t RegisterJoystickButtonsCallback(int32_t joystickNum,
|
||||
HAL_JoystickButtonsCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickButtonsCallback(int32_t uid);
|
||||
void GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons* buttons);
|
||||
void SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons);
|
||||
|
||||
int32_t RegisterJoystickDescriptorCallback(
|
||||
int32_t joystickNum, HAL_JoystickDescriptorCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelJoystickDescriptorCallback(int32_t uid);
|
||||
void GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* descriptor);
|
||||
void SetJoystickDescriptor(int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor);
|
||||
|
||||
int32_t RegisterJoystickOutputsCallback(int32_t joystickNum,
|
||||
HAL_JoystickOutputsCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickOutputsCallback(int32_t uid);
|
||||
void GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble);
|
||||
void SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
|
||||
int32_t RegisterMatchInfoCallback(HAL_MatchInfoCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelMatchInfoCallback(int32_t uid);
|
||||
void GetMatchInfo(HAL_MatchInfo* info);
|
||||
void SetMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
void FreeMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
void NotifyNewData();
|
||||
|
||||
void SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state);
|
||||
@@ -90,16 +124,39 @@ class DriverStationData {
|
||||
SimDataValue<double, HAL_MakeDouble, GetMatchTimeName> matchTime{0.0};
|
||||
|
||||
private:
|
||||
SimCallbackRegistry<HAL_JoystickAxesCallback, GetJoystickAxesName>
|
||||
m_joystickAxesCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickPOVsCallback, GetJoystickPOVsName>
|
||||
m_joystickPOVsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickButtonsCallback, GetJoystickButtonsName>
|
||||
m_joystickButtonsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickOutputsCallback, GetJoystickOutputsName>
|
||||
m_joystickOutputsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickDescriptorCallback, GetJoystickDescriptorName>
|
||||
m_joystickDescriptorCallbacks;
|
||||
SimCallbackRegistry<HAL_MatchInfoCallback, GetMatchInfoName>
|
||||
m_matchInfoCallbacks;
|
||||
|
||||
struct JoystickOutputStore {
|
||||
int64_t outputs = 0;
|
||||
int32_t leftRumble = 0;
|
||||
int32_t rightRumble = 0;
|
||||
};
|
||||
|
||||
struct JoystickData {
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_JoystickButtons buttons;
|
||||
JoystickOutputStore outputs;
|
||||
HAL_JoystickDescriptor descriptor;
|
||||
};
|
||||
|
||||
static constexpr int kNumJoysticks = 6;
|
||||
wpi::spinlock m_joystickDataMutex;
|
||||
JoystickData m_joystickData[kNumJoysticks];
|
||||
|
||||
wpi::spinlock m_matchInfoMutex;
|
||||
|
||||
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
|
||||
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
|
||||
std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
|
||||
|
||||
std::unique_ptr<JoystickOutputStore[]> m_joystickOutputs;
|
||||
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
|
||||
std::unique_ptr<HAL_MatchInfo> m_matchInfo;
|
||||
HAL_MatchInfo m_matchInfo;
|
||||
};
|
||||
extern DriverStationData* SimDriverStationData;
|
||||
} // namespace hal
|
||||
|
||||
Reference in New Issue
Block a user