mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066)
This commit is contained in:
@@ -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).
|
||||
*
|
||||
|
||||
35
hal/src/main/java/edu/wpi/first/hal/SimInt.java
Normal file
35
hal/src/main/java/edu/wpi/first/hal/SimInt.java
Normal 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);
|
||||
}
|
||||
}
|
||||
35
hal/src/main/java/edu/wpi/first/hal/SimLong.java
Normal file
35
hal/src/main/java/edu/wpi/first/hal/SimLong.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user