mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
This makes callback registration completely thread safe. This patch also uses templates and macros to dramatically reduce the amount of manual boilerplate.
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
|
/* 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. */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
#include "../PortsInternal.h"
|
|
#include "AnalogOutDataInternal.h"
|
|
|
|
using namespace hal;
|
|
|
|
namespace hal {
|
|
namespace init {
|
|
void InitializeAnalogOutData() {
|
|
static AnalogOutData siod[kNumAnalogOutputs];
|
|
::hal::SimAnalogOutData = siod;
|
|
}
|
|
} // namespace init
|
|
} // namespace hal
|
|
|
|
AnalogOutData* hal::SimAnalogOutData;
|
|
void AnalogOutData::ResetData() {
|
|
voltage.Reset(0.0);
|
|
initialized.Reset(0);
|
|
}
|
|
|
|
extern "C" {
|
|
void HALSIM_ResetAnalogOutData(int32_t index) {
|
|
SimAnalogOutData[index].ResetData();
|
|
}
|
|
|
|
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
|
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogOut##CAPINAME, \
|
|
SimAnalogOutData, LOWERNAME)
|
|
|
|
DEFINE_CAPI(double, Voltage, voltage)
|
|
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
|
|
|
#define REGISTER(NAME) \
|
|
SimAnalogOutData[index].NAME.RegisterCallback(callback, param, initialNotify)
|
|
|
|
void HALSIM_RegisterAnalogOutAllCallbacks(int32_t index,
|
|
HAL_NotifyCallback callback,
|
|
void* param, HAL_Bool initialNotify) {
|
|
REGISTER(voltage);
|
|
REGISTER(initialized);
|
|
}
|
|
} // extern "C"
|