mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[hal] Remove HAL_GetPort (#7754)
This commit is contained in:
@@ -13,19 +13,19 @@ public class AnalogJNI extends JNIWrapper {
|
||||
/**
|
||||
* Initializes the analog input port using the given port object.
|
||||
*
|
||||
* @param halPortHandle Handle to the port to initialize.
|
||||
* @param channel The smartio channel.
|
||||
* @return the created analog input handle
|
||||
* @see "HAL_InitializeAnalogInputPort"
|
||||
*/
|
||||
public static native int initializeAnalogInputPort(int halPortHandle);
|
||||
public static native int initializeAnalogInputPort(int channel);
|
||||
|
||||
/**
|
||||
* Frees an analog input port.
|
||||
*
|
||||
* @param portHandle Handle to the analog port.
|
||||
* @param analogPortHandle Handle to the analog port.
|
||||
* @see "HAL_FreeAnalogInputPort"
|
||||
*/
|
||||
public static native void freeAnalogInputPort(int portHandle);
|
||||
public static native void freeAnalogInputPort(int analogPortHandle);
|
||||
|
||||
/**
|
||||
* Checks that the analog module number is valid.
|
||||
|
||||
@@ -13,12 +13,12 @@ public class DIOJNI extends JNIWrapper {
|
||||
/**
|
||||
* Creates a new instance of a digital port.
|
||||
*
|
||||
* @param halPortHandle the port handle to create from
|
||||
* @param channel the smartio channel
|
||||
* @param input true for input, false for output
|
||||
* @return the created digital handle
|
||||
* @see "HAL_InitializeDIOPort"
|
||||
*/
|
||||
public static native int initializeDIOPort(int halPortHandle, boolean input);
|
||||
public static native int initializeDIOPort(int channel, boolean input);
|
||||
|
||||
/**
|
||||
* Checks if a DIO channel is valid.
|
||||
|
||||
@@ -13,11 +13,11 @@ public class DutyCycleJNI extends JNIWrapper {
|
||||
/**
|
||||
* Initialize a DutyCycle input.
|
||||
*
|
||||
* @param halPortHandle the port handle to create from
|
||||
* @param channel the smartio channel
|
||||
* @return the created duty cycle handle
|
||||
* @see "HAL_InitializeDutyCycle"
|
||||
*/
|
||||
public static native int initialize(int halPortHandle);
|
||||
public static native int initialize(int channel);
|
||||
|
||||
/**
|
||||
* Free a DutyCycle.
|
||||
|
||||
@@ -211,31 +211,6 @@ public final class HAL extends JNIWrapper {
|
||||
*/
|
||||
public static native boolean getSystemTimeValid();
|
||||
|
||||
/**
|
||||
* Gets a port handle for a specific channel and module.
|
||||
*
|
||||
* <p>This is expected to be used for PCMs, as the roboRIO does not work with modules anymore.
|
||||
*
|
||||
* <p>The created handle does not need to be freed.
|
||||
*
|
||||
* @param module the module number
|
||||
* @param channel the channel number
|
||||
* @return the created port
|
||||
* @see "HAL_GetPortWithModule"
|
||||
*/
|
||||
public static native int getPortWithModule(byte module, byte channel);
|
||||
|
||||
/**
|
||||
* Gets a port handle for a specific channel.
|
||||
*
|
||||
* <p>The created handle does not need to be freed.
|
||||
*
|
||||
* @param channel the channel number
|
||||
* @return the created port
|
||||
* @see "HAL_GetPort"
|
||||
*/
|
||||
public static native int getPort(byte channel);
|
||||
|
||||
/**
|
||||
* Report the usage of a resource of interest.
|
||||
*
|
||||
|
||||
@@ -13,10 +13,10 @@ public class PWMJNI extends DIOJNI {
|
||||
/**
|
||||
* Initializes a PWM port.
|
||||
*
|
||||
* @param halPortHandle the port to initialize
|
||||
* @param channel the smartio channel
|
||||
* @return the created pwm handle
|
||||
*/
|
||||
public static native int initializePWMPort(int halPortHandle);
|
||||
public static native int initializePWMPort(int channel);
|
||||
|
||||
/**
|
||||
* Checks if a pwm channel is valid.
|
||||
|
||||
@@ -49,18 +49,6 @@ void HandleBase::ResetGlobalHandles() {
|
||||
}
|
||||
}
|
||||
}
|
||||
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
|
||||
// set last 8 bits, then shift to first 8 bits
|
||||
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
|
||||
handle = handle << 24;
|
||||
// shift module and add to 3rd set of 8 bits
|
||||
int32_t temp = module;
|
||||
temp = (temp << 8) & 0xff00;
|
||||
handle += temp;
|
||||
// add channel to last 8 bits
|
||||
handle += channel;
|
||||
return handle;
|
||||
}
|
||||
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
|
||||
int16_t version) {
|
||||
if (index < 0) {
|
||||
|
||||
@@ -25,12 +25,11 @@ extern "C" {
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
(JNIEnv* env, jclass, jint channel)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto analog =
|
||||
HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
|
||||
auto analog = HAL_InitializeAnalogInputPort(channel, stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)analog;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ extern "C" {
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
|
||||
(JNIEnv* env, jclass, jint id, jboolean input)
|
||||
(JNIEnv* env, jclass, jint channel, jboolean input)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto dio = HAL_InitializeDIOPort(
|
||||
(HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
|
||||
auto dio = HAL_InitializeDIOPort(channel, static_cast<uint8_t>(input),
|
||||
stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)dio;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@ extern "C" {
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_initialize
|
||||
(JNIEnv* env, jclass, jint portHandle)
|
||||
(JNIEnv* env, jclass, jint channel)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto handle = HAL_InitializeDutyCycle(static_cast<HAL_Handle>(portHandle),
|
||||
stack.c_str(), &status);
|
||||
auto handle = HAL_InitializeDutyCycle(channel, stack.c_str(), &status);
|
||||
CheckStatus(env, status);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -199,30 +199,4 @@ Java_edu_wpi_first_hal_HAL_getSystemTimeValid
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_HAL
|
||||
* Method: getPortWithModule
|
||||
* Signature: (BB)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_HAL_getPortWithModule
|
||||
(JNIEnv* env, jclass, jbyte module, jbyte channel)
|
||||
{
|
||||
HAL_PortHandle port = HAL_GetPortWithModule(module, channel);
|
||||
return (jint)port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_HAL
|
||||
* Method: getPort
|
||||
* Signature: (B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_HAL_getPort
|
||||
(JNIEnv* env, jclass, jbyte channel)
|
||||
{
|
||||
HAL_PortHandle port = HAL_GetPort(channel);
|
||||
return (jint)port;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -26,11 +26,11 @@ extern "C" {
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_PWMJNI_initializePWMPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
(JNIEnv* env, jclass, jint channel)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
|
||||
auto pwm = HAL_InitializePWMPort(channel, stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)pwm;
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ extern "C" {
|
||||
/**
|
||||
* Initializes the analog input port using the given port object.
|
||||
*
|
||||
* @param[in] portHandle Handle to the port to initialize.
|
||||
* @param[in] channel the smartio channel.
|
||||
* @param[in] allocationLocation the location where the allocation is occurring
|
||||
* (can be null)
|
||||
* @param[out] status the error code, or 0 for success
|
||||
* @return the created analog input handle
|
||||
*/
|
||||
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
|
||||
HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status);
|
||||
int32_t channel, const char* allocationLocation, int32_t* status);
|
||||
|
||||
/**
|
||||
* Frees an analog input port.
|
||||
|
||||
@@ -21,15 +21,14 @@ extern "C" {
|
||||
/**
|
||||
* Creates a new instance of a digital port.
|
||||
*
|
||||
* @param[in] portHandle the port handle to create from
|
||||
* @param[in] channel the smartio channel
|
||||
* @param[in] input true for input, false for output
|
||||
* @param[in] allocationLocation the location where the allocation is occurring
|
||||
* (can be null)
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
* @return the created digital handle
|
||||
*/
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
HAL_Bool input,
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
|
||||
const char* allocationLocation,
|
||||
int32_t* status);
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ extern "C" {
|
||||
/**
|
||||
* Initialize a DutyCycle input.
|
||||
*
|
||||
* @param[in] portHandle the port handle to create from
|
||||
* @param[in] channel the smartio channel
|
||||
* @param[in] allocationLocation the location where the allocation is occurring
|
||||
* (can be null)
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
* @return the created duty cycle handle
|
||||
*/
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status);
|
||||
|
||||
|
||||
@@ -148,30 +148,6 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status);
|
||||
*/
|
||||
int32_t HAL_GetCommsDisableCount(int32_t* status);
|
||||
|
||||
/**
|
||||
* Gets a port handle for a specific channel.
|
||||
*
|
||||
* The created handle does not need to be freed.
|
||||
*
|
||||
* @param channel the channel number
|
||||
* @return the created port
|
||||
*/
|
||||
HAL_PortHandle HAL_GetPort(int32_t channel);
|
||||
|
||||
/**
|
||||
* Gets a port handle for a specific channel and module.
|
||||
*
|
||||
* This is expected to be used for PCMs, as the roboRIO does not work with
|
||||
* modules anymore.
|
||||
*
|
||||
* The created handle does not need to be freed.
|
||||
*
|
||||
* @param module the module number
|
||||
* @param channel the channel number
|
||||
* @return the created port
|
||||
*/
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
|
||||
|
||||
/**
|
||||
* Reads the microsecond-resolution timer on the FPGA.
|
||||
*
|
||||
|
||||
@@ -21,13 +21,13 @@ extern "C" {
|
||||
/**
|
||||
* Initializes a PWM port.
|
||||
*
|
||||
* @param[in] portHandle the port to initialize
|
||||
* @param[in] channel the smartio channel
|
||||
* @param[in] allocationLocation the location where the allocation is occurring
|
||||
* (can be null)
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
* @return the created pwm handle
|
||||
*/
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status);
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
typedef int32_t HAL_Handle;
|
||||
|
||||
typedef HAL_Handle HAL_PortHandle;
|
||||
|
||||
typedef HAL_Handle HAL_AnalogInputHandle;
|
||||
|
||||
typedef HAL_Handle HAL_AnalogOutputHandle;
|
||||
|
||||
@@ -153,43 +153,6 @@ inline int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType,
|
||||
* Bit 31: 1 if handle error, 0 if no error
|
||||
*/
|
||||
|
||||
// using a 16 bit value so we can store 0-255 and still report error
|
||||
/**
|
||||
* Gets the port channel of a port handle.
|
||||
*
|
||||
* @param handle the port handle
|
||||
* @return the port channel
|
||||
*/
|
||||
inline int16_t getPortHandleChannel(HAL_PortHandle handle) {
|
||||
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
|
||||
return InvalidHandleIndex;
|
||||
}
|
||||
return static_cast<uint8_t>(handle & 0xff);
|
||||
}
|
||||
|
||||
// using a 16 bit value so we can store 0-255 and still report error
|
||||
/**
|
||||
* Gets the port module of a port handle.
|
||||
*
|
||||
* @param handle the port handle
|
||||
* @return the port module
|
||||
*/
|
||||
inline int16_t getPortHandleModule(HAL_PortHandle handle) {
|
||||
if (!isHandleType(handle, HAL_HandleEnum::Port)) {
|
||||
return InvalidHandleIndex;
|
||||
}
|
||||
return static_cast<uint8_t>((handle >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a port handle.
|
||||
*
|
||||
* @param channel the channel
|
||||
* @param module the module
|
||||
* @return port handle for the module and channel
|
||||
*/
|
||||
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);
|
||||
|
||||
/**
|
||||
* Create a handle for a specific index, type and version.
|
||||
*
|
||||
|
||||
@@ -19,11 +19,9 @@ void InitializeAnalogInput() {}
|
||||
|
||||
extern "C" {
|
||||
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
|
||||
HAL_PortHandle portHandle, const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
int32_t channel, const char* allocationLocation, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) {
|
||||
if (channel < 0 || channel >= kNumAnalogInputs) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
|
||||
0, kNumAnalogInputs, channel);
|
||||
|
||||
@@ -31,14 +31,12 @@ void InitializeDIO() {
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
HAL_Bool input,
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex) {
|
||||
if (channel < 0 || channel >= kNumDigitalChannels) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
|
||||
kNumDigitalChannels, channel);
|
||||
|
||||
@@ -33,7 +33,7 @@ void InitializeDutyCycle() {
|
||||
} // namespace hal::init
|
||||
|
||||
extern "C" {
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
@@ -51,7 +51,7 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
|
||||
}
|
||||
|
||||
int16_t index = getHandleIndex(handle);
|
||||
SimDutyCycleData[index].digitalChannel = getPortHandleChannel(portHandle);
|
||||
SimDutyCycleData[index].digitalChannel = channel;
|
||||
SimDutyCycleData[index].initialized = true;
|
||||
SimDutyCycleData[index].simDevice = 0;
|
||||
dutyCycle->index = index;
|
||||
|
||||
@@ -112,25 +112,6 @@ void InitializeHAL() {
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_PortHandle HAL_GetPort(int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, 1);
|
||||
}
|
||||
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
if (module < 0 || module >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, module);
|
||||
}
|
||||
|
||||
const char* HAL_GetErrorMessage(int32_t code) {
|
||||
switch (code) {
|
||||
case 0:
|
||||
|
||||
@@ -63,13 +63,12 @@ static inline int32_t GetFullRangeScaleFactor(DigitalPort* port) {
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex) {
|
||||
if (channel < 0 || channel >= kNumPWMChannels) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
|
||||
kNumPWMChannels, channel);
|
||||
|
||||
@@ -26,12 +26,10 @@ using namespace hal;
|
||||
extern "C" {
|
||||
|
||||
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
|
||||
HAL_PortHandle portHandle, const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
int32_t channel, const char* allocationLocation, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
|
||||
if (channel < 0 || channel >= kNumSmartIo) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog", 0,
|
||||
kNumSmartIo, channel);
|
||||
|
||||
@@ -25,14 +25,12 @@ void InitializeDIO() {}
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
HAL_Bool input,
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
|
||||
if (channel < 0 || channel >= kNumSmartIo) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
|
||||
kNumSmartIo, channel);
|
||||
|
||||
@@ -24,13 +24,12 @@ void InitializeDutyCycle() {}
|
||||
} // namespace hal::init
|
||||
|
||||
extern "C" {
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_PortHandle portHandle,
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
|
||||
if (channel < 0 || channel >= kNumSmartIo) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DutyCycle", 0,
|
||||
kNumSmartIo, channel);
|
||||
|
||||
@@ -81,25 +81,6 @@ uint64_t GetDSInitializeTime() {
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_PortHandle HAL_GetPort(int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, 1);
|
||||
}
|
||||
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
if (module < 0 || module >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, module);
|
||||
}
|
||||
|
||||
const char* HAL_GetErrorMessage(int32_t code) {
|
||||
switch (code) {
|
||||
case 0:
|
||||
|
||||
@@ -68,13 +68,12 @@ void InitializePWM() {}
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
|
||||
const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
|
||||
if (channel < 0 || channel >= kNumSmartIo) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
|
||||
kNumSmartIo, channel);
|
||||
|
||||
@@ -32,13 +32,13 @@ TEST(AnalogInSimTest, AnalogInInitialization) {
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_PortHandle portHandle;
|
||||
int32_t channel = 0;
|
||||
HAL_DigitalHandle analogInHandle;
|
||||
|
||||
// Use out of range index
|
||||
portHandle = 8000;
|
||||
channel = 8000;
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status);
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(channel, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogInHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -47,18 +47,18 @@ TEST(AnalogInSimTest, AnalogInInitialization) {
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status);
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(channel, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status);
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(channel, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogInHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -73,9 +73,9 @@ TEST(AnalogInSimTest, AnalogInInitialization) {
|
||||
false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status);
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(channel, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str());
|
||||
|
||||
@@ -32,13 +32,13 @@ TEST(DigitalIoSimTest, DigitalIoInitialization) {
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_PortHandle portHandle;
|
||||
int32_t channel = 0;
|
||||
HAL_DigitalHandle digitalIoHandle;
|
||||
|
||||
// Use out of range index
|
||||
portHandle = 8000;
|
||||
channel = 8000;
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status);
|
||||
digitalIoHandle = HAL_InitializeDIOPort(channel, true, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -47,18 +47,18 @@ TEST(DigitalIoSimTest, DigitalIoInitialization) {
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status);
|
||||
digitalIoHandle = HAL_InitializeDIOPort(channel, true, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status);
|
||||
digitalIoHandle = HAL_InitializeDIOPort(channel, true, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -73,9 +73,9 @@ TEST(DigitalIoSimTest, DigitalIoInitialization) {
|
||||
false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status);
|
||||
digitalIoHandle = HAL_InitializeDIOPort(channel, true, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str());
|
||||
|
||||
@@ -31,13 +31,13 @@ TEST(PWMSimTest, PwmInitialization) {
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_PortHandle portHandle;
|
||||
int32_t channel = 0;
|
||||
HAL_DigitalHandle pwmHandle;
|
||||
|
||||
// Use out of range index
|
||||
portHandle = 8000;
|
||||
channel = 8000;
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status);
|
||||
pwmHandle = HAL_InitializePWMPort(channel, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pwmHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -46,18 +46,18 @@ TEST(PWMSimTest, PwmInitialization) {
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status);
|
||||
pwmHandle = HAL_InitializePWMPort(channel, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status);
|
||||
pwmHandle = HAL_InitializePWMPort(channel, nullptr, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pwmHandle);
|
||||
EXPECT_EQ(HAL_USE_LAST_ERROR, status);
|
||||
HAL_GetLastError(&status);
|
||||
@@ -71,9 +71,9 @@ TEST(PWMSimTest, PwmInitialization) {
|
||||
INDEX_TO_TEST, &TestPwmInitializationCallback, &callbackParam, false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
channel = INDEX_TO_TEST;
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status);
|
||||
pwmHandle = HAL_InitializePWMPort(channel, nullptr, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str());
|
||||
|
||||
@@ -19,8 +19,7 @@ AddressableLED::AddressableLED(int port) : m_port{port} {
|
||||
int32_t status = 0;
|
||||
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
m_pwmHandle =
|
||||
HAL_InitializePWMPort(HAL_GetPort(port), stack.c_str(), &status);
|
||||
m_pwmHandle = HAL_InitializePWMPort(port, stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
if (m_pwmHandle == HAL_kInvalidHandle) {
|
||||
return;
|
||||
|
||||
@@ -26,11 +26,9 @@ AnalogInput::AnalogInput(int channel) {
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
|
||||
HAL_PortHandle port = HAL_GetPort(channel);
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_port = HAL_InitializeAnalogInputPort(port, stackTrace.c_str(), &status);
|
||||
m_port = HAL_InitializeAnalogInputPort(channel, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel + 1);
|
||||
|
||||
@@ -27,8 +27,7 @@ DigitalInput::DigitalInput(int channel) {
|
||||
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true,
|
||||
stackTrace.c_str(), &status);
|
||||
m_handle = HAL_InitializeDIOPort(channel, true, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalInput, channel + 1);
|
||||
|
||||
@@ -28,8 +28,7 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false,
|
||||
stackTrace.c_str(), &status);
|
||||
m_handle = HAL_InitializeDIOPort(channel, false, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel + 1);
|
||||
|
||||
@@ -29,8 +29,7 @@ DutyCycle::DutyCycle(int channel) : m_channel{channel} {
|
||||
void DutyCycle::InitDutyCycle() {
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDutyCycle(HAL_GetPort(m_channel), stackTrace.c_str(),
|
||||
&status);
|
||||
m_handle = HAL_InitializeDutyCycle(m_channel, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, m_channel + 1);
|
||||
wpi::SendableRegistry::Add(this, "Duty Cycle", m_channel);
|
||||
|
||||
@@ -26,8 +26,7 @@ PWM::PWM(int channel, bool registerSendable) {
|
||||
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
int32_t status = 0;
|
||||
m_handle =
|
||||
HAL_InitializePWMPort(HAL_GetPort(channel), stack.c_str(), &status);
|
||||
m_handle = HAL_InitializePWMPort(channel, stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
m_channel = channel;
|
||||
|
||||
@@ -62,8 +62,7 @@ int main(void) {
|
||||
|
||||
// Create a Motor Controller
|
||||
status = 0;
|
||||
HAL_DigitalHandle pwmPort =
|
||||
HAL_InitializePWMPort(HAL_GetPort(2), NULL, &status);
|
||||
HAL_DigitalHandle pwmPort = HAL_InitializePWMPort(1, NULL, &status);
|
||||
|
||||
if (status != 0) {
|
||||
const char* message = HAL_GetLastError(&status);
|
||||
@@ -76,8 +75,7 @@ int main(void) {
|
||||
|
||||
// Create an Input
|
||||
status = 0;
|
||||
HAL_DigitalHandle dio =
|
||||
HAL_InitializeDIOPort(HAL_GetPort(2), 1, NULL, &status);
|
||||
HAL_DigitalHandle dio = HAL_InitializeDIOPort(2, 1, NULL, &status);
|
||||
|
||||
if (status != 0) {
|
||||
const char* message = HAL_GetLastError(&status);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class AddressableLED implements AutoCloseable {
|
||||
* @param port the output port to use (Must be a PWM header, not on MXP)
|
||||
*/
|
||||
public AddressableLED(int port) {
|
||||
m_pwmHandle = PWMJNI.initializePWMPort(HAL.getPort((byte) port));
|
||||
m_pwmHandle = PWMJNI.initializePWMPort(port);
|
||||
m_handle = AddressableLEDJNI.initialize(m_pwmHandle);
|
||||
HAL.report(tResourceType.kResourceType_AddressableLEDs, port + 1);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ public class AnalogInput implements Sendable, AutoCloseable {
|
||||
AnalogJNI.checkAnalogInputChannel(channel);
|
||||
m_channel = channel;
|
||||
|
||||
final int portHandle = HAL.getPort((byte) channel);
|
||||
m_port = AnalogJNI.initializeAnalogInputPort(portHandle);
|
||||
m_port = AnalogJNI.initializeAnalogInputPort(channel);
|
||||
|
||||
HAL.report(tResourceType.kResourceType_AnalogChannel, channel + 1);
|
||||
SendableRegistry.add(this, "AnalogInput", channel);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DigitalInput implements AutoCloseable, Sendable {
|
||||
SensorUtil.checkDigitalChannel(channel);
|
||||
m_channel = channel;
|
||||
|
||||
m_handle = DIOJNI.initializeDIOPort(HAL.getPort((byte) channel), true);
|
||||
m_handle = DIOJNI.initializeDIOPort(channel, true);
|
||||
|
||||
HAL.report(tResourceType.kResourceType_DigitalInput, channel + 1);
|
||||
SendableRegistry.add(this, "DigitalInput", channel);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DigitalOutput implements AutoCloseable, Sendable {
|
||||
SensorUtil.checkDigitalChannel(channel);
|
||||
m_channel = channel;
|
||||
|
||||
m_handle = DIOJNI.initializeDIOPort(HAL.getPort((byte) channel), false);
|
||||
m_handle = DIOJNI.initializeDIOPort(channel, false);
|
||||
|
||||
HAL.report(tResourceType.kResourceType_DigitalOutput, channel + 1);
|
||||
SendableRegistry.add(this, "DigitalOutput", channel);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DutyCycle implements Sendable, AutoCloseable {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public DutyCycle(int channel) {
|
||||
m_handle = DutyCycleJNI.initialize(HAL.getPort((byte) channel));
|
||||
m_handle = DutyCycleJNI.initialize(channel);
|
||||
|
||||
m_channel = channel;
|
||||
HAL.report(tResourceType.kResourceType_DutyCycle, channel + 1);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PWM implements Sendable, AutoCloseable {
|
||||
SensorUtil.checkPWMChannel(channel);
|
||||
m_channel = channel;
|
||||
|
||||
m_handle = PWMJNI.initializePWMPort(HAL.getPort((byte) channel));
|
||||
m_handle = PWMJNI.initializePWMPort(channel);
|
||||
|
||||
setDisabled();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user