Java 类edu.wpi.first.wpilibj.hal.DIOJNI 实例源码

项目:Frc2016FirstStronghold    文件:DigitalSource.java   
protected void initDigitalPort(int channel, boolean input) {

    m_channel = channel;

    checkDigitalChannel(m_channel);

    try {
      channels.allocate(m_channel);
    } catch (CheckedAllocationException ex) {
      throw new AllocationException("Digital input " + m_channel + " is already allocated");
    }

    long port_pointer = DIOJNI.getPort((byte) channel);
    m_port = DIOJNI.initializeDigitalPort(port_pointer);
    DIOJNI.allocateDIO(m_port, input);
  }
项目:Frc2016FirstStronghold    文件:PWM.java   
/**
 * Initialize PWMs given a channel.
 *
 * This method is private and is the common path for all the constructors for
 * creating PWM instances. Checks channel value ranges and allocates the
 * appropriate channel. The allocation is only done to help users ensure that
 * they don't double assign channels.
 *$
 * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the
 *        MXP port
 */
private void initPWM(final int channel) {
  checkPWMChannel(channel);
  m_channel = channel;

  m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));

  if (!PWMJNI.allocatePWMChannel(m_port)) {
    throw new AllocationException("PWM channel " + channel + " is already allocated");
  }

  PWMJNI.setPWM(m_port, (short) 0);

  m_eliminateDeadband = false;

  UsageReporting.report(tResourceType.kResourceType_PWM, channel);
}
项目:Frc2016FirstStronghold    文件:Relay.java   
/**
 * Common relay initialization method. This code is common to all Relay
 * constructors and initializes the relay and reserves all resources that need
 * to be locked. Initially the relay is set to both lines at 0v.
 */
private void initRelay() {
  SensorBase.checkRelayChannel(m_channel);
  try {
    if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
      relayChannels.allocate(m_channel * 2);
      UsageReporting.report(tResourceType.kResourceType_Relay, m_channel);
    }
    if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
      relayChannels.allocate(m_channel * 2 + 1);
      UsageReporting.report(tResourceType.kResourceType_Relay, m_channel + 128);
    }
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Relay channel " + m_channel + " is already allocated");
  }

  m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));

  m_safetyHelper = new MotorSafetyHelper(this);
  m_safetyHelper.setSafetyEnabled(false);

  LiveWindow.addActuator("Relay", m_channel, this);
}
项目:Frc2016FirstStronghold    文件:Relay.java   
@Override
public void free() {
  if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
    relayChannels.free(m_channel * 2);
  }
  if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
    relayChannels.free(m_channel * 2 + 1);
  }

  RelayJNI.setRelayForward(m_port, false);
  RelayJNI.setRelayReverse(m_port, false);

  DIOJNI.freeDIO(m_port);
  DIOJNI.freeDigitalPort(m_port);
  m_port = 0;
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Create an instance of a digital output. Create an instance of a digital output given a
 * channel.
 *
 * @param channel the DIO channel to use for the digital output. 0-9 are on-board, 10-25 are on
 *                the MXP
 */
