Switches Java to use HAL Constants (#145)

This commit is contained in:
Thad House
2016-07-08 00:08:07 -07:00
committed by Peter Johnson
parent 4a3e3a6324
commit be2647d44e
22 changed files with 857 additions and 8 deletions

View File

@@ -0,0 +1,14 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
extern "C" {
int32_t HAL_getSystemClockTicksPerMicrosecond(void);
}

View File

@@ -16,6 +16,7 @@
#include "AnalogOutput.h"
#include "AnalogTrigger.h"
#include "Compressor.h"
#include "Constants.h"
#include "Counter.h"
#include "DIO.h"
#include "Errors.h"
@@ -104,8 +105,6 @@ struct HALJoystickDescriptor {
};
extern "C" {
extern const uint32_t kSystemClockTicksPerMicrosecond;
HalPortHandle getPort(uint8_t pin);
HalPortHandle getPortWithModule(uint8_t module, uint8_t pin);
const char* getHALErrorMessage(int32_t code);

View File

@@ -27,5 +27,6 @@ int32_t HAL_getNumRelayHeaders(void);
int32_t HAL_getNumPCMModules(void);
int32_t HAL_getNumSolenoidPins(void);
int32_t HAL_getNumPDPModules(void);
int32_t HAL_getNumPDPChannels(void);
int32_t HAL_getNumCanTalons(void);
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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. */
/*----------------------------------------------------------------------------*/
#include "HAL/Constants.h"
#include "ConstantsInternal.h"
using namespace hal;
extern "C" {
int32_t HAL_getSystemClockTicksPerMicrosecond(void) {
return kSystemClockTicksPerMicrosecond;
}
}

View File

@@ -0,0 +1,14 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
namespace hal {
constexpr int32_t kSystemClockTicksPerMicrosecond = 40;
}

View File

@@ -7,6 +7,7 @@
#include "HAL/Counter.h"
#include "ConstantsInternal.h"
#include "DigitalInternal.h"
#include "HAL/HAL.h"
#include "PortsInternal.h"

View File

@@ -11,6 +11,7 @@
#include <thread>
#include "ChipObject.h"
#include "ConstantsInternal.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/AnalogTrigger.h"
#include "HAL/HAL.h"

View File

@@ -29,5 +29,6 @@ int32_t HAL_getNumRelayHeaders(void) { return kNumRelayHeaders; }
int32_t HAL_getNumPCMModules(void) { return kNumPCMModules; }
int32_t HAL_getNumSolenoidPins(void) { return kNumSolenoidPins; }
int32_t HAL_getNumPDPModules(void) { return kNumPDPModules; }
int32_t HAL_getNumPDPChannels(void) { return kNumPDPChannels; }
int32_t HAL_getNumCanTalons(void) { return kNumCanTalons; }
}

View File

@@ -30,5 +30,6 @@ constexpr int32_t kNumRelayHeaders = kNumRelayPins / 2;
constexpr int32_t kNumPCMModules = 63;
constexpr int32_t kNumSolenoidPins = 8;
constexpr int32_t kNumPDPModules = 63;
constexpr int32_t kNumPDPChannels = 16;
constexpr int32_t kNumCanTalons = 63;
}

View File

