Add ability to associate other devices with a SimDevice

Implemented only for AnalogInput, DIO, and Encoder.
This commit is contained in:
Peter Johnson
2019-10-04 22:56:24 -07:00
parent 81c2c8a7de
commit aa90645865
36 changed files with 222 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -46,6 +46,8 @@ public class AnalogJNI extends JNIWrapper {
public static native boolean checkAnalogOutputChannel(int channel);
public static native void setAnalogInputSimDevice(int handle, int device);
public static native void setAnalogOutput(int portHandle, double voltage);
public static native double getAnalogOutput(int portHandle);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -15,6 +15,8 @@ public class DIOJNI extends JNIWrapper {
public static native void freeDIOPort(int dioPortHandle);
public static native void setDIOSimDevice(int handle, int device);
// TODO(Thad): Switch this to use boolean
public static native void setDIO(int dioPortHandle, short value);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -14,6 +14,8 @@ public class EncoderJNI extends JNIWrapper {
public static native void freeEncoder(int encoderHandle);
public static native void setEncoderSimDevice(int handle, int device);
public static native int getEncoder(int encoderHandle);
public static native int getEncoderRaw(int encoderHandle);

View File

@@ -75,6 +75,9 @@ HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) {
return channel < kNumAnalogInputs && channel >= 0;
}
void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle,
HAL_SimDeviceHandle device) {}
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need double comparison with epsilon.

View File

@@ -160,6 +160,9 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
}
}
void HAL_SetDIOSimDevice(HAL_DigitalHandle handle, HAL_SimDeviceHandle device) {
}
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
auto handle = digitalPWMHandles->Allocate();
if (handle == HAL_kInvalidHandle) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -261,6 +261,9 @@ void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
encoderHandles->Free(encoderHandle);
}
void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle,
HAL_SimDeviceHandle device) {}
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles->Get(encoderHandle);
if (encoder == nullptr) {

View File

@@ -118,6 +118,19 @@ Java_edu_wpi_first_hal_AnalogJNI_checkAnalogOutputChannel
return returnValue;
}
/*
* Class: edu_wpi_first_hal_AnalogJNI
* Method: setAnalogInputSimDevice
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_AnalogJNI_setAnalogInputSimDevice
(JNIEnv* env, jclass, jint handle, jint device)
{
HAL_SetAnalogInputSimDevice((HAL_AnalogInputHandle)handle,
(HAL_SimDeviceHandle)device);
}
/*
* Class: edu_wpi_first_hal_AnalogJNI
* Method: setAnalogOutput

View File

@@ -61,6 +61,18 @@ Java_edu_wpi_first_hal_DIOJNI_freeDIOPort
HAL_FreeDIOPort((HAL_DigitalHandle)id);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: setDIOSimDevice
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDIOSimDevice
(JNIEnv* env, jclass, jint handle, jint device)
{
HAL_SetDIOSimDevice((HAL_DigitalHandle)handle, (HAL_SimDeviceHandle)device);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: setDIO

View File

@@ -54,6 +54,19 @@ Java_edu_wpi_first_hal_EncoderJNI_freeEncoder
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_EncoderJNI
* Method: setEncoderSimDevice
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_EncoderJNI_setEncoderSimDevice
(JNIEnv* env, jclass, jint handle, jint device)
{
HAL_SetEncoderSimDevice((HAL_EncoderHandle)handle,
(HAL_SimDeviceHandle)device);
}
/*
* Class: edu_wpi_first_hal_EncoderJNI
* Method: getEncoder

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -55,6 +55,15 @@ HAL_Bool HAL_CheckAnalogModule(int32_t module);
*/
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel);
/**
* Indicates the analog input is used by a simulated device.
*
* @param handle the analog input handle
* @param device simulated device handle
*/
void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle,
HAL_SimDeviceHandle device);
/**
* Sets the sample rate.
*

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -41,6 +41,14 @@ HAL_Bool HAL_CheckDIOChannel(int32_t channel);
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle);
/**
* Indicates the DIO channel is used by a simulated device.
*
* @param handle the DIO channel handle
* @param device simulated device handle
*/
void HAL_SetDIOSimDevice(HAL_DigitalHandle handle, HAL_SimDeviceHandle device);
/**
* Allocates a DO PWM Generator.
*

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-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. */
@@ -72,6 +72,15 @@ HAL_EncoderHandle HAL_InitializeEncoder(
*/
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
/**
* Indicates the encoder is used by a simulated device.
*
* @param handle the encoder handle
* @param device simulated device handle
*/
void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle,
HAL_SimDeviceHandle device);
/**
* Gets the current counts of the encoder after encoding type scaling.
*

View File

@@ -23,6 +23,8 @@ void HALSIM_CancelAnalogInInitializedCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetAnalogInInitialized(int32_t index);
void HALSIM_SetAnalogInInitialized(int32_t index, HAL_Bool initialized);
HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index);
int32_t HALSIM_RegisterAnalogInAverageBitsCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,

View File

@@ -23,6 +23,8 @@ void HALSIM_CancelDIOInitializedCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetDIOInitialized(int32_t index);
void HALSIM_SetDIOInitialized(int32_t index, HAL_Bool initialized);
HAL_SimDeviceHandle HALSIM_GetDIOSimDevice(int32_t index);
int32_t HALSIM_RegisterDIOValueCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);

View File

@@ -24,6 +24,8 @@ void HALSIM_CancelEncoderInitializedCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetEncoderInitialized(int32_t index);
void HALSIM_SetEncoderInitialized(int32_t index, HAL_Bool initialized);
HAL_SimDeviceHandle HALSIM_GetEncoderSimDevice(int32_t index);
int32_t HALSIM_RegisterEncoderCountCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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:

View File

@@ -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)

View File

@@ -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};

View File

@@ -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)

View File

@@ -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};

View File

@@ -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)

View File

@@ -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)()};

View File

@@ -224,6 +224,10 @@ double AnalogInput::PIDGet() {
return GetAverageVoltage();
}
void AnalogInput::SetSimDevice(HAL_SimDeviceHandle device) {
HAL_SetAnalogInputSimDevice(m_port, device);
}
void AnalogInput::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Analog Input");
builder.AddDoubleProperty("Value", [=]() { return GetAverageVoltage(); },

View File

@@ -65,6 +65,10 @@ AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const {
bool DigitalInput::IsAnalogTrigger() const { return false; }
void DigitalInput::SetSimDevice(HAL_SimDeviceHandle device) {
HAL_SetDIOSimDevice(m_handle, device);
}
int DigitalInput::GetChannel() const { return m_channel; }
void DigitalInput::InitSendable(SendableBuilder& builder) {

View File

@@ -140,6 +140,10 @@ void DigitalOutput::UpdateDutyCycle(double dutyCycle) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
void DigitalOutput::SetSimDevice(HAL_SimDeviceHandle device) {
HAL_SetDIOSimDevice(m_handle, device);
}
void DigitalOutput::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Digital Output");
builder.AddBooleanProperty("Value", [=]() { return Get(); },

View File

@@ -217,6 +217,10 @@ void Encoder::SetIndexSource(const DigitalSource& source,
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
void Encoder::SetSimDevice(HAL_SimDeviceHandle device) {
HAL_SetEncoderSimDevice(m_encoder, device);
}
int Encoder::GetFPGAIndex() const {
int32_t status = 0;
int val = HAL_GetEncoderFPGAIndex(m_encoder, &status);

View File

@@ -286,6 +286,13 @@ class AnalogInput : public ErrorBase,
*/
double PIDGet() override;
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
void SetSimDevice(HAL_SimDeviceHandle device);
void InitSendable(SendableBuilder& builder) override;
private:

View File

@@ -71,6 +71,13 @@ class DigitalInput : public DigitalSource,
*/
int GetChannel() const override;
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
void SetSimDevice(HAL_SimDeviceHandle device);
void InitSendable(SendableBuilder& builder) override;
private:

View File

@@ -125,6 +125,13 @@ class DigitalOutput : public ErrorBase,
*/
void UpdateDutyCycle(double dutyCycle);
/**
* Indicates this output is used by a simulated device.
*
* @param device simulated device handle
*/
void SetSimDevice(HAL_SimDeviceHandle device);
void InitSendable(SendableBuilder& builder) override;
private:

View File

@@ -332,6 +332,13 @@ class Encoder : public ErrorBase,
void SetIndexSource(const DigitalSource& source,
IndexingType type = kResetOnRisingEdge);
/**
* Indicates this encoder is used by a simulated device.
*
* @param device simulated device handle
*/
void SetSimDevice(HAL_SimDeviceHandle device);
int GetFPGAIndex() const;
void InitSendable(SendableBuilder& builder) override;

View File

@@ -11,6 +11,7 @@ import edu.wpi.first.hal.AccumulatorResult;
import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.sim.AnalogInSim;
import edu.wpi.first.hal.util.AllocationException;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
@@ -344,6 +345,15 @@ public class AnalogInput implements PIDSource, Sendable, AutoCloseable {
return getAverageVoltage();
}
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
public void setSimDevice(SimDevice device) {
AnalogJNI.setAnalogInputSimDevice(m_port, device.getNativeHandle());
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Analog Input");

View File

@@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
@@ -98,6 +99,15 @@ public class DigitalInput extends DigitalSource implements Sendable, AutoCloseab
return m_handle;
}
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
public void setSimDevice(SimDevice device) {
DIOJNI.setDIOSimDevice(m_handle, device.getNativeHandle());
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Digital Input");

View File

@@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
@@ -161,6 +162,15 @@ public class DigitalOutput implements Sendable, AutoCloseable {
DIOJNI.setDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle);
}
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
public void setSimDevice(SimDevice device) {
DIOJNI.setDIOSimDevice(m_handle, device.getNativeHandle());
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Digital Output");

View File

@@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.EncoderJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.util.AllocationException;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
@@ -560,6 +561,15 @@ public class Encoder implements CounterBase, PIDSource, Sendable, AutoCloseable
source.getAnalogTriggerTypeForRouting(), type.value);
}
/**
* Indicates this input is used by a simulated device.
*
* @param device simulated device handle
*/
public void setSimDevice(SimDevice device) {
EncoderJNI.setEncoderSimDevice(m_encoder, device.getNativeHandle());
}
@Override
public void initSendable(SendableBuilder builder) {
if (EncoderJNI.getEncoderEncodingType(m_encoder) == EncodingType.k4X.value) {