[hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066)

This commit is contained in:
Peter Johnson
2021-01-09 23:26:19 -08:00
committed by GitHub
parent e620bd4d3f
commit fb99910c23
5 changed files with 274 additions and 0 deletions

View File

@@ -81,6 +81,36 @@ public class SimDeviceJNI extends JNIWrapper {
initialValue.getNativeDouble());
}
/**
* Creates an int value on a simulated device.
*
* <p>Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.
*
* @param device simulated device handle
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated value handle
*/
public static int createSimValueInt(int device, String name, int direction, int initialValue) {
return createSimValueNative(device, name, direction, HALValue.kInt, initialValue, 0.0);
}
/**
* Creates a long value on a simulated device.
*
* <p>Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.
*
* @param device simulated device handle
* @param name value name
* @param direction input/output/bidir (from perspective of user code)
* @param initialValue initial value
* @return simulated value handle
*/
public static int createSimValueLong(int device, String name, int direction, long initialValue) {
return createSimValueNative(device, name, direction, HALValue.kLong, initialValue, 0.0);
}
/**
* Creates a double value on a simulated device.
*
@@ -221,6 +251,22 @@ public class SimDeviceJNI extends JNIWrapper {
*/
public static native HALValue getSimValue(int handle);
/**
* Gets a simulated value (int).
*
* @param handle simulated value handle
* @return The current value
*/
public static native int getSimValueInt(int handle);
/**
* Gets a simulated value (long).
*
* @param handle simulated value handle
* @return The current value
*/
public static native long getSimValueLong(int handle);
/**
* Gets a simulated value (double).
*
@@ -257,6 +303,26 @@ public class SimDeviceJNI extends JNIWrapper {
setSimValueNative(handle, value.getType(), value.getNativeLong(), value.getNativeDouble());
}
/**
* Sets a simulated value (int).
*
* @param handle simulated value handle
* @param value the value to set
*/
public static void setSimValueInt(int handle, int value) {
setSimValueNative(handle, HALValue.kInt, value, 0.0);
}
/**
* Sets a simulated value (long).
*
* @param handle simulated value handle
* @param value the value to set
*/
public static void setSimValueLong(int handle, long value) {
setSimValueNative(handle, HALValue.kLong, value, 0.0);
}
/**
* Sets a simulated value (double).
*

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.hal;
/** A wrapper around a simulator int value handle. */
public class SimInt extends SimValue {
/**
* Wraps a simulated value handle as returned by SimDeviceJNI.createSimValueInt().
*
* @param handle simulated value handle
*/
public SimInt(int handle) {
super(handle);
}
/**
* Gets the simulated value.
*
* @return The current value
*/
public int get() {
return SimDeviceJNI.getSimValueInt(m_handle);
}
/**
* Sets the simulated value.
*
* @param value the value to set
*/
public void set(int value) {
SimDeviceJNI.setSimValueInt(m_handle, value);
}
}

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.hal;
/** A wrapper around a simulator long value handle. */
public class SimLong extends SimValue {
/**
* Wraps a simulated value handle as returned by SimDeviceJNI.createSimValueLong().
*
* @param handle simulated value handle
*/
public SimLong(int handle) {
super(handle);
}
/**
* Gets the simulated value.
*
* @return The current value
*/
public long get() {
return SimDeviceJNI.getSimValueLong(m_handle);
}
/**
* Sets the simulated value.
*
* @param value the value to set
*/
public void set(long value) {
SimDeviceJNI.setSimValueLong(m_handle, value);
}
}