Java 类edu.wpi.first.wpilibj.util.CheckedAllocationException 实例源码

项目: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    文件:AnalogOutput.java   
/**
 * Construct an analog output on a specified MXP channel.
 *
 * @param channel The channel number to represent.
 */
public AnalogOutput(final int channel) {
  m_channel = channel;

  if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
    throw new AllocationException("Analog output channel " + m_channel
        + " cannot be allocated. Channel is not present.");
  }
  try {
    channels.allocate(channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
  }

  long port_pointer = AnalogJNI.getPort((byte) channel);
  m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer);

  LiveWindow.addSensor("AnalogOutput", channel, this);
  UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);
}
项目:Frc2016FirstStronghold    文件:Solenoid.java   
/**
 * Common function to implement constructor behavior.
 */
private synchronized void initSolenoid() {
  checkSolenoidModule(m_moduleNumber);
  checkSolenoidChannel(m_channel);

  try {
    m_allocated.allocate(m_moduleNumber * kSolenoidChannels + m_channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Solenoid channel " + m_channel + " on module "
      + m_moduleNumber + " is already allocated");
  }

  long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
  m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port);

  LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
  UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
}
项目: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    文件:AnalogInput.java   
/**
 * Construct an analog channel.
 *
 * @param channel The channel number to represent. 0-3 are on-board 4-7 are on
 *        the MXP port.
 */
public AnalogInput(final int channel) {
  m_channel = channel;

  if (!AnalogJNI.checkAnalogInputChannel(channel)) {
    throw new AllocationException("Analog input channel " + m_channel
        + " cannot be allocated. Channel is not present.");
  }
  try {
    channels.allocate(channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Analog input channel " + m_channel + " is already allocated");
  }

  long port_pointer = AnalogJNI.getPort((byte) channel);
  m_port = AnalogJNI.initializeAnalogInputPort(port_pointer);

  LiveWindow.addSensor("AnalogInput", channel, this);
  UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);
}
项目:wpilibj    文件:AnalogChannel.java   
/**
 * Construct an analog channel on a specified module.
 *
 * @param moduleNumber The digital module to use (1 or 2).
 * @param channel The channel number to represent.
 */
public AnalogChannel(final int moduleNumber, final int channel) {
    m_shouldUseVoltageForPID = false;
    checkAnalogModule(moduleNumber);
    checkAnalogChannel(channel);
    m_channel = channel;
    m_moduleNumber = moduleNumber;
    m_module = AnalogModule.getInstance(moduleNumber);
    try {
        channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Analog channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }
    if (channel == 1 || channel == 2) {
        m_accumulator = new tAccumulator((byte) (channel - 1));
        m_accumulatorOffset = 0;
    } else {
        m_accumulator = null;
    }

    LiveWindow.addSensor("Analog", moduleNumber, channel, this);
    UsageReporting.report(UsageReporting.kResourceType_AnalogChannel, channel, m_moduleNumber-1);
}
项目:wpilibj    文件:Counter.java   
private void initCounter(final Mode mode) {
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try {
        m_index = counters.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No counters left to be allocated");
    }

    m_counter = new tCounter(m_index);
    m_counter.writeConfig_Mode(mode.value);
    m_upSource = null;
    m_downSource = null;
    m_counter.writeTimerConfig_AverageSize(1);

   UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:wpilibj    文件:PWM.java   
/**
 * Initialize PWMs given an module and channel.
 *
 * This method is private and is the common path for all the constructors for creating PWM
 * instances. Checks module and channel value ranges and allocates the appropriate channel.
 * The allocation is only done to help users ensure that they don't double assign channels.
 */
private void initPWM(final int moduleNumber, final int channel) {
    checkPWMModule(moduleNumber);
    checkPWMChannel(channel);
    try {
        allocated.allocate((moduleNumber - 1) * kPwmChannels + channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
    }
    m_channel = channel;
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setPWM(m_channel, kPwmDisabled);
    m_eliminateDeadband = false;

    UsageReporting.report(UsageReporting.kResourceType_PWM, channel, moduleNumber-1);
}
项目:wpilibj    文件: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.
 * @param moduleNumber The number of the digital module to use.
 */
private void initRelay(final int moduleNumber) {
    SensorBase.checkRelayModule(moduleNumber);
    SensorBase.checkRelayChannel(m_channel);
    try {
        if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel, moduleNumber-1);
        }
        if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2 + 1);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel+128, moduleNumber-1);
        }
    } catch (CheckedAllocationException e) {
        throw new AllocationException("Relay channel " + m_channel + " on module " + moduleNumber + " is already allocated");
    }
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setRelayForward(m_channel, false);
    m_module.setRelayReverse(m_channel, false);
    LiveWindow.addActuator("Relay", moduleNumber, m_channel, this);
}
项目:wpilibj    文件:DigitalModule.java   
/**
 * Allocate Digital I/O channels.
 * Allocate channels so that they are not accidently reused. Also the direction is set at the
 * time of the allocation.
 *
 * @param channel The channel to allocate.
 * @param input Indicates whether the I/O pin is an input (true) or an output (false).
 * @return True if the I/O pin was allocated, false otherwise.
 */
