mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Rename SimDevice constants to all caps
Also use enum class for SimDevice C++ wrapper.
This commit is contained in:
@@ -19,11 +19,11 @@ public class SimDevice implements AutoCloseable {
|
||||
/** Sim device direction. */
|
||||
public enum Direction {
|
||||
/** Input direction for simulation devices. */
|
||||
kInput(SimDeviceJNI.kInput),
|
||||
INPUT(SimDeviceJNI.VALUE_INPUT),
|
||||
/** Output direction for simulation devices. */
|
||||
kOutput(SimDeviceJNI.kOutput),
|
||||
OUTPUT(SimDeviceJNI.VALUE_OUTPUT),
|
||||
/** Bidirectional direction for simulation devices. */
|
||||
kBidir(SimDeviceJNI.kBidir);
|
||||
BIDIR(SimDeviceJNI.VALUE_BIDIR);
|
||||
|
||||
/** The native value of this Direction. */
|
||||
public final int m_value;
|
||||
|
||||
@@ -11,13 +11,13 @@ package org.wpilib.hardware.hal;
|
||||
*/
|
||||
public class SimDeviceJNI extends JNIWrapper {
|
||||
/** Input to user code from the simulator. */
|
||||
public static final int kInput = 0;
|
||||
public static final int VALUE_INPUT = 0;
|
||||
|
||||
/** Output from user code to the simulator. */
|
||||
public static final int kOutput = 1;
|
||||
public static final int VALUE_OUTPUT = 1;
|
||||
|
||||
/** Bidirectional between user code and simulator. */
|
||||
public static final int kBidir = 2;
|
||||
public static final int VALUE_BIDIR = 2;
|
||||
|
||||
/**
|
||||
* Creates a simulated device.
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
* Direction of a simulated value (from the perspective of user code).
|
||||
*/
|
||||
HAL_ENUM(HAL_SimValueDirection) {
|
||||
HAL_SimValueInput = 0, /**< input to user code from the simulator */
|
||||
HAL_SimValueOutput, /**< output from user code to the simulator */
|
||||
HAL_SimValueBidir /**< bidirectional between user code and simulator */
|
||||
HAL_SIM_VALUE_INPUT = 0, /**< input to user code from the simulator */
|
||||
HAL_SIM_VALUE_OUTPUT, /**< output from user code to the simulator */
|
||||
HAL_SIM_VALUE_BIDIR /**< bidirectional between user code and simulator */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -280,10 +280,10 @@ class SimDevice {
|
||||
/**
|
||||
* Direction of a simulated value (from the perspective of user code).
|
||||
*/
|
||||
enum Direction {
|
||||
kInput = HAL_SimValueInput,
|
||||
kOutput = HAL_SimValueOutput,
|
||||
kBidir = HAL_SimValueBidir
|
||||
enum class Direction {
|
||||
INPUT = HAL_SIM_VALUE_INPUT,
|
||||
OUTPUT = HAL_SIM_VALUE_OUTPUT,
|
||||
BIDIR = HAL_SIM_VALUE_BIDIR
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -403,9 +403,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated value object
|
||||
*/
|
||||
SimValue CreateValue(const char* name, int32_t direction,
|
||||
SimValue CreateValue(const char* name, Direction direction,
|
||||
const HAL_Value& initialValue) {
|
||||
return HAL_CreateSimValue(m_handle, name, direction, &initialValue);
|
||||
return HAL_CreateSimValue(m_handle, name, static_cast<int32_t>(direction),
|
||||
&initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,8 +420,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimInt CreateInt(const char* name, int32_t direction, int32_t initialValue) {
|
||||
return HAL_CreateSimValueInt(m_handle, name, direction, initialValue);
|
||||
SimInt CreateInt(const char* name, Direction direction,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueInt(m_handle, name,
|
||||
static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,9 +437,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimLong CreateLong(const char* name, int32_t direction,
|
||||
SimLong CreateLong(const char* name, Direction direction,
|
||||
int64_t initialValue) {
|
||||
return HAL_CreateSimValueLong(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueLong(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,9 +454,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated double value object
|
||||
*/
|
||||
SimDouble CreateDouble(const char* name, int32_t direction,
|
||||
SimDouble CreateDouble(const char* name, Direction direction,
|
||||
double initialValue) {
|
||||
return HAL_CreateSimValueDouble(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueDouble(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,12 +474,12 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnum(const char* name, int32_t direction,
|
||||
SimEnum CreateEnum(const char* name, Direction direction,
|
||||
std::initializer_list<const char*> options,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
|
||||
const_cast<const char**>(options.begin()),
|
||||
initialValue);
|
||||
return HAL_CreateSimValueEnum(
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.begin()), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,12 +496,12 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnum(const char* name, int32_t direction,
|
||||
SimEnum CreateEnum(const char* name, Direction direction,
|
||||
std::span<const char* const> options,
|
||||
int32_t initialValue) {
|
||||
return HAL_CreateSimValueEnum(m_handle, name, direction, options.size(),
|
||||
const_cast<const char**>(options.data()),
|
||||
initialValue);
|
||||
return HAL_CreateSimValueEnum(
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.data()), initialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +520,7 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnumDouble(const char* name, int32_t direction,
|
||||
SimEnum CreateEnumDouble(const char* name, Direction direction,
|
||||
std::initializer_list<const char*> options,
|
||||
std::initializer_list<double> optionValues,
|
||||
int32_t initialValue) {
|
||||
@@ -523,7 +528,7 @@ class SimDevice {
|
||||
return {};
|
||||
}
|
||||
return HAL_CreateSimValueEnumDouble(
|
||||
m_handle, name, direction, options.size(),
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.begin()), optionValues.begin(),
|
||||
initialValue);
|
||||
}
|
||||
@@ -544,7 +549,7 @@ class SimDevice {
|
||||
* @param initialValue initial value (selection)
|
||||
* @return simulated enum value object
|
||||
*/
|
||||
SimEnum CreateEnumDouble(const char* name, int32_t direction,
|
||||
SimEnum CreateEnumDouble(const char* name, Direction direction,
|
||||
std::span<const char* const> options,
|
||||
std::span<const double> optionValues,
|
||||
int32_t initialValue) {
|
||||
@@ -552,7 +557,7 @@ class SimDevice {
|
||||
return {};
|
||||
}
|
||||
return HAL_CreateSimValueEnumDouble(
|
||||
m_handle, name, direction, options.size(),
|
||||
m_handle, name, static_cast<int32_t>(direction), options.size(),
|
||||
const_cast<const char**>(options.data()), optionValues.data(),
|
||||
initialValue);
|
||||
}
|
||||
@@ -568,9 +573,10 @@ class SimDevice {
|
||||
* @param initialValue initial value
|
||||
* @return simulated boolean value object
|
||||
*/
|
||||
SimBoolean CreateBoolean(const char* name, int32_t direction,
|
||||
SimBoolean CreateBoolean(const char* name, Direction direction,
|
||||
bool initialValue) {
|
||||
return HAL_CreateSimValueBoolean(m_handle, name, direction, initialValue);
|
||||
return HAL_CreateSimValueBoolean(
|
||||
m_handle, name, static_cast<int32_t>(direction), initialValue);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -148,11 +148,11 @@ classes:
|
||||
CreateDouble:
|
||||
CreateEnum:
|
||||
overloads:
|
||||
const char*, int32_t, std::initializer_list<const char *>, int32_t:
|
||||
const char*, Direction, std::initializer_list<const char *>, int32_t:
|
||||
ignore: true
|
||||
const char*, int32_t, std::span<const char * const>, int32_t:
|
||||
const char*, Direction, std::span<const char * const>, int32_t:
|
||||
cpp_code: |
|
||||
[](SimDevice &self, const char * name, int32_t direction, const wpi::util::SmallVector<std::string, 8> &options, int32_t initialValue) {
|
||||
[](SimDevice &self, const char * name, SimDevice::Direction direction, const wpi::util::SmallVector<std::string, 8> &options, int32_t initialValue) {
|
||||
wpi::util::SmallVector<const char *, 8> coptions;
|
||||
coptions.reserve(options.size());
|
||||
for (auto &s: options) {
|
||||
@@ -163,11 +163,11 @@ classes:
|
||||
|
||||
CreateEnumDouble:
|
||||
overloads:
|
||||
const char*, int32_t, std::initializer_list<const char *>, std::initializer_list<double>, int32_t:
|
||||
const char*, Direction, std::initializer_list<const char *>, std::initializer_list<double>, int32_t:
|
||||
ignore: true
|
||||
const char*, int32_t, std::span<const char * const>, std::span<const double>, int32_t:
|
||||
const char*, Direction, std::span<const char * const>, std::span<const double>, int32_t:
|
||||
cpp_code: |
|
||||
[](SimDevice &self, const char * name, int32_t direction, const wpi::util::SmallVector<std::string, 8> &options, const wpi::util::SmallVector<double, 8> &optionValues, int32_t initialValue) {
|
||||
[](SimDevice &self, const char * name, SimDevice::Direction direction, const wpi::util::SmallVector<std::string, 8> &options, const wpi::util::SmallVector<double, 8> &optionValues, int32_t initialValue) {
|
||||
wpi::util::SmallVector<const char *, 8> coptions;
|
||||
coptions.reserve(options.size());
|
||||
for (auto &s: options) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import hal
|
||||
|
||||
def test_hal_simdevice():
|
||||
device = hal.SimDevice("deviceName")
|
||||
v = device.createInt("i", 0, 1)
|
||||
v = device.createInt("i", hal.SimDevice.Direction.INPUT, 1)
|
||||
assert v.get() == 1
|
||||
assert v.type == hal.Type.INT
|
||||
|
||||
@@ -14,7 +14,7 @@ def test_hal_simdevice():
|
||||
def test_hal_simdevice_enum():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
v = device.createEnum("e", 0, names, 0)
|
||||
v = device.createEnum("e", hal.SimDevice.Direction.INPUT, names, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
@@ -28,7 +28,7 @@ def test_hal_simdevice_enum_double():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
values = [0.0, 1.0, 2.0]
|
||||
v = device.createEnumDouble("e", 0, names, values, 0)
|
||||
v = device.createEnumDouble("e", hal.SimDevice.Direction.INPUT, names, values, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_value_changed_callback():
|
||||
devunused = hal.simulation.registerSimValueCreatedCallback(dev, created_cb, True)
|
||||
assert recv is None
|
||||
|
||||
val = dev.createInt("answer", 0, 42)
|
||||
val = dev.createInt("answer", hal.SimDevice.Direction.INPUT, 42)
|
||||
|
||||
assert recv == (True, "answer", 42)
|
||||
recv = None
|
||||
|
||||
Reference in New Issue
Block a user