New 2018 and later build setup (#1001)

This commit is contained in:
Thad House
2018-04-29 13:29:07 -07:00
committed by Peter Johnson
parent cb2c9eb6d5
commit 7f88cf768d
317 changed files with 60521 additions and 54781 deletions

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
/**
* Structure for holding the values stored in an accumulator.
*/
public class AccumulatorResult {
/**
* The total value accumulated.
*/
@SuppressWarnings("MemberName")
public long value;
/**
* The number of sample value was accumulated over.
*/
@SuppressWarnings("MemberName")
public long count;
/**
* Set the value and count.
*/
public void set(long value, long count) {
this.value = value;
this.count = count;
}
}

View File

@@ -0,0 +1,51 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
/**
* Structure for holding the config data result for PWM.
*/
public class PWMConfigDataResult {
PWMConfigDataResult(int max, int deadbandMax, int center, int deadbandMin, int min) {
this.max = max;
this.deadbandMax = deadbandMax;
this.center = center;
this.deadbandMin = deadbandMin;
this.min = min;
}
/**
* The maximum PWM value.
*/
@SuppressWarnings("MemberName")
public int max;
/**
* The deadband maximum PWM value.
*/
@SuppressWarnings("MemberName")
public int deadbandMax;
/**
* The center PWM value.
*/
@SuppressWarnings("MemberName")
public int center;
/**
* The deadband minimum PWM value.
*/
@SuppressWarnings("MemberName")
public int deadbandMin;
/**
* The minimum PWM value.
*/
@SuppressWarnings("MemberName")
public int min;
}

View File

@@ -0,0 +1,44 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
import edu.wpi.first.wpilibj.communication.NIRioStatus;
import edu.wpi.first.wpilibj.util.UncleanStatusException;
public class CANExceptionFactory {
// FRC Error codes
static final int ERR_CANSessionMux_InvalidBuffer = -44086;
static final int ERR_CANSessionMux_MessageNotFound = -44087;
static final int ERR_CANSessionMux_NotAllowed = -44088;
static final int ERR_CANSessionMux_NotInitialized = -44089;
@SuppressWarnings("JavadocMethod")
public static void checkStatus(int status, int messageID) throws CANInvalidBufferException,
CANMessageNotAllowedException, CANNotInitializedException, UncleanStatusException {
switch (status) {
case NIRioStatus.kRioStatusSuccess:
// Everything is ok... don't throw.
return;
case ERR_CANSessionMux_InvalidBuffer:
case NIRioStatus.kRIOStatusBufferInvalidSize:
throw new CANInvalidBufferException();
case ERR_CANSessionMux_MessageNotFound:
case NIRioStatus.kRIOStatusOperationTimedOut:
throw new CANMessageNotFoundException();
case ERR_CANSessionMux_NotAllowed:
case NIRioStatus.kRIOStatusFeatureNotSupported:
throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID));
case ERR_CANSessionMux_NotInitialized:
case NIRioStatus.kRIOStatusResourceNotInitialized:
throw new CANNotInitializedException();
default:
throw new UncleanStatusException("Fatal status code detected: " + Integer.toString(
status));
}
}
}

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
/**
* Exception indicating that a CAN driver library entry-point was passed an invalid buffer.
* Typically, this is due to a buffer being too small to include the needed safety token.
*/
public class CANInvalidBufferException extends RuntimeException {
private static final long serialVersionUID = -7993785672956997939L;
public CANInvalidBufferException() {
super();
}
public CANInvalidBufferException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import edu.wpi.first.wpilibj.hal.JNIWrapper;
@SuppressWarnings("AbbreviationAsWordInName")
public class CANJNI extends JNIWrapper {
public static final int CAN_SEND_PERIOD_NO_REPEAT = 0;
public static final int CAN_SEND_PERIOD_STOP_REPEATING = -1;
/* Flags in the upper bits of the messageID */
public static final int CAN_IS_FRAME_REMOTE = 0x80000000;
public static final int CAN_IS_FRAME_11BIT = 0x40000000;
@SuppressWarnings("MethodName")
public static native void FRCNetCommCANSessionMuxSendMessage(int messageID,
byte[] data,
int periodMs);
@SuppressWarnings("MethodName")
public static native byte[] FRCNetCommCANSessionMuxReceiveMessage(
IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp);
@SuppressWarnings("MethodName")
public static native void GetCANStatus(CANStatus status);
}

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
/**
* Exception indicating that the Jaguar CAN Driver layer refused to send a restricted message ID to
* the CAN bus.
*/
public class CANMessageNotAllowedException extends RuntimeException {
private static final long serialVersionUID = -638450112427013494L;
public CANMessageNotAllowedException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
/**
* Exception indicating that a can message is not available from Network Communications. This
* usually just means we already have the most recent value cached locally.
*/
public class CANMessageNotFoundException extends RuntimeException {
private static final long serialVersionUID = 8249780881928189975L;
public CANMessageNotFoundException() {
super();
}
public CANMessageNotFoundException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
/**
* Exception indicating that the CAN driver layer has not been initialized. This happens when an
* entry-point is called before a CAN driver plugin has been installed.
*/
public class CANNotInitializedException extends RuntimeException {
private static final long serialVersionUID = -5982895147092686594L;
public CANNotInitializedException() {
super();
}
public CANNotInitializedException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.can;
/**
* Structure for holding the result of a CAN Status request.
*/
public class CANStatus {
/**
* The utilization of the CAN Bus.
*/
@SuppressWarnings("MemberName")
public double percentBusUtilization;
/**
* The CAN Bus off count.
*/
@SuppressWarnings("MemberName")
public int busOffCount;
/**
* The CAN Bus TX full count.
*/
@SuppressWarnings("MemberName")
public int txFullCount;
/**
* The CAN Bus receive error count.
*/
@SuppressWarnings("MemberName")
public int receiveErrorCount;
/**
* The CAN Bus transmit error count.
*/
@SuppressWarnings("MemberName")
public int transmitErrorCount;
@SuppressWarnings("JavadocMethod")
public void setStatus(double percentBusUtilization, int busOffCount, int txFullCount,
int receiveErrorCount, int transmitErrorCount) {
this.percentBusUtilization = percentBusUtilization;
this.busOffCount = busOffCount;
this.txFullCount = txFullCount;
this.receiveErrorCount = receiveErrorCount;
this.transmitErrorCount = transmitErrorCount;
}
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.communication;
public class NIRioStatus {
public static final int kRioStatusOffset = -63000;
public static final int kRioStatusSuccess = 0;
public static final int kRIOStatusBufferInvalidSize = kRioStatusOffset - 80;
public static final int kRIOStatusOperationTimedOut = -52007;
public static final int kRIOStatusFeatureNotSupported = kRioStatusOffset - 193;
public static final int kRIOStatusResourceNotInitialized = -52010;
}

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class AccelerometerJNI extends JNIWrapper {
public static native void setAccelerometerActive(boolean active);
public static native void setAccelerometerRange(int range);
public static native double getAccelerometerX();
public static native double getAccelerometerY();
public static native double getAccelerometerZ();
}

View File

@@ -0,0 +1,12 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public enum AllianceStationID {
Red1, Red2, Red3, Blue1, Blue2, Blue3
}

View File

@@ -0,0 +1,37 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class AnalogGyroJNI extends JNIWrapper {
public static native int initializeAnalogGyro(int halAnalogInputHandle);
public static native void setupAnalogGyro(int handle);
public static native void freeAnalogGyro(int handle);
public static native void setAnalogGyroParameters(int handle,
double voltsPerDegreePerSecond,
double offset, int center);
public static native void setAnalogGyroVoltsPerDegreePerSecond(int handle,
double voltsPerDegreePerSecond);
public static native void resetAnalogGyro(int handle);
public static native void calibrateAnalogGyro(int handle);
public static native void setAnalogGyroDeadband(int handle, double volts);
public static native double getAnalogGyroAngle(int handle);
public static native double getAnalogGyroRate(int handle);
public static native double getAnalogGyroOffset(int handle);
public static native int getAnalogGyroCenter(int handle);
}

View File

@@ -0,0 +1,117 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import edu.wpi.first.wpilibj.AccumulatorResult;
import java.nio.IntBuffer;
public class AnalogJNI extends JNIWrapper {
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:58</i><br> enum values
*/
public interface AnalogTriggerType {
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:54</i>
*/
int kInWindow = 0;
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:55</i>
*/
int kState = 1;
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:56</i>
*/
int kRisingPulse = 2;
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:57</i>
*/
int kFallingPulse = 3;
}
public static native int initializeAnalogInputPort(int halPortHandle);
public static native void freeAnalogInputPort(int portHandle);
public static native int initializeAnalogOutputPort(int halPortHandle);
public static native void freeAnalogOutputPort(int portHandle);
public static native boolean checkAnalogModule(byte module);
public static native boolean checkAnalogInputChannel(int channel);
public static native boolean checkAnalogOutputChannel(int channel);
public static native void setAnalogOutput(int portHandle, double voltage);
public static native double getAnalogOutput(int portHandle);
public static native void setAnalogSampleRate(double samplesPerSecond);
public static native double getAnalogSampleRate();
public static native void setAnalogAverageBits(int analogPortHandle, int bits);
public static native int getAnalogAverageBits(int analogPortHandle);
public static native void setAnalogOversampleBits(int analogPortHandle, int bits);
public static native int getAnalogOversampleBits(int analogPortHandle);
public static native short getAnalogValue(int analogPortHandle);
public static native int getAnalogAverageValue(int analogPortHandle);
public static native int getAnalogVoltsToValue(int analogPortHandle, double voltage);
public static native double getAnalogVoltage(int analogPortHandle);
public static native double getAnalogAverageVoltage(int analogPortHandle);
public static native int getAnalogLSBWeight(int analogPortHandle);
public static native int getAnalogOffset(int analogPortHandle);
public static native boolean isAccumulatorChannel(int analogPortHandle);
public static native void initAccumulator(int analogPortHandle);
public static native void resetAccumulator(int analogPortHandle);
public static native void setAccumulatorCenter(int analogPortHandle, int center);
public static native void setAccumulatorDeadband(int analogPortHandle, int deadband);
public static native long getAccumulatorValue(int analogPortHandle);
public static native int getAccumulatorCount(int analogPortHandle);
public static native void getAccumulatorOutput(int analogPortHandle, AccumulatorResult result);
public static native int initializeAnalogTrigger(int analogInputHandle, IntBuffer index);
public static native void cleanAnalogTrigger(int analogTriggerHandle);
public static native void setAnalogTriggerLimitsRaw(int analogTriggerHandle, int lower,
int upper);
public static native void setAnalogTriggerLimitsVoltage(int analogTriggerHandle,
double lower, double upper);
public static native void setAnalogTriggerAveraged(int analogTriggerHandle,
boolean useAveragedValue);
public static native void setAnalogTriggerFiltered(int analogTriggerHandle,
boolean useFilteredValue);
public static native boolean getAnalogTriggerInWindow(int analogTriggerHandle);
public static native boolean getAnalogTriggerTriggerState(int analogTriggerHandle);
public static native boolean getAnalogTriggerOutput(int analogTriggerHandle, int type);
}

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class CompressorJNI extends JNIWrapper {
public static native int initializeCompressor(byte module);
public static native boolean checkCompressorModule(byte module);
public static native boolean getCompressor(int compressorHandle);
public static native void setCompressorClosedLoopControl(int compressorHandle, boolean value);
public static native boolean getCompressorClosedLoopControl(int compressorHandle);
public static native boolean getCompressorPressureSwitch(int compressorHandle);
public static native double getCompressorCurrent(int compressorHandle);
public static native boolean getCompressorCurrentTooHighFault(int compressorHandle);
public static native boolean getCompressorCurrentTooHighStickyFault(int compressorHandle);
public static native boolean getCompressorShortedStickyFault(int compressorHandle);
public static native boolean getCompressorShortedFault(int compressorHandle);
public static native boolean getCompressorNotConnectedStickyFault(int compressorHandle);
public static native boolean getCompressorNotConnectedFault(int compressorHandle);
public static native void clearAllPCMStickyFaults(byte compressorModule);
}

View File

@@ -0,0 +1,12 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class ConstantsJNI extends JNIWrapper {
public static native int getSystemClockTicksPerMicrosecond();
}

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
/**
* A wrapper for the HALControlWord bitfield.
*/
public class ControlWord {
private boolean m_enabled;
private boolean m_autonomous;
private boolean m_test;
private boolean m_emergencyStop;
private boolean m_fmsAttached;
private boolean m_dsAttached;
void update(boolean enabled, boolean autonomous, boolean test, boolean emergencyStop,
boolean fmsAttached, boolean dsAttached) {
m_enabled = enabled;
m_autonomous = autonomous;
m_test = test;
m_emergencyStop = emergencyStop;
m_fmsAttached = fmsAttached;
m_dsAttached = dsAttached;
}
public boolean getEnabled() {
return m_enabled;
}
public boolean getAutonomous() {
return m_autonomous;
}
public boolean getTest() {
return m_test;
}
public boolean getEStop() {
return m_emergencyStop;
}
public boolean getFMSAttached() {
return m_fmsAttached;
}
public boolean getDSAttached() {
return m_dsAttached;
}
}

View File

@@ -0,0 +1,65 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import java.nio.IntBuffer;
public class CounterJNI extends JNIWrapper {
public static native int initializeCounter(int mode, IntBuffer index);
public static native void freeCounter(int counterHandle);
public static native void setCounterAverageSize(int counterHandle, int size);
public static native void setCounterUpSource(int counterHandle, int digitalSourceHandle,
int analogTriggerType);
public static native void setCounterUpSourceEdge(int counterHandle, boolean risingEdge,
boolean fallingEdge);
public static native void clearCounterUpSource(int counterHandle);
public static native void setCounterDownSource(int counterHandle, int digitalSourceHandle,
int analogTriggerType);
public static native void setCounterDownSourceEdge(int counterHandle, boolean risingEdge,
boolean fallingEdge);
public static native void clearCounterDownSource(int counterHandle);
public static native void setCounterUpDownMode(int counterHandle);
public static native void setCounterExternalDirectionMode(int counterHandle);
public static native void setCounterSemiPeriodMode(int counterHandle,
boolean highSemiPeriod);
public static native void setCounterPulseLengthMode(int counterHandle, double threshold);
public static native int getCounterSamplesToAverage(int counterHandle);
public static native void setCounterSamplesToAverage(int counterHandle,
int samplesToAverage);
public static native void resetCounter(int counterHandle);
public static native int getCounter(int counterHandle);
public static native double getCounterPeriod(int counterHandle);
public static native void setCounterMaxPeriod(int counterHandle, double maxPeriod);
public static native void setCounterUpdateWhenEmpty(int counterHandle, boolean enabled);
public static native boolean getCounterStopped(int counterHandle);
public static native boolean getCounterDirection(int counterHandle);
public static native void setCounterReverseDirection(int counterHandle,
boolean reverseDirection);
}

View File

@@ -0,0 +1,44 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
@SuppressWarnings("AbbreviationAsWordInName")
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);
// 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);
public static native void pulse(int dioPortHandle, double pulseLength);
public static native boolean isPulsing(int dioPortHandle);
public static native boolean isAnyPulsing();
public static native short getLoopTiming();
public static native int allocateDigitalPWM();
public static native void freeDigitalPWM(int pwmGenerator);
public static native void setDigitalPWMRate(double rate);
public static native void setDigitalPWMDutyCycle(int pwmGenerator, double dutyCycle);
public static native void setDigitalPWMOutputChannel(int pwmGenerator, int channel);
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class DigitalGlitchFilterJNI extends JNIWrapper {
public static native void setFilterSelect(int digitalPortHandle, int filterIndex);
public static native int getFilterSelect(int digitalPortHandle);
public static native void setFilterPeriod(int filterIndex, int fpgaCycles);
public static native int getFilterPeriod(int filterIndex);
}

View File

@@ -0,0 +1,62 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class EncoderJNI extends JNIWrapper {
public static native int initializeEncoder(int digitalSourceHandleA, int analogTriggerTypeA,
int digitalSourceHandleB, int analogTriggerTypeB,
boolean reverseDirection, int encodingType);
public static native void freeEncoder(int encoderHandle);
public static native int getEncoder(int encoderHandle);
public static native int getEncoderRaw(int encoderHandle);
public static native int getEncodingScaleFactor(int encoderHandle);
public static native void resetEncoder(int encoderHandle);
public static native double getEncoderPeriod(int encoderHandle);
public static native void setEncoderMaxPeriod(int encoderHandle, double maxPeriod);
public static native boolean getEncoderStopped(int encoderHandle);
public static native boolean getEncoderDirection(int encoderHandle);
public static native double getEncoderDistance(int encoderHandle);
public static native double getEncoderRate(int encoderHandle);
public static native void setEncoderMinRate(int encoderHandle, double minRate);
public static native void setEncoderDistancePerPulse(int encoderHandle, double distancePerPulse);
public static native void setEncoderReverseDirection(int encoderHandle,
boolean reverseDirection);
public static native void setEncoderSamplesToAverage(int encoderHandle,
int samplesToAverage);
public static native int getEncoderSamplesToAverage(int encoderHandle);
public static native void setEncoderIndexSource(int encoderHandle, int digitalSourceHandle,
int analogTriggerType, int indexingType);
@SuppressWarnings("AbbreviationAsWordInName")
public static native int getEncoderFPGAIndex(int encoderHandle);
public static native int getEncoderEncodingScale(int encoderHandle);
public static native double getEncoderDecodingScaleFactor(int encoderHandle);
public static native double getEncoderDistancePerPulse(int encoderHandle);
public static native int getEncoderEncodingType(int encoderHandle);
}

View File

@@ -0,0 +1,160 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
/**
* JNI wrapper for library <b>FRC_NetworkCommunication</b><br>.
*/
@SuppressWarnings("MethodName")
public class FRCNetComm extends JNIWrapper {
/**
* Module type from LoadOut.h
*/
@SuppressWarnings("TypeName")
public interface tModuleType {
int kModuleType_Unknown = 0x00;
int kModuleType_Analog = 0x01;
int kModuleType_Digital = 0x02;
int kModuleType_Solenoid = 0x03;
}
/**
* Target class from LoadOut.h
*/
@SuppressWarnings("TypeName")
public interface tTargetClass {
int kTargetClass_Unknown = 0x00;
int kTargetClass_FRC1 = 0x10;
int kTargetClass_FRC2 = 0x20;
int kTargetClass_FRC3 = 0x30;
int kTargetClass_RoboRIO = 0x40;
int kTargetClass_FRC2_Analog = kTargetClass_FRC2 | tModuleType.kModuleType_Analog;
int kTargetClass_FRC2_Digital = kTargetClass_FRC2 | tModuleType.kModuleType_Digital;
int kTargetClass_FRC2_Solenoid = kTargetClass_FRC2 | tModuleType.kModuleType_Solenoid;
int kTargetClass_FamilyMask = 0xF0;
int kTargetClass_ModuleMask = 0x0F;
}
/**
* Resource type from UsageReporting.h
*/
@SuppressWarnings("TypeName")
public interface tResourceType {
int kResourceType_Controller = 0;
int kResourceType_Module = 1;
int kResourceType_Language = 2;
int kResourceType_CANPlugin = 3;
int kResourceType_Accelerometer = 4;
int kResourceType_ADXL345 = 5;
int kResourceType_AnalogChannel = 6;
int kResourceType_AnalogTrigger = 7;
int kResourceType_AnalogTriggerOutput = 8;
int kResourceType_CANJaguar = 9;
int kResourceType_Compressor = 10;
int kResourceType_Counter = 11;
int kResourceType_Dashboard = 12;
int kResourceType_DigitalInput = 13;
int kResourceType_DigitalOutput = 14;
int kResourceType_DriverStationCIO = 15;
int kResourceType_DriverStationEIO = 16;
int kResourceType_DriverStationLCD = 17;
int kResourceType_Encoder = 18;
int kResourceType_GearTooth = 19;
int kResourceType_Gyro = 20;
int kResourceType_I2C = 21;
int kResourceType_Framework = 22;
int kResourceType_Jaguar = 23;
int kResourceType_Joystick = 24;
int kResourceType_Kinect = 25;
int kResourceType_KinectStick = 26;
int kResourceType_PIDController = 27;
int kResourceType_Preferences = 28;
int kResourceType_PWM = 29;
int kResourceType_Relay = 30;
int kResourceType_RobotDrive = 31;
int kResourceType_SerialPort = 32;
int kResourceType_Servo = 33;
int kResourceType_Solenoid = 34;
int kResourceType_SPI = 35;
int kResourceType_Task = 36;
int kResourceType_Ultrasonic = 37;
int kResourceType_Victor = 38;
int kResourceType_Button = 39;
int kResourceType_Command = 40;
int kResourceType_AxisCamera = 41;
int kResourceType_PCVideoServer = 42;
int kResourceType_SmartDashboard = 43;
int kResourceType_Talon = 44;
int kResourceType_HiTechnicColorSensor = 45;
int kResourceType_HiTechnicAccel = 46;
int kResourceType_HiTechnicCompass = 47;
int kResourceType_SRF08 = 48;
int kResourceType_AnalogOutput = 49;
int kResourceType_VictorSP = 50;
int kResourceType_PWMTalonSRX = 51;
int kResourceType_CANTalonSRX = 52;
int kResourceType_ADXL362 = 53;
int kResourceType_ADXRS450 = 54;
int kResourceType_RevSPARK = 55;
int kResourceType_MindsensorsSD540 = 56;
int kResourceType_DigitalFilter = 57;
int kResourceType_ADIS16448 = 58;
int kResourceType_PDP = 59;
int kResourceType_PCM = 60;
int kResourceType_PigeonIMU = 61;
int kResourceType_NidecBrushless = 62;
}
/**
* Instances from UsageReporting.h
*/
@SuppressWarnings("TypeName")
public interface tInstances {
int kLanguage_LabVIEW = 1;
int kLanguage_CPlusPlus = 2;
int kLanguage_Java = 3;
int kLanguage_Python = 4;
int kCANPlugin_BlackJagBridge = 1;
int kCANPlugin_2CAN = 2;
int kFramework_Iterative = 1;
int kFramework_Simple = 2;
int kFramework_CommandControl = 3;
int kRobotDrive_ArcadeStandard = 1;
int kRobotDrive_ArcadeButtonSpin = 2;
int kRobotDrive_ArcadeRatioCurve = 3;
int kRobotDrive_Tank = 4;
int kRobotDrive_MecanumPolar = 5;
int kRobotDrive_MecanumCartesian = 6;
int kDriverStationCIO_Analog = 1;
int kDriverStationCIO_DigitalIn = 2;
int kDriverStationCIO_DigitalOut = 3;
int kDriverStationEIO_Acceleration = 1;
int kDriverStationEIO_AnalogIn = 2;
int kDriverStationEIO_AnalogOut = 3;
int kDriverStationEIO_Button = 4;
int kDriverStationEIO_LED = 5;
int kDriverStationEIO_DigitalIn = 6;
int kDriverStationEIO_DigitalOut = 7;
int kDriverStationEIO_FixedDigitalOut = 8;
int kDriverStationEIO_PWM = 9;
int kDriverStationEIO_Encoder = 10;
int kDriverStationEIO_TouchSlider = 11;
int kADXL345_SPI = 1;
int kADXL345_I2C = 2;
int kCommand_Scheduler = 1;
int kSmartDashboard_Instance = 1;
}
}

View File

@@ -0,0 +1,130 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import java.nio.ByteBuffer;
/**
* JNI Wrapper for HAL<br>.
*/
@SuppressWarnings({"AbbreviationAsWordInName", "MethodName"})
public class HAL extends JNIWrapper {
public static native void waitForDSData();
public static native boolean initialize(int timeout, int mode);
public static native void observeUserProgramStarting();
public static native void observeUserProgramDisabled();
public static native void observeUserProgramAutonomous();
public static native void observeUserProgramTeleop();
public static native void observeUserProgramTest();
public static void report(int resource, int instanceNumber) {
report(resource, instanceNumber, 0, "");
}
public static void report(int resource, int instanceNumber, int context) {
report(resource, instanceNumber, context, "");
}
/**
* Report the usage of a resource of interest. <br>
*
* <p>Original signature: <code>uint32_t report(tResourceType, uint8_t, uint8_t, const
* char*)</code>
*
* @param resource one of the values in the tResourceType above (max value 51). <br>
* @param instanceNumber an index that identifies the resource instance. <br>
* @param context an optional additional context number for some cases (such as module
* number). Set to 0 to omit. <br>
* @param feature a string to be included describing features in use on a specific
* resource. Setting the same resource more than once allows you to change
* the feature string.
*/
public static native int report(int resource, int instanceNumber, int context, String feature);
public static native int nativeGetControlWord();
@SuppressWarnings("JavadocMethod")
public static void getControlWord(ControlWord controlWord) {
int word = nativeGetControlWord();
controlWord.update((word & 1) != 0, ((word >> 1) & 1) != 0, ((word >> 2) & 1) != 0,
((word >> 3) & 1) != 0, ((word >> 4) & 1) != 0, ((word >> 5) & 1) != 0);
}
private static native int nativeGetAllianceStation();
@SuppressWarnings("JavadocMethod")
public static AllianceStationID getAllianceStation() {
switch (nativeGetAllianceStation()) {
case 0:
return AllianceStationID.Red1;
case 1:
return AllianceStationID.Red2;
case 2:
return AllianceStationID.Red3;
case 3:
return AllianceStationID.Blue1;
case 4:
return AllianceStationID.Blue2;
case 5:
return AllianceStationID.Blue3;
default:
return null;
}
}
@SuppressWarnings("JavadocMethod")
public static native boolean isNewControlData();
@SuppressWarnings("JavadocMethod")
public static native void releaseDSMutex();
@SuppressWarnings("JavadocMethod")
public static native boolean waitForDSDataTimeout(double timeout);
public static int kMaxJoystickAxes = 12;
public static int kMaxJoystickPOVs = 12;
public static native short getJoystickAxes(byte joystickNum, float[] axesArray);
public static native short getJoystickPOVs(byte joystickNum, short[] povsArray);
public static native int getJoystickButtons(byte joystickNum, ByteBuffer count);
public static native int setJoystickOutputs(byte joystickNum, int outputs, short leftRumble,
short rightRumble);
public static native int getJoystickIsXbox(byte joystickNum);
public static native int getJoystickType(byte joystickNum);
public static native String getJoystickName(byte joystickNum);
public static native int getJoystickAxisType(byte joystickNum, byte axis);
public static native double getMatchTime();
public static native boolean getSystemActive();
public static native boolean getBrownedOut();
public static native int getMatchInfo(MatchInfoData info);
public static native int sendError(boolean isError, int errorCode, boolean isLVCode,
String details, String location, String callStack,
boolean printMsg);
public static native int getPortWithModule(byte module, byte channel);
public static native int getPort(byte channel);
}

View File

@@ -0,0 +1,40 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
@SuppressWarnings("AbbreviationAsWordInName")
public class HALUtil extends JNIWrapper {
public static final int NULL_PARAMETER = -1005;
public static final int SAMPLE_RATE_TOO_HIGH = 1001;
public static final int VOLTAGE_OUT_OF_RANGE = 1002;
public static final int LOOP_TIMING_ERROR = 1004;
public static final int INCOMPATIBLE_STATE = 1015;
public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -1011;
public static final int NO_AVAILABLE_RESOURCES = -104;
public static final int PARAMETER_OUT_OF_RANGE = -1028;
public static native short getFPGAVersion();
public static native int getFPGARevision();
public static native long getFPGATime();
public static native int getHALRuntimeType();
public static native boolean getFPGAButton();
public static native String getHALErrorMessage(int code);
public static native int getHALErrno();
public static native String getHALstrerror(int errno);
public static String getHALstrerror() {
return getHALstrerror(getHALErrno());
}
}

View File

@@ -0,0 +1,33 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import java.nio.ByteBuffer;
@SuppressWarnings("AbbreviationAsWordInName")
public class I2CJNI extends JNIWrapper {
public static native void i2CInitialize(int port);
public static native int i2CTransaction(int port, byte address, ByteBuffer dataToSend,
byte sendSize, ByteBuffer dataReceived, byte receiveSize);
public static native int i2CTransactionB(int port, byte address, byte[] dataToSend,
byte sendSize, byte[] dataReceived, byte receiveSize);
public static native int i2CWrite(int port, byte address, ByteBuffer dataToSend, byte sendSize);
public static native int i2CWriteB(int port, byte address, byte[] dataToSend, byte sendSize);
public static native int i2CRead(int port, byte address, ByteBuffer dataReceived,
byte receiveSize);
public static native int i2CReadB(int port, byte address, byte[] dataReceived,
byte receiveSize);
public static native void i2CClose(int port);
}

View File

@@ -0,0 +1,41 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class InterruptJNI extends JNIWrapper {
public static final int HalInvalidHandle = 0;
public interface InterruptJNIHandlerFunction {
void apply(int interruptAssertedMask, Object param);
}
public static native int initializeInterrupts(boolean watcher);
public static native void cleanInterrupts(int interruptHandle);
public static native int waitForInterrupt(int interruptHandle, double timeout,
boolean ignorePrevious);
public static native void enableInterrupts(int interruptHandle);
public static native void disableInterrupts(int interruptHandle);
public static native double readInterruptRisingTimestamp(int interruptHandle);
public static native double readInterruptFallingTimestamp(int interruptHandle);
public static native void requestInterrupts(int interruptHandle, int digitalSourceHandle,
int analogTriggerType);
public static native void attachInterruptHandler(int interruptHandle,
InterruptJNIHandlerFunction handler,
Object param);
public static native void setInterruptUpSourceEdge(int interruptHandle, boolean risingEdge,
boolean fallingEdge);
}

View File

@@ -0,0 +1,68 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import edu.wpi.first.wpiutil.RuntimeDetector;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Base class for all JNI wrappers.
*/
public class JNIWrapper {
static boolean libraryLoaded = false;
static File jniLibrary = null;
static {
if (!libraryLoaded) {
String jniFileName = "wpiHal";
try {
System.loadLibrary(jniFileName);
} catch (UnsatisfiedLinkError ule) {
try {
String resname = RuntimeDetector.getLibraryResource(jniFileName);
InputStream is = JNIWrapper.class.getResourceAsStream(resname);
if (is != null) {
// create temporary file
if (System.getProperty("os.name").startsWith("Windows")) {
jniLibrary = File.createTempFile(jniFileName, ".dll");
} else if (System.getProperty("os.name").startsWith("Mac")) {
jniLibrary = File.createTempFile(jniFileName, ".dylib");
} else {
jniLibrary = File.createTempFile(jniFileName, ".so");
}
// flag for delete on exit
jniLibrary.deleteOnExit();
OutputStream os = new FileOutputStream(jniLibrary);
byte[] buffer = new byte[1024];
int readBytes;
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
} finally {
os.close();
is.close();
}
System.load(jniLibrary.getAbsolutePath());
} else {
System.loadLibrary(jniFileName);
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
libraryLoaded = true;
}
}
}

View File

@@ -0,0 +1,56 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
/**
* Structure for holding the match info data request.
*/
public class MatchInfoData {
/**
* Stores the event name.
*/
@SuppressWarnings("MemberName")
public String eventName = "";
/**
* Stores the game specific message.
*/
@SuppressWarnings("MemberName")
public String gameSpecificMessage = "";
/**
* Stores the match number.
*/
@SuppressWarnings("MemberName")
public int matchNumber;
/**
* Stores the replay number.
*/
@SuppressWarnings("MemberName")
public int replayNumber;
/**
* Stores the match type.
*/
@SuppressWarnings("MemberName")
public int matchType;
/**
* Called from JNI to set the structure data.
*/
@SuppressWarnings("JavadocMethod")
public void setData(String eventName, String gameSpecificMessage,
int matchNumber, int replayNumber, int matchType) {
this.eventName = eventName;
this.gameSpecificMessage = gameSpecificMessage;
this.matchNumber = matchNumber;
this.replayNumber = replayNumber;
this.matchType = matchType;
}
}

View File

@@ -0,0 +1,49 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
/**
* The NotifierJNI class directly wraps the C++ HAL Notifier.
*
* <p>This class is not meant for direct use by teams. Instead, the edu.wpi.first.wpilibj.Notifier
* class, which corresponds to the C++ Notifier class, should be used.
*/
public class NotifierJNI extends JNIWrapper {
/**
* Initializes the notifier.
*/
public static native int initializeNotifier();
/**
* Wakes up the waiter with time=0. Note: after this function is called, all
* calls to waitForNotifierAlarm() will immediately start returning 0.
*/
public static native void stopNotifier(int notifierHandle);
/**
* Deletes the notifier object when we are done with it.
*/
public static native void cleanNotifier(int notifierHandle);
/**
* Sets the notifier to wakeup the waiter in another triggerTime microseconds.
*/
public static native void updateNotifierAlarm(int notifierHandle, long triggerTime);
/**
* Cancels any pending wakeups set by updateNotifierAlarm(). Does NOT wake
* up any waiters.
*/
public static native void cancelNotifierAlarm(int notifierHandle);
/**
* Block until woken up by an alarm (or stop).
* @return Time when woken up.
*/
public static native long waitForNotifierAlarm(int notifierHandle);
}

View File

@@ -0,0 +1,46 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class OSSerialPortJNI extends JNIWrapper {
public static native void serialInitializePort(byte port);
public static native void serialSetBaudRate(byte port, int baud);
public static native void serialSetDataBits(byte port, byte bits);
public static native void serialSetParity(byte port, byte parity);
public static native void serialSetStopBits(byte port, byte stopBits);
public static native void serialSetWriteMode(byte port, byte mode);
public static native void serialSetFlowControl(byte port, byte flow);
public static native void serialSetTimeout(byte port, double timeout);
public static native void serialEnableTermination(byte port, char terminator);
public static native void serialDisableTermination(byte port);
public static native void serialSetReadBufferSize(byte port, int size);
public static native void serialSetWriteBufferSize(byte port, int size);
public static native int serialGetBytesReceived(byte port);
public static native int serialRead(byte port, byte[] buffer, int count);
public static native int serialWrite(byte port, byte[] buffer, int count);
public static native void serialFlush(byte port);
public static native void serialClear(byte port);
public static native void serialClose(byte port);
}

View File

@@ -0,0 +1,33 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
@SuppressWarnings("AbbreviationAsWordInName")
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);
public static native double getPDPChannelCurrent(byte channel, int module);
public static native double getPDPTotalCurrent(int module);
public static native double getPDPTotalPower(int module);
public static native double getPDPTotalEnergy(int module);
public static native void resetPDPTotalEnergy(int module);
public static native void clearPDPStickyFaults(int module);
}

View File

@@ -0,0 +1,51 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import edu.wpi.first.wpilibj.PWMConfigDataResult;
@SuppressWarnings("AbbreviationAsWordInName")
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,
int deadbandMaxPwm, int centerPwm,
int deadbandMinPwm, int minPwm);
public static native void setPWMConfig(int pwmPortHandle, double maxPwm,
double deadbandMaxPwm, double centerPwm,
double deadbandMinPwm, double minPwm);
public static native PWMConfigDataResult getPWMConfigRaw(int pwmPortHandle);
public static native void setPWMEliminateDeadband(int pwmPortHandle, boolean eliminateDeadband);
public static native boolean getPWMEliminateDeadband(int pwmPortHandle);
public static native void setPWMRaw(int pwmPortHandle, short value);
public static native void setPWMSpeed(int pwmPortHandle, double speed);
public static native void setPWMPosition(int pwmPortHandle, double position);
public static native short getPWMRaw(int pwmPortHandle);
public static native double getPWMSpeed(int pwmPortHandle);
public static native double getPWMPosition(int pwmPortHandle);
public static native void setPWMDisabled(int pwmPortHandle);
public static native void latchPWMZero(int pwmPortHandle);
public static native void setPWMPeriodScale(int pwmPortHandle, int squelchMask);
}

View File

@@ -0,0 +1,46 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class PortsJNI extends JNIWrapper {
public static native int getNumAccumulators();
public static native int getNumAnalogTriggers();
public static native int getNumAnalogInputs();
public static native int getNumAnalogOutputs();
public static native int getNumCounters();
public static native int getNumDigitalHeaders();
public static native int getNumPWMHeaders();
public static native int getNumDigitalChannels();
public static native int getNumPWMChannels();
public static native int getNumDigitalPWMOutputs();
public static native int getNumEncoders();
public static native int getNumInterrupts();
public static native int getNumRelayChannels();
public static native int getNumRelayHeaders();
public static native int getNumPCMModules();
public static native int getNumSolenoidChannels();
public static native int getNumPDPModules();
public static native int getNumPDPChannels();
}

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class PowerJNI extends JNIWrapper {
public static native double getVinVoltage();
public static native double getVinCurrent();
public static native double getUserVoltage6V();
public static native double getUserCurrent6V();
public static native boolean getUserActive6V();
public static native int getUserCurrentFaults6V();
public static native double getUserVoltage5V();
public static native double getUserCurrent5V();
public static native boolean getUserActive5V();
public static native int getUserCurrentFaults5V();
public static native double getUserVoltage3V3();
public static native double getUserCurrent3V3();
public static native boolean getUserActive3V3();
public static native int getUserCurrentFaults3V3();
}

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class RelayJNI extends DIOJNI {
public static native int initializeRelayPort(int halPortHandle, boolean forward);
public static native void freeRelayPort(int relayPortHandle);
public static native boolean checkRelayChannel(int channel);
public static native void setRelay(int relayPortHandle, boolean on);
public static native boolean getRelay(int relayPortHandle);
}

View File

@@ -0,0 +1,64 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import java.nio.ByteBuffer;
@SuppressWarnings("AbbreviationAsWordInName")
public class SPIJNI extends JNIWrapper {
public static native void spiInitialize(int port);
public static native int spiTransaction(int port, ByteBuffer dataToSend,
ByteBuffer dataReceived, byte size);
public static native int spiTransactionB(int port, byte[] dataToSend,
byte[] dataReceived, byte size);
public static native int spiWrite(int port, ByteBuffer dataToSend, byte sendSize);
public static native int spiWriteB(int port, byte[] dataToSend, byte sendSize);
public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, byte size);
public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, byte size);
public static native void spiClose(int port);
public static native void spiSetSpeed(int port, int speed);
public static native void spiSetOpts(int port, int msbFirst, int sampleOnTrailing,
int clkIdleHigh);
public static native void spiSetChipSelectActiveHigh(int port);
public static native void spiSetChipSelectActiveLow(int port);
public static native void spiInitAuto(int port, int bufferSize);
public static native void spiFreeAuto(int port);
public static native void spiStartAutoRate(int port, double period);
public static native void spiStartAutoTrigger(int port, int digitalSourceHandle,
int analogTriggerType, boolean triggerRising,
boolean triggerFalling);
public static native void spiStopAuto(int port);
public static native void spiSetAutoTransmitData(int port, byte[] dataToSend, int zeroSize);
public static native void spiForceAutoRead(int port);
public static native int spiReadAutoReceivedData(int port, ByteBuffer buffer, int numToRead,
double timeout);
public static native int spiReadAutoReceivedData(int port, byte[] buffer, int numToRead,
double timeout);
public static native int spiGetAutoDroppedCount(int port);
}

