mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[sim] Add callback for NotifyNewData
This commit is contained in:
@@ -71,6 +71,14 @@ void HALSIM_GetMatchInfo(HAL_MatchInfo* info) {}
|
||||
|
||||
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {}
|
||||
|
||||
int32_t HALSIM_RegisterDriverStationNewDataCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HALSIM_CancelDriverStationNewDataCallback(int32_t uid) {}
|
||||
|
||||
void HALSIM_NotifyDriverStationNewData(void) {}
|
||||
|
||||
void HALSIM_SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state) {}
|
||||
|
||||
@@ -159,6 +159,10 @@ void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
|
||||
int32_t HALSIM_RegisterDriverStationNewDataCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDriverStationNewDataCallback(int32_t uid);
|
||||
void HALSIM_NotifyDriverStationNewData(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -274,6 +274,7 @@ static int32_t newDataOccur(uint32_t refNum) {
|
||||
// Since we could get other values, require our specific handle
|
||||
// to signal our threads
|
||||
if (refNum != refNumber) return 0;
|
||||
SimDriverStationData->CallNewDataCallbacks();
|
||||
std::scoped_lock lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
|
||||
@@ -58,6 +58,7 @@ void DriverStationData::ResetData() {
|
||||
m_matchInfoCallbacks.Reset();
|
||||
m_matchInfo = HAL_MatchInfo{};
|
||||
}
|
||||
m_newDataCallbacks.Reset();
|
||||
}
|
||||
|
||||
#define DEFINE_CPPAPI_CALLBACKS(name, data, data2) \
|
||||
@@ -186,6 +187,28 @@ void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
|
||||
m_matchInfoCallbacks(info);
|
||||
}
|
||||
|
||||
int32_t DriverStationData::RegisterNewDataCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
int32_t uid = m_newDataCallbacks.Register(callback, param);
|
||||
if (initialNotify) {
|
||||
HAL_Value empty;
|
||||
empty.type = HAL_UNASSIGNED;
|
||||
callback(GetNewDataName(), param, &empty);
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
void DriverStationData::CancelNewDataCallback(int32_t uid) {
|
||||
m_newDataCallbacks.Cancel(uid);
|
||||
}
|
||||
|
||||
void DriverStationData::CallNewDataCallbacks() {
|
||||
HAL_Value empty;
|
||||
empty.type = HAL_UNASSIGNED;
|
||||
m_newDataCallbacks(&empty);
|
||||
}
|
||||
|
||||
void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
|
||||
|
||||
void DriverStationData::SetJoystickButton(int32_t stick, int32_t button,
|
||||
@@ -401,6 +424,17 @@ void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {
|
||||
SimDriverStationData->SetMatchInfo(info);
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterDriverStationNewDataCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimDriverStationData->RegisterNewDataCallback(callback, param,
|
||||
initialNotify);
|
||||
}
|
||||
|
||||
void HALSIM_CancelDriverStationNewDataCallback(int32_t uid) {
|
||||
SimDriverStationData->CancelNewDataCallback(uid);
|
||||
}
|
||||
|
||||
void HALSIM_NotifyDriverStationNewData(void) {
|
||||
SimDriverStationData->NotifyNewData();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class DriverStationData {
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickDescriptor)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickOutputs)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(MatchInfo)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(NewData)
|
||||
|
||||
static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value
|
||||
MakeAllianceStationIdValue(HAL_AllianceStationID value) {
|
||||
@@ -90,6 +91,11 @@ class DriverStationData {
|
||||
|
||||
void FreeMatchInfo(const HAL_MatchInfo* info);
|
||||
|
||||
int32_t RegisterNewDataCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void CancelNewDataCallback(int32_t uid);
|
||||
void CallNewDataCallbacks();
|
||||
|
||||
void NotifyNewData();
|
||||
|
||||
void SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state);
|
||||
@@ -136,6 +142,7 @@ class DriverStationData {
|
||||
m_joystickDescriptorCallbacks;
|
||||
SimCallbackRegistry<HAL_MatchInfoCallback, GetMatchInfoName>
|
||||
m_matchInfoCallbacks;
|
||||
SimCallbackRegistry<HAL_NotifyCallback, GetNewDataName> m_newDataCallbacks;
|
||||
|
||||
struct JoystickOutputStore {
|
||||
int64_t outputs = 0;
|
||||
|
||||
Reference in New Issue
Block a user