mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Add ability to associate other devices with a SimDevice
Implemented only for AnalogInput, DIO, and Encoder.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -53,6 +53,7 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
|
||||
|
||||
SimAnalogInData[channel].initialized = true;
|
||||
SimAnalogInData[channel].accumulatorInitialized = false;
|
||||
SimAnalogInData[channel].simDevice = 0;
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -71,6 +72,13 @@ HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) {
|
||||
return channel < kNumAnalogInputs && channel >= 0;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle,
|
||||
HAL_SimDeviceHandle device) {
|
||||
auto port = analogInputHandles->Get(handle);
|
||||
if (port == nullptr) return;
|
||||
SimAnalogInData[port->channel].simDevice = device;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
|
||||
// No op
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
port->channel = static_cast<uint8_t>(channel);
|
||||
|
||||
SimDIOData[channel].initialized = true;
|
||||
|
||||
SimDIOData[channel].isInput = input;
|
||||
SimDIOData[channel].simDevice = 0;
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -81,6 +81,12 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
||||
SimDIOData[port->channel].initialized = false;
|
||||
}
|
||||
|
||||
void HAL_SetDIOSimDevice(HAL_DigitalHandle handle, HAL_SimDeviceHandle device) {
|
||||
auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) return;
|
||||
SimDIOData[port->channel].simDevice = device;
|
||||
}
|
||||
|
||||
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
|
||||
auto handle = digitalPWMHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -84,6 +84,7 @@ HAL_EncoderHandle HAL_InitializeEncoder(
|
||||
SimEncoderData[index].digitalChannelA = getHandleIndex(digitalSourceHandleA);
|
||||
SimEncoderData[index].initialized = true;
|
||||
SimEncoderData[index].reverseDirection = reverseDirection;
|
||||
SimEncoderData[index].simDevice = 0;
|
||||
// TODO: Add encoding type to Sim data
|
||||
encoder->index = index;
|
||||
encoder->nativeHandle = nativeHandle;
|
||||
@@ -104,6 +105,13 @@ void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||
SimEncoderData[encoder->index].initialized = false;
|
||||
}
|
||||
|
||||
void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle,
|
||||
HAL_SimDeviceHandle device) {
|
||||
auto encoder = encoderHandles->Get(handle);
|
||||
if (encoder == nullptr) return;
|
||||
SimEncoderData[encoder->index].simDevice = device;
|
||||
}
|
||||
|
||||
static inline int EncodingScaleFactor(Encoder* encoder) {
|
||||
switch (encoder->encodingType) {
|
||||
case HAL_Encoder_k1X:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -22,6 +22,7 @@ void InitializeAnalogInData() {
|
||||
AnalogInData* hal::SimAnalogInData;
|
||||
void AnalogInData::ResetData() {
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
averageBits.Reset(7);
|
||||
oversampleBits.Reset(0);
|
||||
voltage.Reset(0.0);
|
||||
@@ -37,6 +38,10 @@ void HALSIM_ResetAnalogInData(int32_t index) {
|
||||
SimAnalogInData[index].ResetData();
|
||||
}
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index) {
|
||||
return SimAnalogInData[index].simDevice;
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogIn##CAPINAME, \
|
||||
SimAnalogInData, LOWERNAME)
|
||||
|
||||
@@ -25,6 +25,7 @@ class AnalogInData {
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
|
||||
false};
|
||||
std::atomic<HAL_SimDeviceHandle> simDevice;
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetAverageBitsName> averageBits{7};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetOversampleBitsName> oversampleBits{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVoltageName> voltage{0.0};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -22,6 +22,7 @@ void InitializeDIOData() {
|
||||
DIOData* hal::SimDIOData;
|
||||
void DIOData::ResetData() {
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
value.Reset(true);
|
||||
pulseLength.Reset(0.0);
|
||||
isInput.Reset(true);
|
||||
@@ -31,6 +32,10 @@ void DIOData::ResetData() {
|
||||
extern "C" {
|
||||
void HALSIM_ResetDIOData(int32_t index) { SimDIOData[index].ResetData(); }
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetDIOSimDevice(int32_t index) {
|
||||
return SimDIOData[index].simDevice;
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, DIO##CAPINAME, SimDIOData, \
|
||||
LOWERNAME)
|
||||
|
||||
@@ -21,6 +21,7 @@ class DIOData {
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
|
||||
false};
|
||||
std::atomic<HAL_SimDeviceHandle> simDevice;
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetValueName> value{true};
|
||||
SimDataValue<double, HAL_MakeDouble, GetPulseLengthName> pulseLength{0.0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetIsInputName> isInput{true};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -23,6 +23,7 @@ EncoderData* hal::SimEncoderData;
|
||||
void EncoderData::ResetData() {
|
||||
digitalChannelA = 0;
|
||||
initialized.Reset(false);
|
||||
simDevice = 0;
|
||||
count.Reset(0);
|
||||
period.Reset(std::numeric_limits<double>::max());
|
||||
reset.Reset(false);
|
||||
@@ -42,6 +43,10 @@ int16_t HALSIM_GetDigitalChannelA(int32_t index) {
|
||||
return SimEncoderData[index].digitalChannelA;
|
||||
}
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetEncoderSimDevice(int32_t index) {
|
||||
return SimEncoderData[index].simDevice;
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Encoder##CAPINAME, \
|
||||
SimEncoderData, LOWERNAME)
|
||||
|
||||
@@ -29,6 +29,7 @@ class EncoderData {
|
||||
std::atomic<int16_t> digitalChannelA{0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
|
||||
false};
|
||||
std::atomic<HAL_SimDeviceHandle> simDevice;
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetCountName> count{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetPeriodName> period{
|
||||
(std::numeric_limits<double>::max)()};
|
||||
|
||||
Reference in New Issue
Block a user