View File

@@ -0,0 +1,48 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class SerialPortJNI extends JNIWrapper {
public static native void serialInitializePort(byte port);
public static native void serialInitializePortDirect(byte port, String portName);
public static native void serialSetBaudRate(byte port, int baud);
public static native void serialSetDataBits(byte port, byte bits);
public static native void serialSetParity(byte port, byte parity);
public static native void serialSetStopBits(byte port, byte stopBits);
public static native void serialSetWriteMode(byte port, byte mode);
public static native void serialSetFlowControl(byte port, byte flow);
public static native void serialSetTimeout(byte port, double timeout);
public static native void serialEnableTermination(byte port, char terminator);
public static native void serialDisableTermination(byte port);
public static native void serialSetReadBufferSize(byte port, int size);
public static native void serialSetWriteBufferSize(byte port, int size);
public static native int serialGetBytesReceived(byte port);
public static native int serialRead(byte port, byte[] buffer, int count);
public static native int serialWrite(byte port, byte[] buffer, int count);
public static native void serialFlush(byte port);
public static native void serialClear(byte port);
public static native void serialClose(byte port);
}

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
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);
public static native boolean getSolenoid(int portHandle);
public static native int getAllSolenoids(int module);
public static native int getPCMSolenoidBlackList(int module);
public static native boolean getPCMSolenoidVoltageStickyFault(int module);
public static native boolean getPCMSolenoidVoltageFault(int module);
public static native void clearAllPCMStickyFaults(int module);
public static native void setOneShotDuration(int portHandle, long durationMS);
public static native void fireOneShot(int portHandle);
}