@@ -159,7 +159,7 @@ void DigitalGlitchFilter::SetPeriodCycles(uint32_t fpga_cycles) {
void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
int32_t status = 0;
uint32_t fpga_cycles =
nanoseconds * kSystemClockTicksPerMicrosecond / 4 / 1000;
nanoseconds * HAL_getSystemClockTicksPerMicrosecond() / 4 / 1000;
setFilterPeriod(m_channelIndex, fpga_cycles, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
@@ -191,5 +191,5 @@ uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
return static_cast<uint64_t>(fpga_cycles) * 1000L /
static_cast<uint64_t>(kSystemClockTicksPerMicrosecond / 4);
static_cast<uint64_t>(HAL_getSystemClockTicksPerMicrosecond() / 4);
}

View File

@@ -126,7 +126,7 @@ void PWM::SetBounds(double max, double deadbandMax, double center,
// calculate the loop time in milliseconds
int32_t status = 0;
double loopTime =
getLoopTiming(&status) / (kSystemClockTicksPerMicrosecond * 1e3);
getLoopTiming(&status) / (HAL_getSystemClockTicksPerMicrosecond() * 1e3);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
if (StatusIsFatal()) return;

View File

@@ -160,6 +160,7 @@ task jniHeaders {
args 'edu.wpi.first.wpilibj.hal.AnalogJNI'
args 'edu.wpi.first.wpilibj.hal.AnalogGyroJNI'
args 'edu.wpi.first.wpilibj.hal.CanTalonJNI'
args 'edu.wpi.first.wpilibj.hal.ConstantsJNI'
args 'edu.wpi.first.wpilibj.hal.CounterJNI'
args 'edu.wpi.first.wpilibj.hal.DigitalGlitchFilterJNI'
args 'edu.wpi.first.wpilibj.hal.DIOJNI'
@@ -167,6 +168,7 @@ task jniHeaders {
args 'edu.wpi.first.wpilibj.hal.I2CJNI'
args 'edu.wpi.first.wpilibj.hal.InterruptJNI'
args 'edu.wpi.first.wpilibj.hal.NotifierJNI'
args 'edu.wpi.first.wpilibj.hal.PortsJNI'
args 'edu.wpi.first.wpilibj.hal.PWMJNI'
args 'edu.wpi.first.wpilibj.hal.RelayJNI'
args 'edu.wpi.first.wpilibj.hal.SPIJNI'

View File

@@ -0,0 +1,40 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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. */
/*----------------------------------------------------------------------------*/
#include <assert.h>
#include <jni.h>
#include "Log.h"
#include "edu_wpi_first_wpilibj_hal_ConstantsJNI.h"
#include "HAL/Constants.h"
#include "HALUtil.h"
// set the logging level
TLogLevel constantsJNILogLevel = logWARNING;
#define CONSTANTSJNI_LOG(level) \
if (level > constantsJNILogLevel) \
; \
else \
Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_ConstantsJNI
* Method: getSystemClockTicksPerMicrosecond
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_ConstantsJNI_getSystemClockTicksPerMicrosecond(
JNIEnv *env, jclass) {
CONSTANTSJNI_LOG(logDEBUG) << "Calling ConstantsJNI getSystemClockTicksPerMicrosecond";
jint value = HAL_getSystemClockTicksPerMicrosecond();
CONSTANTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
}

View File

@@ -0,0 +1,310 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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. */
/*----------------------------------------------------------------------------*/
#include <assert.h>
#include <jni.h>
#include "Log.h"
#include "edu_wpi_first_wpilibj_hal_PortsJNI.h"
#include "HAL/Ports.h"
#include "HALUtil.h"
// set the logging level
TLogLevel portsJNILogLevel = logWARNING;
#define PORTSJNI_LOG(level) \
if (level > portsJNILogLevel) \
; \
else \
Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumAccumulators
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAccumulators(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAccumulators";
jint value = HAL_getNumAccumulators();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumAnalogTriggers
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogTriggers(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogTriggers";
jint value = HAL_getNumAnalogTriggers();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumAnalogInputs
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogInputs(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogInputs";
jint value = HAL_getNumAnalogInputs();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumAnalogOutputs
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumAnalogOutputs(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumAnalogOutputs";
jint value = HAL_getNumAnalogOutputs();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumCounters
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumCounters(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumCounters";
jint value = HAL_getNumCounters();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumDigitalHeaders
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalHeaders(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalHeaders";
jint value = HAL_getNumDigitalHeaders();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPWMHeaders
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMHeaders(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMHeaders";
jint value = HAL_getNumPWMHeaders();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumDigitalPins
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPins(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalPins";
jint value = HAL_getNumDigitalPins();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPWMPins
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMPins(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMPins";
jint value = HAL_getNumPWMPins();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumDigitalPWMOutputs
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPWMOutputs(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalPWMOutputs";
jint value = HAL_getNumDigitalPWMOutputs();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumEncoders
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumEncoders(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumEncoders";
jint value = HAL_getNumEncoders();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumInterrupts
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumInterrupts(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumInterrupts";
jint value = HAL_getNumInterrupts();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumRelayPins
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayPins(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayPins";
jint value = HAL_getNumRelayPins();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumRelayHeaders
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayHeaders(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayHeaders";
jint value = HAL_getNumRelayHeaders();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPCMModules
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPCMModules(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPCMModules";
jint value = HAL_getNumPCMModules();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumSolenoidPins
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumSolenoidPins(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumSolenoidPins";
jint value = HAL_getNumSolenoidPins();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPDPModules
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPDPModules(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPDPModules";
jint value = HAL_getNumPDPModules();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPDPChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPDPChannels(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPDPChannels";
jint value = HAL_getNumPDPChannels();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumCanTalons
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumCanTalons(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumCanTalons";
jint value = HAL_getNumCanTalons();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
}

View File

@@ -0,0 +1,195 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. 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;
import edu.wpi.first.wpilibj.hal.ConstantsJNI;
import edu.wpi.first.wpilibj.hal.PortsJNI;
/**
* Base class for all sensors. Stores most recent status information as well as containing utility
* functions for checking channels and error processing.
*/
public abstract class SensorBase { // TODO: Refactor
/**
* Ticks per microsecond.
*/
public static final int kSystemClockTicksPerMicrosecond =
ConstantsJNI.getSystemClockTicksPerMicrosecond();
/**
* Number of digital channels per roboRIO.
*/
public static final int kDigitalChannels = PortsJNI.getNumDigitalPins();
/**
* Number of analog input channels.
*/
public static final int kAnalogInputChannels = PortsJNI.getNumAnalogInputs();
/**
* Number of analog output channels.
*/
public static final int kAnalogOutputChannels = PortsJNI.getNumAnalogOutputs();
/**
* Number of solenoid channels per module.
*/
public static final int kSolenoidChannels = PortsJNI.getNumSolenoidPins();
/**
* Number of PWM channels per roboRIO.
*/
public static final int kPwmChannels = PortsJNI.getNumPWMPins();
/**
* Number of relay channels per roboRIO.
*/
public static final int kRelayChannels = PortsJNI.getNumRelayPins();
/**
* Number of power distribution channels.
*/
public static final int kPDPChannels = PortsJNI.getNumPDPChannels();
/**
* Number of power distribution modules.
*/
public static final int kPDPModules = PortsJNI.getNumPDPModules();
/**
* Number of PCM Modules.
*/
public static final int kPCMModules = PortsJNI.getNumPCMModules();
private static int m_defaultSolenoidModule = 0;
/**
* Creates an instance of the sensor base and gets an FPGA handle.
*/
public SensorBase() {
}
/**
* Set the default location for the Solenoid module.
*
* @param moduleNumber The number of the solenoid module to use.
*/
public static void setDefaultSolenoidModule(final int moduleNumber) {
checkSolenoidModule(moduleNumber);
SensorBase.m_defaultSolenoidModule = moduleNumber;
}
/**
* Verify that the solenoid module is correct.
*
* @param moduleNumber The solenoid module module number to check.
*/
protected static void checkSolenoidModule(final int moduleNumber) {
}
/**
* Check that the digital channel number is valid. Verify that the channel number is one of the
* legal channel numbers. Channel numbers are 1-based.
*
* @param channel The channel number to check.
*/
protected static void checkDigitalChannel(final int channel) {
if (channel < 0 || channel >= kDigitalChannels) {
throw new IndexOutOfBoundsException("Requested digital channel number is out of range.");
}
}
/**
* Check that the digital channel number is valid. Verify that the channel number is one of the
* legal channel numbers. Channel numbers are 1-based.
*
* @param channel The channel number to check.
*/
protected static void checkRelayChannel(final int channel) {
if (channel < 0 || channel >= kRelayChannels) {
throw new IndexOutOfBoundsException("Requested relay channel number is out of range.");
}
}
/**
* Check that the digital channel number is valid. Verify that the channel number is one of the
* legal channel numbers. Channel numbers are 1-based.
*
* @param channel The channel number to check.
*/
protected static void checkPWMChannel(final int channel) {
if (channel < 0 || channel >= kPwmChannels) {
throw new IndexOutOfBoundsException("Requested PWM channel number is out of range.");
}
}
/**
* Check that the analog input number is value. Verify that the analog input number is one of the
* legal channel numbers. Channel numbers are 0-based.
*
* @param channel The channel number to check.
*/
protected static void checkAnalogInputChannel(final int channel) {
if (channel < 0 || channel >= kAnalogInputChannels) {
throw new IndexOutOfBoundsException("Requested analog input channel number is out of range.");
}
}
/**
* Check that the analog input number is value. Verify that the analog input number is one of the
* legal channel numbers. Channel numbers are 0-based.
*
* @param channel The channel number to check.
*/
protected static void checkAnalogOutputChannel(final int channel) {
if (channel < 0 || channel >= kAnalogOutputChannels) {
throw new IndexOutOfBoundsException(
"Requested analog output channel number is out of range.");
}
}
/**
* Verify that the solenoid channel number is within limits. Channel numbers are 1-based.
*
* @param channel The channel number to check.
*/
protected static void checkSolenoidChannel(final int channel) {
if (channel < 0 || channel >= kSolenoidChannels) {
throw new IndexOutOfBoundsException("Requested solenoid channel number is out of range.");
}
}
/**
* Verify that the power distribution channel number is within limits. Channel numbers are
* 1-based.
*
* @param channel The channel number to check.
*/
protected static void checkPDPChannel(final int channel) {
if (channel < 0 || channel >= kPDPChannels) {
throw new IndexOutOfBoundsException("Requested PDP channel number is out of range.");
}
}
/**
* Verify that the PDP module number is within limits. module numbers are 0-based.
*
* @param module The module number to check.
*/
protected static void checkPDPModule(final int module) {
if (module < 0 || module > kPDPModules) {
throw new IndexOutOfBoundsException("Requested PDP module number is out of range.");
}
}
/**
* Get the number of the default solenoid module.
*
* @return The number of the default solenoid module.
*/
public static int getDefaultSolenoidModule() {
return SensorBase.m_defaultSolenoidModule;
}
/**
* Free the resources used by this object.
*/
public void free() {
}
}

View File

@@ -0,0 +1,12 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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,48 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. 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 getNumDigitalPins();
public static native int getNumPWMPins();
public static native int getNumDigitalPWMOutputs();
public static native int getNumEncoders();
public static native int getNumInterrupts();
public static native int getNumRelayPins();
public static native int getNumRelayHeaders();
public static native int getNumPCMModules();
public static native int getNumSolenoidPins();
public static native int getNumPDPModules();
public static native int getNumPDPChannels();
public static native int getNumCanTalons();
}

View File

@@ -0,0 +1,90 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. 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;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.tables.ITable;
/**
* GyroBase is the common base class for Gyro implementations such as AnalogGyro.
*/
public abstract class GyroBase extends SensorBase implements Gyro, PIDSource, LiveWindowSendable {
private PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
/**
* Set which parameter of the gyro you are using as a process control variable. The Gyro class
* supports the rate and displacement parameters
*
* @param pidSource An enum to select the parameter.
*/
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_pidSource = pidSource;
}
@Override
public PIDSourceType getPIDSourceType() {
return m_pidSource;
}
/**
* Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on
* the set PIDSourceType
*
* @return the output according to the gyro
*/
@Override
public double pidGet() {
switch (m_pidSource) {
case kRate:
return getRate();
case kDisplacement:
return getAngle();
default:
return 0.0;
}
}
/*
* Live Window code, only does anything if live window is activated.
*/
@Override
public String getSmartDashboardType() {
return "Gyro";
}
private ITable m_table;
@Override
public void initTable(ITable subtable) {
m_table = subtable;
updateTable();
}
@Override
public ITable getTable() {
return m_table;
}
@Override
public void updateTable() {
if (m_table != null) {
m_table.putNumber("Value", getAngle());
}
}
@Override
public void startLiveWindowMode() {
}
@Override
public void stopLiveWindowMode() {
}
}

View File

@@ -0,0 +1,102 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2016. 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;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
import static org.junit.Assert.assertEquals;
/**
* Tests for checking our constant and port values.
*/
public class ConstantsPortsTest extends AbstractComsSetup {
private static final Logger logger = Logger.getLogger(ConstantsPortsTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* kDigitalChannels.
*/
@Test
public void testDigitalChannels() {
assertEquals(26, SensorBase.kDigitalChannels);
}
/**
* kAnalogInputChannels.
*/
@Test
public void testAnalogInputChannels() {
assertEquals(8, SensorBase.kAnalogInputChannels);
}
/**
* kAnalogOutputChannels.
*/
@Test
public void testAnalogOutputChannels() {
assertEquals(2, SensorBase.kAnalogOutputChannels);
}
/**
* kSolenoidChannels.
*/
@Test
public void testSolenoidChannels() {
assertEquals(8, SensorBase.kSolenoidChannels);
}
/**
* kPwmChannels.
*/
@Test
public void testPwmChannels() {
assertEquals(20, SensorBase.kPwmChannels);
}
/**
* kRelayChannels.
*/
@Test
public void testRelayChannels() {
assertEquals(8, SensorBase.kRelayChannels);
}
/**
* kPDPChannels.
*/
@Test
public void testPDPChannels() {
assertEquals(16, SensorBase.kPDPChannels);
}
/**
* kPDPModules.
*/
@Test
public void testPDPModules() {
assertEquals(63, SensorBase.kPDPModules);
}
/**
* kPCMModules.
*/
@Test
public void testPCMModules() {
assertEquals(63, SensorBase.kPCMModules);
}
}

View File

@@ -20,9 +20,9 @@ import edu.wpi.first.wpilibj.test.AbstractTestSuite;
@RunWith(Suite.class)
@SuiteClasses({AnalogCrossConnectTest.class, AnalogPotentiometerTest.class,
BuiltInAccelerometerTest.class, CANTalonTest.class,
CircularBufferTest.class, CounterTest.class, DigitalGlitchFilterTest.class,
DIOCrossConnectTest.class, EncoderTest.class, FilterNoiseTest.class,
FilterOutputTest.class, GyroTest.class, MotorEncoderTest.class,
CircularBufferTest.class, ConstantsPortsTest.class, CounterTest.class,
DigitalGlitchFilterTest.class, DIOCrossConnectTest.class, EncoderTest.class,
FilterNoiseTest.class, FilterOutputTest.class, GyroTest.class, MotorEncoderTest.class,
MotorInvertingTest.class, PCMTest.class, PDPTest.class, PIDTest.class,
PIDToleranceTest.class, PreferencesTest.class, RelayCrossConnectTest.class,
SampleTest.class, TimerTest.class})