mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Changes HAL Port from a pointer to a handle (#93)
HAL Port is using a special handle, where the module and pin are bit shifted straight into the handle. This is one of the few special cases we have, but for the way port is used it is much cleaner and uses much less memory. Plus it is generic and not specific to one type.
This commit is contained in:
committed by
Peter Johnson
parent
5a82f73d9b
commit
fc515f4572
@@ -31,14 +31,14 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: initializeAnalogInputPort
|
||||
* Signature: (J)J
|
||||
* Signature: (I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort(
|
||||
JNIEnv *env, jclass, jlong id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
|
||||
int32_t status = 0;
|
||||
void *analog = initializeAnalogInputPort((void *)id, &status);
|
||||
void *analog = initializeAnalogInputPort((HalPortHandle)id, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
|
||||
CheckStatus(env, status);
|
||||
@@ -60,14 +60,14 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_freeAnalogInputPort(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: initializeAnalogOutputPort
|
||||
* Signature: (J)J
|
||||
* Signature: (I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort(
|
||||
JNIEnv *env, jclass, jlong id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
|
||||
int32_t status = 0;
|
||||
void *analog = initializeAnalogOutputPort((void *)id, &status);
|
||||
void *analog = initializeAnalogOutputPort((HalPortHandle)id, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
|
||||
CheckStatus(env, status);
|
||||
@@ -521,19 +521,19 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: initializeAnalogTrigger
|
||||
* Signature: (JLjava/nio/IntBuffer;)J
|
||||
* Signature: (ILjava/nio/IntBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger(
|
||||
JNIEnv *env, jclass, jlong id, jobject index) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
|
||||
JNIEnv *env, jclass, jint id, jobject index) {
|
||||
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (HalPortHandle)id;
|
||||
|
||||
jint *indexPtr = (jint *)env->GetDirectBufferAddress(index);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
|
||||
|
||||
int32_t status = 0;
|
||||
void *analogTrigger =
|
||||
initializeAnalogTrigger((void *)id, (uint32_t *)indexPtr, &status);
|
||||
initializeAnalogTrigger((HalPortHandle)id, (uint32_t *)indexPtr, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << analogTrigger;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -29,15 +29,15 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
|
||||
* Method: initializeDigitalPort
|
||||
* Signature: (J)J;
|
||||
* Signature: (I)J;
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort(
|
||||
JNIEnv *env, jclass, jlong id) {
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI initializeDigitalPort";
|
||||
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)id;
|
||||
DIOJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)id;
|
||||
int32_t status = 0;
|
||||
void *dio = initializeDigitalPort((void *)id, &status);
|
||||
void *dio = initializeDigitalPort((HalPortHandle)id, &status);
|
||||
DIOJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << dio;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -18,46 +18,46 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: getPortWithModule
|
||||
* Signature: (BB)J
|
||||
* Signature: (BB)I
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule(
|
||||
JNIEnv* env, jclass, jbyte module, jbyte pin) {
|
||||
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
void* port = getPortWithModule(module, pin);
|
||||
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
return (jlong)port;
|
||||
HalPortHandle port = getPortWithModule(module, pin);
|
||||
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
|
||||
return (jint)port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: getPort
|
||||
* Signature: (BB)J
|
||||
* Signature: (B)I
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort(
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort(
|
||||
JNIEnv* env, jclass, jbyte pin) {
|
||||
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
void* port = getPort(pin);
|
||||
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
return (jlong)port;
|
||||
HalPortHandle port = getPort(pin);
|
||||
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
|
||||
return (jint)port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: freePort
|
||||
* Signature: (J)V
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_freePort(
|
||||
JNIEnv* env, jclass, jlong id) {
|
||||
JNIEnv* env, jclass, jint id) {
|
||||
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
freePort((void*)id);
|
||||
// FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
freePort((HalPortHandle)id);
|
||||
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -26,21 +26,21 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: initializeSolenoidPort
|
||||
* Signature: (J)J
|
||||
* Signature: (I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort(
|
||||
JNIEnv *env, jclass, jlong port_pointer) {
|
||||
JNIEnv *env, jclass, jint port_handle) {
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort";
|
||||
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << (void *)port_pointer;
|
||||
char *aschars = (char *)port_pointer;
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Port Handle = " << (HalPortHandle)port_handle;
|
||||
char *aschars = (char *)port_handle;
|
||||
SOLENOIDJNI_LOG(logDEBUG) << '\t' << (int)aschars[0] << '\t'
|
||||
<< (int)aschars[1] << std::endl;
|
||||
|
||||
int32_t status = 0;
|
||||
void *solenoid_port_pointer =
|
||||
initializeSolenoidPort((void *)port_pointer, &status);
|
||||
initializeSolenoidPort((HalPortHandle)port_handle, &status);
|
||||
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = "
|
||||
@@ -68,19 +68,6 @@ Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_freeSolenoidPort(
|
||||
freeSolenoidPort((void *)id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: getPortWithModule
|
||||
* Signature: (BB)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule(
|
||||
JNIEnv *env, jclass, jbyte module, jbyte channel) {
|
||||
void *port_pointer = getPortWithModule(module, channel);
|
||||
|
||||
return (jlong)port_pointer;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: setSolenoid
|
||||
|
||||
Reference in New Issue
Block a user