public DigitalOutput(int channel) {
  checkDigitalChannel(channel);
  m_channel = channel;

  m_handle = DIOJNI.initializeDIOPort(DIOJNI.getPort((byte)channel), false);

  HAL.report(tResourceType.kResourceType_DigitalOutput, channel);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Free the resources associated with a digital output.
 */
@Override
public void free() {
  // disable the pwm only if we have allocated it
  if (m_pwmGenerator != invalidPwmGenerator) {
    disablePWM();
  }
  DIOJNI.freeDIOPort(m_handle);
  m_handle = 0;
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * @param channel     Unused
 * @param pulseLength The length of the pulse.
 * @deprecated Generate a single pulse. Write a pulse to the specified digital output channel.
 *             There can only be a single pulse going at any time.
 */
@Deprecated
@SuppressWarnings("PMD.UnusedFormalParameter")
public void pulse(final int channel, final int pulseLength) {
  double convertedPulse = pulseLength / 1.0e9 * (DIOJNI.getLoopTiming() * 25);
  System.err
      .println("You should use the double version of pulse for portability.  This is deprecated");
  DIOJNI.pulse(m_handle, convertedPulse);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Change this line from a PWM output back to a static Digital Output line.
 *
 * <p>Free up one of the 6 DO PWM generator resources that were in use.
 */
public void disablePWM() {
  if (m_pwmGenerator == invalidPwmGenerator) {
    return;
  }
  // Disable the output by routing to a dead bit.
  DIOJNI.setDigitalPWMOutputChannel(m_pwmGenerator, kDigitalChannels);
  DIOJNI.freeDigitalPWM(m_pwmGenerator);
  m_pwmGenerator = invalidPwmGenerator;
}
项目:snobot-2017    文件:SensorBase.java   
/**
 * Check that the digital channel number is valid. Verify that the channel number is one of the
 * legal channel numbers. Channel numbers are 0-based.
 *
 * @param channel The channel number to check.
 */
protected static void checkDigitalChannel(final int channel) {
  if (!DIOJNI.checkDIOChannel(channel)) {
    StringBuilder buf = new StringBuilder();
    buf.append("Requested DIO channel is out of range. Minimum: 0, Maximum: ")
      .append(kDigitalChannels)
      .append(", Requested: ")
      .append(channel);
    throw new IndexOutOfBoundsException(buf.toString());
  }
}
项目:snobot-2017    文件:DigitalInput.java   
/**
 * Create an instance of a Digital Input class. Creates a digital input given a channel.
 *
 * @param channel the DIO channel for the digital input 0-9 are on-board, 10-25 are on the MXP
 */
public DigitalInput(int channel) {
  checkDigitalChannel(channel);
  m_channel = channel;

  m_handle = DIOJNI.initializeDIOPort(DIOJNI.getPort((byte)channel), true);

  LiveWindow.addSensor("DigitalInput", channel, this);
  HAL.report(tResourceType.kResourceType_DigitalInput, channel);
}
项目:snobot-2017    文件:DigitalInput.java   
/**
 * Frees the resources for this output.
 */
public void free() {
  if (m_interrupt != 0) {
    cancelInterrupts();
  }

  DIOJNI.freeDIOPort(m_handle);
}
项目:Frc2016FirstStronghold    文件:DigitalSource.java   
@Override
public void free() {
  channels.free(m_channel);
  DIOJNI.freeDIO(m_port);
  DIOJNI.freeDigitalPort(m_port);
  m_port = 0;
  m_channel = 0;
}
项目:Frc2016FirstStronghold    文件:DigitalOutput.java   
/**
 * @deprecated Generate a single pulse. Write a pulse to the specified digital
 *             output channel. There can only be a single pulse going at any
 *             time.
 *
 * @param channel The channel to pulse.
 * @param pulseLength The length of the pulse.
 */
@Deprecated
public void pulse(final int channel, final int pulseLength) {
  float convertedPulse =
      (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming() * 25));
  System.err
      .println("You should use the float version of pulse for portability.  This is deprecated");
  DIOJNI.pulse(m_port, convertedPulse);
}
项目:Frc2016FirstStronghold    文件:PWM.java   
/**
 * Free the PWM channel.
 *
 * Free the resource associated with the PWM channel and set the value to 0.
 */
public void free() {
  if (m_port == 0) return;
  PWMJNI.setPWM(m_port, (short) 0);
  PWMJNI.freePWMChannel(m_port);
  PWMJNI.freeDIO(m_port);
  DIOJNI.freeDigitalPort(m_port);
  m_port = 0;
}
项目:Frc2016FirstStronghold    文件:PWM.java   
/**
 * Set the bounds on the PWM pulse widths. This sets the bounds on the PWM
 * values for a particular type of controller. The values determine the upper
 * and lower speeds as well as the deadband bracket.
 *$
 * @param max The max PWM pulse width in ms
 * @param deadbandMax The high end of the deadband range pulse width in ms
 * @param center The center (off) pulse width in ms
 * @param deadbandMin The low end of the deadband pulse width in ms
 * @param min The minimum pulse width in ms
 */
protected void setBounds(double max, double deadbandMax, double center, double deadbandMin,
    double min) {
  double loopTime =
      DIOJNI.getLoopTiming() / (kSystemClockTicksPerMicrosecond * 1e3);

  m_maxPwm = (int) ((max - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
  m_deadbandMaxPwm =
      (int) ((deadbandMax - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
  m_centerPwm = (int) ((center - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
  m_deadbandMinPwm =
      (int) ((deadbandMin - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
  m_minPwm = (int) ((min - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
}
项目:FlashLib    文件:FRCPWM.java   
@Override
public double getFrequency() {
    return (SensorBase.kSystemClockTicksPerMicrosecond * 1e3) / DIOJNI.getLoopTiming();
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Enable a PWM Output on this line.
 *
 * <p>Allocate one of the 6 DO PWM generator resources.
 *
 * <p>Supply the initial duty-cycle to output so as to avoid a glitch when first starting.
 *
 * <p>The resolution of the duty cycle is 8-bit for low frequencies (1kHz or less) but is reduced
 * the higher the frequency of the PWM signal is.
 *
 * @param initialDutyCycle The duty-cycle to start generating. [0..1]
 */
public void enablePWM(double initialDutyCycle) {
  if (m_pwmGenerator != invalidPwmGenerator) {
    return;
  }
  m_pwmGenerator = DIOJNI.allocateDigitalPWM();
  DIOJNI.setDigitalPWMDutyCycle(m_pwmGenerator, initialDutyCycle);
  DIOJNI.setDigitalPWMOutputChannel(m_pwmGenerator, m_channel);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Change the duty-cycle that is being generated on the line.
 *
 * <p>The resolution of the duty cycle is 8-bit for low frequencies (1kHz or less) but is reduced
 * the
 * higher the frequency of the PWM signal is.
 *
 * @param dutyCycle The duty-cycle to change to. [0..1]
 */
public void updateDutyCycle(double dutyCycle) {
  if (m_pwmGenerator == invalidPwmGenerator) {
    return;
  }
  DIOJNI.setDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle);
}
项目:snobot-2017    文件:PWM.java   
/**
 * Allocate a PWM given a channel.
 *
 * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
 */
public PWM(final int channel) {
  checkPWMChannel(channel);
  m_channel = channel;

  m_handle = PWMJNI.initializePWMPort(DIOJNI.getPort((byte) channel));

  setDisabled();

  PWMJNI.setPWMEliminateDeadband(m_handle, false);

  HAL.report(tResourceType.kResourceType_PWM, channel);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Set the value of a digital output.
 *
 * @param value true is on, off is false
 */
public void set(boolean value) {
  DIOJNI.setDIO(m_handle, (short) (value ? 1 : 0));
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Gets the value being output from the Digital Output.
 *
 * @return the state of the digital output.
 */
public boolean get() {
  return DIOJNI.getDIO(m_handle);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Generate a single pulse. There can only be a single pulse going at any time.
 *
 * @param pulseLength The length of the pulse.
 */
public void pulse(final double pulseLength) {
  DIOJNI.pulse(m_handle, pulseLength);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Generate a single pulse. Write a pulse to the specified digital output channel. There can only
 * be a single pulse going at any time.
 *
 * @param channel     Unused
 * @param pulseLength The length of the pulse.
 * @deprecated Use {@link #pulse(double)} instead.
 */
@Deprecated
@SuppressWarnings("PMD.UnusedFormalParameter")
public void pulse(final int channel, final double pulseLength) {
  DIOJNI.pulse(m_handle, pulseLength);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Determine if the pulse is still going. Determine if a previously started pulse is still going.
 *
 * @return true if pulsing
 */
public boolean isPulsing() {
  return DIOJNI.isPulsing(m_handle);
}
项目:snobot-2017    文件:DigitalOutput.java   
/**
 * Change the PWM frequency of the PWM output on a Digital Output line.
 *
 * <p>The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is logarithmic.
 *
 * <p>There is only one PWM frequency for all channnels.
 *
 * @param rate The frequency to output all digital output PWM signals.
 */
public void setPWMRate(double rate) {
  DIOJNI.setDigitalPWMRate(rate);
}
项目:snobot-2017    文件:DigitalInput.java   
/**
 * Get the value from a digital input channel. Retrieve the value of a single digital input
 * channel from the FPGA.
 *
 * @return the status of the digital input
 */
public boolean get() {
  return DIOJNI.getDIO(m_handle);
}
项目:Frc2016FirstStronghold    文件:DigitalOutput.java   
/**
 * Set the value of a digital output.
 *
 * @param value true is on, off is false
 */
public void set(boolean value) {
  DIOJNI.setDIO(m_port, (short) (value ? 1 : 0));
}
项目:Frc2016FirstStronghold    文件:DigitalOutput.java   
/**
 * Generate a single pulse. Write a pulse to the specified digital output
 * channel. There can only be a single pulse going at any time.
 *
 * @param channel The channel to pulse.
 * @param pulseLength The length of the pulse.
 */
public void pulse(final int channel, final float pulseLength) {
  DIOJNI.pulse(m_port, pulseLength);
}
项目:Frc2016FirstStronghold    文件:DigitalOutput.java   
/**
 * Determine if the pulse is still going. Determine if a previously started
 * pulse is still going.
 *
 * @return true if pulsing
 */
public boolean isPulsing() {
  return DIOJNI.isPulsing(m_port);
}
项目:Frc2016FirstStronghold    文件:DigitalInput.java   
/**
 * Get the value from a digital input channel. Retrieve the value of a single
 * digital input channel from the FPGA.
 *
 * @return the status of the digital input
 */
public boolean get() {
  return DIOJNI.getDIO(m_port);
}