From f5a292dadd26eaf194049ac3b82ccde0eaae5076 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 12 Feb 2018 16:05:10 -0800 Subject: [PATCH] Adds TriState JNI entry point (#938) Also adds missing sim TriState DIO HAL call, and a ToDo for later --- hal/src/main/native/sim/DIO.cpp | 17 +++++++++++++++++ .../java/edu/wpi/first/wpilibj/hal/DIOJNI.java | 3 +++ wpilibj/src/main/native/cpp/DIOJNI.cpp | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/hal/src/main/native/sim/DIO.cpp b/hal/src/main/native/sim/DIO.cpp index 5c039276fb..2e08b8bcc6 100644 --- a/hal/src/main/native/sim/DIO.cpp +++ b/hal/src/main/native/sim/DIO.cpp @@ -198,6 +198,23 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value, SimDIOData[port->channel].SetValue(value); } +/** + * Set direction of a DIO channel. + * + * @param channel The Digital I/O channel + * @param input true to set input, false for output + */ +void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input, + int32_t* status) { + auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO); + if (port == nullptr) { + *status = HAL_HANDLE_ERROR; + return; + } + + SimDIOData[port->channel].SetIsInput(input); +} + /** * Read a digital I/O bit from the FPGA. * Get a single value from a digital I/O channel. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java index c861621749..206addab09 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java @@ -15,8 +15,11 @@ public class DIOJNI extends JNIWrapper { public static native void freeDIOPort(int dioPortHandle); + // TODO(Thad): Switch this to use boolean public static native void setDIO(int dioPortHandle, short value); + public static native void setDIODirection(int dioPortHandle, boolean input); + public static native boolean getDIO(int dioPortHandle); public static native boolean getDIODirection(int dioPortHandle); diff --git a/wpilibj/src/main/native/cpp/DIOJNI.cpp b/wpilibj/src/main/native/cpp/DIOJNI.cpp index 16048dfa08..95867c8d2e 100644 --- a/wpilibj/src/main/native/cpp/DIOJNI.cpp +++ b/wpilibj/src/main/native/cpp/DIOJNI.cpp @@ -90,6 +90,22 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDIO( CheckStatus(env, status); } +/* + * Class: edu_wpi_first_wpilibj_hal_DIOJNI + * Method: setDIODirection + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDIODirection( + JNIEnv *env, jclass, jint id, jboolean input) { + // DIOJNI_LOG(logDEBUG) << "Calling DIOJNI setDIO"; + // DIOJNI_LOG(logDEBUG) << "Port Handle = " << (HAL_DigitalHandle)id; + // DIOJNI_LOG(logDEBUG) << "IsInput = " << input; + int32_t status = 0; + HAL_SetDIODirection((HAL_DigitalHandle)id, input, &status); + // DIOJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: getDIO