[hal] Add SimValue reset() function (#3064)

This enables correct behavior for resetting incremental sensor values like
encoder counts or gyro accumulated angle with WebSockets.
This commit is contained in:
Peter Johnson
2021-01-12 00:38:58 -08:00
committed by GitHub
parent 9c3b51ca0f
commit bc80c55353
20 changed files with 324 additions and 11 deletions

View File

@@ -352,4 +352,13 @@ public class SimDeviceJNI extends JNIWrapper {
public static void setSimValueBoolean(int handle, boolean value) {
setSimValueNative(handle, HALValue.kBoolean, value ? 1 : 0, 0.0);
}
/**
* Resets a simulated double or integral value to 0. Has no effect on other value types. Use this
* instead of Set(0) for resetting incremental sensor values like encoder counts or gyro
* accumulated angle to ensure correct behavior in a distributed system (e.g. WebSockets).
*
* @param handle simulated value handle
*/
public static native void resetSimValue(int handle);
}

View File

@@ -32,4 +32,13 @@ public class SimDouble extends SimValue {
public void set(double value) {
SimDeviceJNI.setSimValueDouble(m_handle, value);
}
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting incremental sensor
* values like encoder counts or gyro accumulated angle to ensure correct behavior in a
* distributed system (e.g. WebSockets).
*/
public void reset() {
SimDeviceJNI.resetSimValue(m_handle);
}
}

View File

@@ -32,4 +32,13 @@ public class SimInt extends SimValue {
public void set(int value) {
SimDeviceJNI.setSimValueInt(m_handle, value);
}
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting incremental sensor
* values like encoder counts or gyro accumulated angle to ensure correct behavior in a
* distributed system (e.g. WebSockets).
*/
public void reset() {
SimDeviceJNI.resetSimValue(m_handle);
}
}

View File

@@ -32,4 +32,13 @@ public class SimLong extends SimValue {
public void set(long value) {
SimDeviceJNI.setSimValueLong(m_handle, value);
}
/**
* Resets the simulated value to 0. Use this instead of Set(0) for resetting incremental sensor
* values like encoder counts or gyro accumulated angle to ensure correct behavior in a
* distributed system (e.g. WebSockets).
*/
public void reset() {
SimDeviceJNI.resetSimValue(m_handle);
}
}

View File

@@ -60,6 +60,19 @@ public class SimDeviceDataJNI extends JNIWrapper {
public static native void cancelSimValueChangedCallback(int uid);
/**
* Register a callback for SimDeviceJNI.resetSimValue(). The callback is called with the old
* value.
*
* @param handle simulated value handle
* @param callback callback
* @param initialNotify ignored (present for consistency)
*/
public static native int registerSimValueResetCallback(
int handle, SimValueCallback2 callback, boolean initialNotify);
public static native void cancelSimValueResetCallback(int uid);
public static native int getSimValueHandle(int device, String name);
public static class SimValueInfo {