public boolean allocateDIO(final int channel, final boolean input) {
    try {
        DIOChannels.allocate((kDigitalChannels * (m_moduleNumber - 1) + channel - 1));
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Digital channel " + channel + " on module " + m_moduleNumber + " is already allocated");
    }
    final int outputEnable = m_fpgaDIO.readOutputEnable();
    final int bitToSet = 1 << (DigitalModule.remapDigitalChannel((channel - 1)));
    short outputEnableValue;

    if (input) {
        outputEnableValue = (short) (outputEnable & (~bitToSet));
    } else {
        outputEnableValue = (short) (outputEnable | bitToSet);
    }

    m_fpgaDIO.writeOutputEnable(outputEnableValue);
    return true;
}
项目:wpilibj    文件:DigitalInput.java   
/**
 * Request interrupts asynchronously on this digital input.
 * @param handler The address of the interrupt handler function of type tInterruptHandler that
 * will be called whenever there is an interrupt on the digitial input port.
 * Request interrupts in synchronus mode where the user program interrupt handler will be
 * called when an interrupt occurs.
 * The default is interrupt on rising edges only.
 * @param param argument to pass to the handler
 */
public void requestInterrupts(/*tInterruptHandler*/Object handler, Object param) {
    //TODO: add interrupt support

    try {
        m_interruptIndex = interrupts.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No interrupts are left to be allocated");
    }

    allocateInterrupts(false);

    m_interrupt.writeConfig_WaitForAck(false);
    m_interrupt.writeConfig_Source_AnalogTrigger(getAnalogTriggerForRouting());
    m_interrupt.writeConfig_Source_Channel((byte) getChannelForRouting());
    m_interrupt.writeConfig_Source_Module((byte) getModuleForRouting());
    setUpSourceEdge(true, false);

    //TODO: m_manager.registerHandler(handler, param);
}
项目:2013_drivebase_proto    文件:Counter.java   
private void initCounter(final Mode mode)
{
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try
    {
        m_index = counters.allocate();
    }
    catch (CheckedAllocationException e)
    {
        throw new AllocationException("No counters left to be allocated");
    }

    m_upSource = null;
    m_downSource = null;

    //UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:2014_software    文件:Counter.java   
private void initCounter(final Mode mode)
{
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try
    {
        m_index = counters.allocate();
    }
    catch (CheckedAllocationException e)
    {
        throw new AllocationException("No counters left to be allocated");
    }

    m_upSource = null;
    m_downSource = null;

    //UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:wpilib-java    文件:AnalogChannel.java   
/**
 * Construct an analog channel on a specified module.
 *
 * @param moduleNumber The digital module to use (1 or 2).
 * @param channel The channel number to represent.
 */
public AnalogChannel(final int moduleNumber, final int channel) {
    checkAnalogModule(moduleNumber);
    checkAnalogChannel(channel);
    m_channel = channel;
    m_moduleNumber = moduleNumber;
    m_module = AnalogModule.getInstance(moduleNumber);
    try {
        channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Analog channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }
    if (channel == 1 || channel == 2) {
        m_accumulator = new tAccumulator((byte) (channel - 1));
        m_accumulatorOffset = 0;
    } else {
        m_accumulator = null;
    }

    LiveWindow.addSensor("Analog", moduleNumber, channel, this);
    UsageReporting.report(UsageReporting.kResourceType_AnalogChannel, channel, m_moduleNumber-1);
}
项目:wpilib-java    文件:Counter.java   
private void initCounter(final Mode mode) {
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try {
        m_index = counters.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No counters left to be allocated");
    }

    m_counter = new tCounter(m_index);
    m_counter.writeConfig_Mode(mode.value);
    m_upSource = null;
    m_downSource = null;
    m_counter.writeTimerConfig_AverageSize(1);

   UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:wpilib-java    文件:PWM.java   
/**
 * Initialize PWMs given an module and channel.
 *
 * This method is private and is the common path for all the constructors for creating PWM
 * instances. Checks module and channel value ranges and allocates the appropriate channel.
 * The allocation is only done to help users ensure that they don't double assign channels.
 */
private void initPWM(final int moduleNumber, final int channel) {
    checkPWMModule(moduleNumber);
    checkPWMChannel(channel);
    try {
        allocated.allocate((moduleNumber - 1) * kPwmChannels + channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
    }
    m_channel = channel;
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setPWM(m_channel, kPwmDisabled);
    m_eliminateDeadband = false;

    UsageReporting.report(UsageReporting.kResourceType_PWM, channel, moduleNumber-1);
}
项目:wpilib-java    文件: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.
 * @param moduleNumber The number of the digital module to use.
 */
private void initRelay(final int moduleNumber) {
    SensorBase.checkRelayModule(moduleNumber);
    SensorBase.checkRelayChannel(m_channel);
    try {
        if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel, moduleNumber-1);
        }
        if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2 + 1);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel+128, moduleNumber-1);
        }
    } catch (CheckedAllocationException e) {
        throw new AllocationException("Relay channel " + m_channel + " on module " + moduleNumber + " is already allocated");
    }
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setRelayForward(m_channel, false);
    m_module.setRelayReverse(m_channel, false);
    LiveWindow.addActuator("Relay", moduleNumber, m_channel, this);
}
项目:wpilib-java    文件:DigitalModule.java   
/**
 * Allocate Digital I/O channels.
 * Allocate channels so that they are not accidently reused. Also the direction is set at the
 * time of the allocation.
 *
 * @param channel The channel to allocate.
 * @param input Indicates whether the I/O pin is an input (true) or an output (false).
 * @return True if the I/O pin was allocated, false otherwise.
 */
