mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Makes SensorBase checks use HAL check methods (#182)
This commit is contained in:
committed by
Peter Johnson
parent
0901ae0808
commit
512ecf6490
@@ -49,9 +49,21 @@ Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDIOPort(
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
|
||||
* Method: freeDIOPort
|
||||
* Signature: (I)V;
|
||||
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
|
||||
* Method: checkDIOChannel
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_checkDIOChannel(
|
||||
JNIEnv *env, jclass, jint channel) {
|
||||
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI checkDIOChannel";
|
||||
DIOJNI_LOG(logDEBUG) << "Channel = " << channel;
|
||||
return HAL_CheckDIOChannel(channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
|
||||
* Method: freeDIOPort
|
||||
* Signature: (I)V;
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_freeDIOPort(
|
||||
JNIEnv *env, jclass, jint id) {
|
||||
|
||||
@@ -24,6 +24,26 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP(
|
||||
CheckStatusRange(env, 0, HAL_GetNumPDPModules(), module, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
|
||||
* Method: checkPDPChannel
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_checkPDPChannel(
|
||||
JNIEnv *env, jclass, jint channel) {
|
||||
return HAL_CheckPDPChannel(channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
|
||||
* Method: checkPDPModule
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_checkPDPModule(
|
||||
JNIEnv *env, jclass, jint module) {
|
||||
return HAL_CheckPDPModule(module);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
|
||||
* Method: getPDPTemperature
|
||||
|
||||
@@ -47,6 +47,18 @@ Java_edu_wpi_first_wpilibj_hal_PWMJNI_initializePWMPort(
|
||||
return (jint)pwm;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
|
||||
* Method: checkPWMChannel
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_checkPWMChannel(
|
||||
JNIEnv *env, jclass, jint channel) {
|
||||
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI checkPWMChannel";
|
||||
PWMJNI_LOG(logDEBUG) << "Channel = " << channel;
|
||||
return HAL_CheckPWMChannel(channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
|
||||
* Method: freeDIOPort
|
||||
|
||||
@@ -49,6 +49,30 @@ Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort(
|
||||
return (jint)handle;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: checkSolenoidChannel
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_checkSolenoidChannel(
|
||||
JNIEnv *env, jclass, jint channel) {
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI checkSolenoidChannel";
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Channel = " << channel;
|
||||
return HAL_CheckSolenoidChannel(channel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: checkSolenoidModule
|
||||
* Signature: (I)Z;
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_checkSolenoidModule(
|
||||
JNIEnv *env, jclass, jint module) {
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI checkSolenoidModule";
|
||||
SOLENOIDJNI_LOG(logDEBUG) << "Module = " << module;
|
||||
return HAL_CheckSolenoidModule(module);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
||||
* Method: freeSolenoidPort
|
||||
|
||||
@@ -7,8 +7,14 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.ConstantsJNI;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.PDPJNI;
|
||||
import edu.wpi.first.wpilibj.hal.PWMJNI;
|
||||
import edu.wpi.first.wpilibj.hal.PortsJNI;
|
||||
import edu.wpi.first.wpilibj.hal.RelayJNI;
|
||||
import edu.wpi.first.wpilibj.hal.SolenoidJNI;
|
||||
|
||||
/**
|
||||
* Base class for all sensors. Stores most recent status information as well as containing utility
|
||||
@@ -43,7 +49,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
/**
|
||||
* Number of relay channels per roboRIO.
|
||||
*/
|
||||
public static final int kRelayChannels = PortsJNI.getNumRelayPins();
|
||||
public static final int kRelayChannels = PortsJNI.getNumRelayHeaders();
|
||||
/**
|
||||
* Number of power distribution channels.
|
||||
*/
|
||||
@@ -81,6 +87,9 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param moduleNumber The solenoid module module number to check.
|
||||
*/
|
||||
protected static void checkSolenoidModule(final int moduleNumber) {
|
||||
if (!SolenoidJNI.checkSolenoidModule(moduleNumber)) {
|
||||
throw new IndexOutOfBoundsException("Requested solenoid module number is out of range");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +99,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkDigitalChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kDigitalChannels) {
|
||||
if (!DIOJNI.checkDIOChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested digital channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -102,7 +111,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkRelayChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kRelayChannels) {
|
||||
if (!RelayJNI.checkRelayChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested relay channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -114,7 +123,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkPWMChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kPwmChannels) {
|
||||
if (!PWMJNI.checkPWMChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested PWM channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -126,7 +135,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkAnalogInputChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kAnalogInputChannels) {
|
||||
if (!AnalogJNI.checkAnalogInputChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested analog input channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -138,7 +147,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkAnalogOutputChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kAnalogOutputChannels) {
|
||||
if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException(
|
||||
"Requested analog output channel number is out of range.");
|
||||
}
|
||||
@@ -150,7 +159,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkSolenoidChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kSolenoidChannels) {
|
||||
if (!SolenoidJNI.checkSolenoidChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested solenoid channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -162,7 +171,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param channel The channel number to check.
|
||||
*/
|
||||
protected static void checkPDPChannel(final int channel) {
|
||||
if (channel < 0 || channel >= kPDPChannels) {
|
||||
if (!PDPJNI.checkPDPChannel(channel)) {
|
||||
throw new IndexOutOfBoundsException("Requested PDP channel number is out of range.");
|
||||
}
|
||||
}
|
||||
@@ -173,7 +182,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param module The module number to check.
|
||||
*/
|
||||
protected static void checkPDPModule(final int module) {
|
||||
if (module < 0 || module > kPDPModules) {
|
||||
if (!PDPJNI.checkPDPModule(module)) {
|
||||
throw new IndexOutOfBoundsException("Requested PDP module number is out of range.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ package edu.wpi.first.wpilibj.hal;
|
||||
public class DIOJNI extends JNIWrapper {
|
||||
public static native int initializeDIOPort(int halPortHandle, boolean input);
|
||||
|
||||
public static native boolean checkDIOChannel(int channel);
|
||||
|
||||
public static native void freeDIOPort(int dioPortHandle);
|
||||
|
||||
public static native void setDIO(int dioPortHandle, short value);
|
||||
|
||||
@@ -11,6 +11,10 @@ package edu.wpi.first.wpilibj.hal;
|
||||
public class PDPJNI extends JNIWrapper {
|
||||
public static native void initializePDP(int module);
|
||||
|
||||
public static native boolean checkPDPModule(int module);
|
||||
|
||||
public static native boolean checkPDPChannel(int channel);
|
||||
|
||||
public static native double getPDPTemperature(int module);
|
||||
|
||||
public static native double getPDPVoltage(int module);
|
||||
|
||||
@@ -13,6 +13,8 @@ import edu.wpi.first.wpilibj.PWMConfigDataResult;
|
||||
public class PWMJNI extends DIOJNI {
|
||||
public static native int initializePWMPort(int halPortHandle);
|
||||
|
||||
public static native boolean checkPWMChannel(int channel);
|
||||
|
||||
public static native void freePWMPort(int pwmPortHandle);
|
||||
|
||||
public static native void setPWMConfigRaw(int pwmPortHandle, int maxPwm,
|
||||
|
||||
@@ -10,6 +10,10 @@ package edu.wpi.first.wpilibj.hal;
|
||||
public class SolenoidJNI extends JNIWrapper {
|
||||
public static native int initializeSolenoidPort(int halPortHandle);
|
||||
|
||||
public static native boolean checkSolenoidModule(int module);
|
||||
|
||||
public static native boolean checkSolenoidChannel(int channel);
|
||||
|
||||
public static native void freeSolenoidPort(int portHandle);
|
||||
|
||||
public static native void setSolenoid(int portHandle, boolean on);
|
||||
|
||||
Reference in New Issue
Block a user