View File

@@ -0,0 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
public class ThreadsJNI extends JNIWrapper {
public static native int getCurrentThreadPriority();
public static native boolean getCurrentThreadIsRealTime();
public static native boolean setCurrentThreadPriority(boolean realTime, int priority);
}

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* Exception indicating that the resource is already allocated.
*/
public class AllocationException extends RuntimeException {
/**
* Create a new AllocationException.
*
* @param msg the message to attach to the exception
*/
public AllocationException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* Thrown if there is an error caused by a basic system or setting not being properly initialized
* before being used.
*/
public class BaseSystemNotInitializedException extends RuntimeException {
/**
* Create a new BaseSystemNotInitializedException.
*
* @param message the message to attach to the exception
*/
public BaseSystemNotInitializedException(String message) {
super(message);
}
/**
* Create a new BaseSystemNotInitializedException using the offending class that was not set and
* the class that was affected.
*
* @param offender The class or interface that was not properly initialized.
* @param affected The class that was was affected by this missing initialization.
*/
public BaseSystemNotInitializedException(Class<?> offender, Class<?> affected) {
super("The " + offender.getSimpleName() + " for the " + affected.getSimpleName()
+ " was never set.");
}
}

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* This exception represents an error in which a lower limit was set as higher than an upper limit.
*/
public class BoundaryException extends RuntimeException {
/**
* Create a new exception with the given message.
*
* @param message the message to attach to the exception
*/
public BoundaryException(String message) {
super(message);
}
/**
* Make sure that the given value is between the upper and lower bounds, and throw an exception if
* they are not.
*
* @param value The value to check.
* @param lower The minimum acceptable value.
* @param upper The maximum acceptable value.
*/
public static void assertWithinBounds(double value, double lower, double upper) {
if (value < lower || value > upper) {
throw new BoundaryException("Value must be between " + lower + " and " + upper + ", " + value
+ " given");
}
}
/**
* Returns the message for a boundary exception. Used to keep the message consistent across all
* boundary exceptions.
*
* @param value The given value
* @param lower The lower limit
* @param upper The upper limit
* @return the message for a boundary exception
*/
public static String getMessage(double value, double lower, double upper) {
return "Value must be between " + lower + " and " + upper + ", " + value + " given";
}
}

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* Exception indicating that the resource is already allocated This is meant to be thrown by the
* resource class.
*/
public class CheckedAllocationException extends Exception {
/**
* Create a new CheckedAllocationException.
*
* @param msg the message to attach to the exception
*/
public CheckedAllocationException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* Exception indicating that an error has occured with a HAL Handle.
*/
public class HalHandleException extends RuntimeException {
/**
* Create a new HalHandleException.
*
* @param msg the message to attach to the exception
*/
public HalHandleException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,60 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.util;
/**
* Exception for bad status codes from the chip object.
*/
public final class UncleanStatusException extends IllegalStateException {
private final int m_statusCode;
/**
* Create a new UncleanStatusException.
*
* @param status the status code that caused the exception
* @param message A message describing the exception
*/
public UncleanStatusException(int status, String message) {
super(message);
m_statusCode = status;
}
/**
* Create a new UncleanStatusException.
*
* @param status the status code that caused the exception
*/
public UncleanStatusException(int status) {
this(status, "Status code was non-zero");
}
/**
* Create a new UncleanStatusException.
*
* @param message a message describing the exception
*/
public UncleanStatusException(String message) {
this(-1, message);
}
/**
* Create a new UncleanStatusException.
*/
public UncleanStatusException() {
this(-1, "Status code was non-zero");
}
/**
* Create a new UncleanStatusException.
*
* @return the status code that caused the exception
*/
public int getStatus() {
return m_statusCode;
}
}