public boolean allocateDIO(final int channel, final boolean input) {
    try {
        DIOChannels.allocate((kDigitalChannels * (m_moduleNumber - 1) + channel - 1));
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Digital channel " + channel + " on module " + m_moduleNumber + " is already allocated");
    }
    final int outputEnable = m_fpgaDIO.readOutputEnable();
    final int bitToSet = 1 << (DigitalModule.remapDigitalChannel((channel - 1)));
    short outputEnableValue;

    if (input) {
        outputEnableValue = (short) (outputEnable & (~bitToSet));
    } else {
        outputEnableValue = (short) (outputEnable | bitToSet);
    }

    m_fpgaDIO.writeOutputEnable(outputEnableValue);
    return true;
}
项目:wpilib-java    文件:DigitalInput.java   
/**
 * Request interrupts asynchronously on this digital input.
 * @param handler The address of the interrupt handler function of type tInterruptHandler that
 * will be called whenever there is an interrupt on the digitial input port.
 * Request interrupts in synchronus mode where the user program interrupt handler will be
 * called when an interrupt occurs.
 * The default is interrupt on rising edges only.
 * @param param argument to pass to the handler
 */
public void requestInterrupts(/*tInterruptHandler*/Object handler, Object param) {
    //TODO: add interrupt support

    try {
        m_interruptIndex = interrupts.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No interrupts are left to be allocated");
    }

    allocateInterrupts(false);

    m_interrupt.writeConfig_WaitForAck(false);
    m_interrupt.writeConfig_Source_AnalogTrigger(getAnalogTriggerForRouting());
    m_interrupt.writeConfig_Source_Channel((byte) getChannelForRouting());
    m_interrupt.writeConfig_Source_Module((byte) getModuleForRouting());
    setUpSourceEdge(true, false);

    //TODO: m_manager.registerHandler(handler, param);
}
项目:2013_robot_software    文件:Counter.java   
private void initCounter(final Mode mode)
{
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try
    {
        m_index = counters.allocate();
    }
    catch (CheckedAllocationException e)
    {
        throw new AllocationException("No counters left to be allocated");
    }

    m_upSource = null;
    m_downSource = null;

    //UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:snobot-2017    文件:Resource.java   
/**
 * Allocate a resource. When a resource is requested, mark it allocated. In this case, a free
 * resource value within the range is located and returned after it is marked allocated.
 *
 * @return The index of the allocated block.
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate() throws CheckedAllocationException {
  for (int i = 0; i < m_size; i++) {
    if (m_numAllocated[i] == false) {
      m_numAllocated[i] = true;
      return i;
    }
  }
  throw new CheckedAllocationException("No available resources");
}
项目:snobot-2017    文件:Resource.java   
/**
 * Allocate a specific resource value. The user requests a specific resource value, i.e. channel
 * number and it is verified unallocated, then returned.
 *
 * @param index The resource to allocate
 * @return The index of the allocated block
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate(final int index) throws CheckedAllocationException {
  if (index >= m_size || index < 0) {
    throw new CheckedAllocationException("Index " + index + " out of range");
  }
  if (m_numAllocated[index] == true) {
    throw new CheckedAllocationException("Resource at index " + index + " already allocated");
  }
  m_numAllocated[index] = true;
  return index;
}
项目:Frc2016FirstStronghold    文件:InterruptableSensorBase.java   
/**
 * Allocate the interrupt
 *
 * @param watcher true if the interrupt should be in synchronous mode where
 *        the user program will have to explicitly wait for the interrupt to
 *        occur.
 */
protected void allocateInterrupts(boolean watcher) {
  try {
    m_interruptIndex = interrupts.allocate();
  } catch (CheckedAllocationException e) {
    throw new AllocationException("No interrupts are left to be allocated");
  }
  m_isSynchronousInterrupt = watcher;

  m_interrupt =
      InterruptJNI.initializeInterrupts(m_interruptIndex, watcher);
}
项目:Frc2016FirstStronghold    文件:Resource.java   
/**
 * Allocate a resource. When a resource is requested, mark it allocated. In
 * this case, a free resource value within the range is located and returned
 * after it is marked allocated.
 *
 * @return The index of the allocated block.
 * @throws CheckedAllocationException If there are no resources available to
 *         be allocated.
 */
public int allocate() throws CheckedAllocationException {
  for (int i = 0; i < m_size; i++) {
    if (m_numAllocated[i] == false) {
      m_numAllocated[i] = true;
      return i;
    }
  }
  throw new CheckedAllocationException("No available resources");
}
项目:Frc2016FirstStronghold    文件:Resource.java   
/**
 * Allocate a specific resource value. The user requests a specific resource
 * value, i.e. channel number and it is verified unallocated, then returned.
 *
 * @param index The resource to allocate
 * @return The index of the allocated block
 * @throws CheckedAllocationException If there are no resources available to
 *         be allocated.
 */
public int allocate(final int index) throws CheckedAllocationException {
  if (index >= m_size || index < 0) {
    throw new CheckedAllocationException("Index " + index + " out of range");
  }
  if (m_numAllocated[index] == true) {
    throw new CheckedAllocationException("Resource at index " + index + " already allocated");
  }
  m_numAllocated[index] = true;
  return index;
}
项目:wpilibj    文件:AnalogTrigger.java   
/**
 * Initialize an analog trigger from a module number and channel.
 * This is the common code for the two constructors that use a module number and channel.
 * @param moduleNumber The number of the analog module to create this trigger on.
 * @param channel the port to use for the analog trigger
 */
protected void initTrigger(final int moduleNumber, final int channel) {
    m_channel = channel;
    m_analogModule = AnalogModule.getInstance(moduleNumber);
    try {
        m_index = triggers.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No analog triggers are available to allocate");
    }
    m_trigger = new tAnalogTrigger((byte) m_index);
    m_trigger.writeSourceSelect_Channel((byte) (m_channel - 1));
    m_trigger.writeSourceSelect_Module((byte) moduleNumber - 1);
    UsageReporting.report(UsageReporting.kResourceType_AnalogTrigger, channel, moduleNumber-1);
}
项目:wpilibj    文件:Encoder.java   
/**
 * Common initialization code for Encoders.
 * This code allocates resources for Encoders and is common to all constructors.
 * @param reverseDirection If true, counts down instead of up (this is all relative)
 * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X decoding. If 4X is
 * selected, then an encoder FPGA object is used and the returned counts will be 4x the encoder
 * spec'd value since all rising and falling edges are counted. If 1X or 2X are selected then
 * a counter object will be used and the returned value will either exactly match the spec'd count
 * or be double (2x) the spec'd count.
 */
private void initEncoder(boolean reverseDirection) {
    switch (m_encodingType.value) {
        case EncodingType.k4X_val:
            try {
                m_index = quadEncoders.allocate();
            } catch (CheckedAllocationException e) {
                throw new AllocationException("There are no encoders left to allocate");
            }
            m_encoder = new tEncoder(m_index);
            m_encoder.writeConfig_ASource_Module(m_aSource.getModuleForRouting());
            m_encoder.writeConfig_ASource_Channel(m_aSource.getChannelForRouting());
            m_encoder.writeConfig_ASource_AnalogTrigger(m_aSource.getAnalogTriggerForRouting());
            m_encoder.writeConfig_BSource_Module(m_bSource.getModuleForRouting());
            m_encoder.writeConfig_BSource_Channel(m_bSource.getChannelForRouting());
            m_encoder.writeConfig_BSource_AnalogTrigger(m_bSource.getAnalogTriggerForRouting());
            m_encoder.strobeReset();
            m_encoder.writeConfig_Reverse(reverseDirection);
            m_encoder.writeTimerConfig_AverageSize(1);
            if (m_indexSource != null) {
                m_encoder.writeConfig_IndexSource_Module(m_indexSource.getModuleForRouting());
                m_encoder.writeConfig_IndexSource_Channel(m_indexSource.getChannelForRouting());
                m_encoder.writeConfig_IndexSource_AnalogTrigger(m_indexSource.getAnalogTriggerForRouting());
                m_encoder.writeConfig_IndexActiveHigh(true);
            }
            m_counter = null;
            break;
        case EncodingType.k2X_val:
        case EncodingType.k1X_val:
            m_counter = new Counter(m_encodingType, m_aSource, m_bSource, reverseDirection);
            break;
    }
    m_distancePerPulse = 1.0;

    UsageReporting.report(UsageReporting.kResourceType_Encoder, m_index, m_encodingType.value);
    LiveWindow.addSensor("Encoder", m_aSource.getModuleForRouting(), m_aSource.getChannelForRouting(), this);
}
项目:wpilibj    文件:Solenoid.java   
/**
 * Common function to implement constructor behavior.
 */
private synchronized void initSolenoid() {
    checkSolenoidModule(m_moduleNumber);
    checkSolenoidChannel(m_channel);

    try {
        m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Solenoid channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }

    LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
    UsageReporting.report(UsageReporting.kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
}
项目:wpilibj    文件:DigitalModule.java   
/**
 * Allocate a DO PWM Generator.
 * Allocate PWM generators so that they are not accidently reused.
 */
public int allocateDO_PWM() {
    try {
        return DO_PWMGenerators[m_moduleNumber - 1].allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
            "No Digital Output PWM Generators on module " + m_moduleNumber + " remaining");
    }
}
项目:wpilibj    文件:DigitalInput.java   
/**
 * Request interrupts synchronously on this digital input.
 * Request interrupts in synchronus mode where the user program will have to explicitly
 * wait for the interrupt to occur.
 * The default is interrupt on rising edges only.
 */
public void requestInterrupts() {
    try {
        m_interruptIndex = interrupts.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No interrupts are left to be allocated");
    }

    allocateInterrupts(true);

    m_interrupt.writeConfig_Source_AnalogTrigger(getAnalogTriggerForRouting());
    m_interrupt.writeConfig_Source_Channel((byte) getChannelForRouting());
    m_interrupt.writeConfig_Source_Module((byte) getModuleForRouting());
    setUpSourceEdge(true, false);
}
项目:wpilibj    文件:Resource.java   
/**
 * Allocate a resource.
 * When a resource is requested, mark it allocated. In this case, a free resource value
 * within the range is located and returned after it is marked allocated.
 *
 * @return The index of the allocated block.
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate() throws CheckedAllocationException {
    for (int i = 0; i < m_size; i++) {
        if (m_numAllocated[i] == false) {
            m_numAllocated[i] = true;
            return i;
        }
    }
    throw new CheckedAllocationException("No available resources");
}
项目:wpilibj    文件:Resource.java   
/**
 * Allocate a specific resource value.
 * The user requests a specific resource value, i.e. channel number and it is verified
 * unallocated, then returned.
 *
 * @param index The resource to allocate
 * @return The index of the allocated block
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate(final int index) throws CheckedAllocationException {
    if (index >= m_size) {
        throw new CheckedAllocationException("Index " + index + " out of range");
    }
    if (m_numAllocated[index] == true) {
        throw new CheckedAllocationException("Resource at index " + index + " already allocated");
    }
    m_numAllocated[index] = true;
    return index;
}
项目:wpilib-java    文件:AnalogTrigger.java   
/**
 * Initialize an analog trigger from a module number and channel.
 * This is the common code for the two constructors that use a module number and channel.
 * @param moduleNumber The number of the analog module to create this trigger on.
 * @param channel the port to use for the analog trigger
 */
protected void initTrigger(final int moduleNumber, final int channel) {
    m_channel = channel;
    m_analogModule = AnalogModule.getInstance(moduleNumber);
    try {
        m_index = triggers.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No analog triggers are available to allocate");
    }
    m_trigger = new tAnalogTrigger((byte) m_index);
    m_trigger.writeSourceSelect_Channel((byte) (m_channel - 1));
    m_trigger.writeSourceSelect_Module((byte) moduleNumber - 1);
    UsageReporting.report(UsageReporting.kResourceType_AnalogTrigger, channel, moduleNumber-1);
}
项目:wpilib-java    文件:Encoder.java   
/**
 * Common initialization code for Encoders.
 * This code allocates resources for Encoders and is common to all constructors.
 * @param reverseDirection If true, counts down instead of up (this is all relative)
 * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X decoding. If 4X is
 * selected, then an encoder FPGA object is used and the returned counts will be 4x the encoder
 * spec'd value since all rising and falling edges are counted. If 1X or 2X are selected then
 * a counter object will be used and the returned value will either exactly match the spec'd count
 * or be double (2x) the spec'd count.
 */
private void initEncoder(boolean reverseDirection) {
    switch (m_encodingType.value) {
        case EncodingType.k4X_val:
            try {
                m_index = quadEncoders.allocate();
            } catch (CheckedAllocationException e) {
                throw new AllocationException("There are no encoders left to allocate");
            }
            m_encoder = new tEncoder(m_index);
            m_encoder.writeConfig_ASource_Module(m_aSource.getModuleForRouting());
            m_encoder.writeConfig_ASource_Channel(m_aSource.getChannelForRouting());
            m_encoder.writeConfig_ASource_AnalogTrigger(m_aSource.getAnalogTriggerForRouting());
            m_encoder.writeConfig_BSource_Module(m_bSource.getModuleForRouting());
            m_encoder.writeConfig_BSource_Channel(m_bSource.getChannelForRouting());
            m_encoder.writeConfig_BSource_AnalogTrigger(m_bSource.getAnalogTriggerForRouting());
            m_encoder.strobeReset();
            m_encoder.writeConfig_Reverse(reverseDirection);
            m_encoder.writeTimerConfig_AverageSize(1);
            if (m_indexSource != null) {
                m_encoder.writeConfig_IndexSource_Module(m_indexSource.getModuleForRouting());
                m_encoder.writeConfig_IndexSource_Channel(m_indexSource.getChannelForRouting());
                m_encoder.writeConfig_IndexSource_AnalogTrigger(m_indexSource.getAnalogTriggerForRouting());
                m_encoder.writeConfig_IndexActiveHigh(true);
            }
            m_counter = null;
            break;
        case EncodingType.k2X_val:
        case EncodingType.k1X_val:
            m_counter = new Counter(m_encodingType, m_aSource, m_bSource, reverseDirection);
            break;
    }
    m_distancePerPulse = 1.0;

    UsageReporting.report(UsageReporting.kResourceType_Encoder, m_index, m_encodingType.value);
    LiveWindow.addSensor("Encoder", m_aSource.getModuleForRouting(), m_aSource.getChannelForRouting(), this);
}
项目:wpilib-java    文件:Solenoid.java   
/**
 * Common function to implement constructor behavior.
 */
private synchronized void initSolenoid() {
    checkSolenoidModule(m_moduleNumber);
    checkSolenoidChannel(m_channel);

    try {
        m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Solenoid channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }

    LiveWindow.addSensor("Solenoid", m_moduleNumber, m_channel, this);
    UsageReporting.report(UsageReporting.kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
}
项目:wpilib-java    文件:DigitalModule.java   
/**
 * Allocate a DO PWM Generator.
 * Allocate PWM generators so that they are not accidently reused.
 */
public int allocateDO_PWM() {
    try {
        return DO_PWMGenerators[m_moduleNumber - 1].allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
            "No Digital Output PWM Generators on module " + m_moduleNumber + " remaining");
    }
}
项目:wpilib-java    文件:DigitalInput.java   
/**
 * Request interrupts synchronously on this digital input.
 * Request interrupts in synchronus mode where the user program will have to explicitly
 * wait for the interrupt to occur.
 * The default is interrupt on rising edges only.
 */
public void requestInterrupts() {
    try {
        m_interruptIndex = interrupts.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No interrupts are left to be allocated");
    }

    allocateInterrupts(true);

    m_interrupt.writeConfig_Source_AnalogTrigger(getAnalogTriggerForRouting());
    m_interrupt.writeConfig_Source_Channel((byte) getChannelForRouting());
    m_interrupt.writeConfig_Source_Module((byte) getModuleForRouting());
    setUpSourceEdge(true, false);
}
项目:wpilib-java    文件:Resource.java   
/**
 * Allocate a resource.
 * When a resource is requested, mark it allocated. In this case, a free resource value
 * within the range is located and returned after it is marked allocated.
 *
 * @return The index of the allocated block.
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate() throws CheckedAllocationException {
    for (int i = 0; i < m_size; i++) {
        if (m_numAllocated[i] == false) {
            m_numAllocated[i] = true;
            return i;
        }
    }
    throw new CheckedAllocationException("No available resources");
}
项目:wpilib-java    文件:Resource.java   
/**
 * Allocate a specific resource value.
 * The user requests a specific resource value, i.e. channel number and it is verified
 * unallocated, then returned.
 *
 * @param index The resource to allocate
 * @return The index of the allocated block
 * @throws CheckedAllocationException If there are no resources available to be allocated.
 */
public int allocate(final int index) throws CheckedAllocationException {
    if (index >= m_size) {
        throw new CheckedAllocationException("Index " + index + " out of range");
    }
    if (m_numAllocated[index] == true) {
        throw new CheckedAllocationException("Resource at index " + index + " already allocated");
    }
    m_numAllocated[index] = true;
    return index;
}