2017-08-18 21:35:53 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 22:11:24 -07:00
|
|
|
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
2017-08-18 21:35:53 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
#include <wpi/spinlock.h>
|
2017-11-13 09:51:48 -08:00
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include "hal/simulation/DriverStationData.h"
|
2020-08-03 22:38:48 -07:00
|
|
|
#include "hal/simulation/SimCallbackRegistry.h"
|
2020-06-27 22:11:24 -07:00
|
|
|
#include "hal/simulation/SimDataValue.h"
|
2017-08-18 21:35:53 -07:00
|
|
|
|
|
|
|
|
namespace hal {
|
2017-11-12 19:33:43 -08:00
|
|
|
|
2017-08-18 21:35:53 -07:00
|
|
|
class DriverStationData {
|
2018-09-03 16:08:07 -07:00
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(Enabled)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(Autonomous)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(Test)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(EStop)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(FmsAttached)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(DsAttached)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(AllianceStationId)
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_NAME(MatchTime)
|
2020-08-03 22:38:48 -07:00
|
|
|
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)
|
2020-08-14 22:14:07 -07:00
|
|
|
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(NewData)
|
2018-09-03 16:08:07 -07:00
|
|
|
|
|
|
|
|
static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value
|
|
|
|
|
MakeAllianceStationIdValue(HAL_AllianceStationID value) {
|
2019-09-23 23:28:49 -07:00
|
|
|
return HAL_MakeEnum(value);
|
2018-09-03 16:08:07 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-18 21:35:53 -07:00
|
|
|
public:
|
2017-11-12 19:33:43 -08:00
|
|
|
DriverStationData();
|
2017-08-18 21:35:53 -07:00
|
|
|
void ResetData();
|
|
|
|
|
|
2020-08-03 22:38:48 -07:00
|
|
|
int32_t RegisterJoystickAxesCallback(int32_t joystickNum,
|
|
|
|
|
HAL_JoystickAxesCallback callback,
|
|
|
|
|
void* param, HAL_Bool initialNotify);
|
|
|
|
|
void CancelJoystickAxesCallback(int32_t uid);
|
2017-11-12 19:33:43 -08:00
|
|
|
void GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
|
|
|
|
|
void SetJoystickAxes(int32_t joystickNum, const HAL_JoystickAxes* axes);
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
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);
|
2017-11-12 19:33:43 -08:00
|
|
|
void SetJoystickPOVs(int32_t joystickNum, const HAL_JoystickPOVs* povs);
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
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);
|
2017-11-12 19:33:43 -08:00
|
|
|
void SetJoystickButtons(int32_t joystickNum,
|
|
|
|
|
const HAL_JoystickButtons* buttons);
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
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);
|
2017-11-12 19:33:43 -08:00
|
|
|
void SetJoystickDescriptor(int32_t joystickNum,
|
|
|
|
|
const HAL_JoystickDescriptor* descriptor);
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
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);
|
2017-11-12 19:33:43 -08:00
|
|
|
void SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
|
|
|
|
int32_t leftRumble, int32_t rightRumble);
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
int32_t RegisterMatchInfoCallback(HAL_MatchInfoCallback callback, void* param,
|
|
|
|
|
HAL_Bool initialNotify);
|
|
|
|
|
void CancelMatchInfoCallback(int32_t uid);
|
|
|
|
|
void GetMatchInfo(HAL_MatchInfo* info);
|
2017-11-12 19:33:43 -08:00
|
|
|
void SetMatchInfo(const HAL_MatchInfo* info);
|
|
|
|
|
|
2020-08-03 22:38:48 -07:00
|
|
|
void FreeMatchInfo(const HAL_MatchInfo* info);
|
|
|
|
|
|
2020-08-14 22:14:07 -07:00
|
|
|
int32_t RegisterNewDataCallback(HAL_NotifyCallback callback, void* param,
|
|
|
|
|
HAL_Bool initialNotify);
|
|
|
|
|
void CancelNewDataCallback(int32_t uid);
|
|
|
|
|
void CallNewDataCallbacks();
|
|
|
|
|
|
2017-08-18 21:35:53 -07:00
|
|
|
void NotifyNewData();
|
|
|
|
|
|
2020-07-15 00:33:57 -07:00
|
|
|
void SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state);
|
|
|
|
|
void SetJoystickAxis(int32_t stick, int32_t axis, double value);
|
|
|
|
|
void SetJoystickPOV(int32_t stick, int32_t pov, int32_t value);
|
|
|
|
|
void SetJoystickButtons(int32_t stick, uint32_t buttons);
|
|
|
|
|
void SetJoystickAxisCount(int32_t stick, int32_t count);
|
|
|
|
|
void SetJoystickPOVCount(int32_t stick, int32_t count);
|
|
|
|
|
void SetJoystickButtonCount(int32_t stick, int32_t count);
|
2020-08-23 23:17:03 -07:00
|
|
|
void GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
|
|
|
|
int32_t* buttonCount, int32_t* povCount);
|
2020-07-15 00:33:57 -07:00
|
|
|
|
|
|
|
|
void SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
|
|
|
|
|
void SetJoystickType(int32_t stick, int32_t type);
|
|
|
|
|
void SetJoystickName(int32_t stick, const char* name);
|
|
|
|
|
void SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
|
|
|
|
|
|
|
|
|
void SetGameSpecificMessage(const char* message);
|
|
|
|
|
void SetEventName(const char* name);
|
|
|
|
|
void SetMatchType(HAL_MatchType type);
|
|
|
|
|
void SetMatchNumber(int32_t matchNumber);
|
|
|
|
|
void SetReplayNumber(int32_t replayNumber);
|
|
|
|
|
|
2019-09-23 23:28:49 -07:00
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetEnabledName> enabled{false};
|
|
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetAutonomousName> autonomous{false};
|
|
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetTestName> test{false};
|
|
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetEStopName> eStop{false};
|
|
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFmsAttachedName> fmsAttached{
|
|
|
|
|
false};
|
|
|
|
|
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetDsAttachedName> dsAttached{true};
|
2018-09-03 16:08:07 -07:00
|
|
|
SimDataValue<HAL_AllianceStationID, MakeAllianceStationIdValue,
|
|
|
|
|
GetAllianceStationIdName>
|
|
|
|
|
allianceStationId{static_cast<HAL_AllianceStationID>(0)};
|
2019-09-23 23:28:49 -07:00
|
|
|
SimDataValue<double, HAL_MakeDouble, GetMatchTimeName> matchTime{0.0};
|
2017-11-12 19:33:43 -08:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
private:
|
2020-08-03 22:38:48 -07:00
|
|
|
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;
|
2020-08-14 22:14:07 -07:00
|
|
|
SimCallbackRegistry<HAL_NotifyCallback, GetNewDataName> m_newDataCallbacks;
|
2020-08-03 22:38:48 -07:00
|
|
|
|
|
|
|
|
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;
|
2018-09-03 16:08:07 -07:00
|
|
|
wpi::spinlock m_joystickDataMutex;
|
2020-08-03 22:38:48 -07:00
|
|
|
JoystickData m_joystickData[kNumJoysticks];
|
2017-11-12 19:33:43 -08:00
|
|
|
|
2020-08-03 22:38:48 -07:00
|
|
|
wpi::spinlock m_matchInfoMutex;
|
|
|
|
|
HAL_MatchInfo m_matchInfo;
|
2017-08-18 21:35:53 -07:00
|
|
|
};
|
2017-12-10 19:38:53 -08:00
|
|
|
extern DriverStationData* SimDriverStationData;
|
2017-08-18 21:35:53 -07:00
|
|
|
} // namespace hal
|