mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[sim] Add callback for NotifyNewData
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user