Exemple #1
0
  /**
   * Constructor.
   *
   * @param port The I2C port the device is connected to.
   * @param deviceAddress The address of the device on the I2C bus.
   */
  public I2C(Port port, int deviceAddress) {
    ByteBuffer status = ByteBuffer.allocateDirect(4);
    status.order(ByteOrder.LITTLE_ENDIAN);

    m_port = port;
    m_deviceAddress = deviceAddress;

    I2CJNI.i2CInitialize((byte) m_port.getValue(), status.asIntBuffer());
    HALUtil.checkStatus(status.asIntBuffer());

    UsageReporting.report(tResourceType.kResourceType_I2C, deviceAddress);
  }
Exemple #2
0
  /**
   * Initialize PWMs given a channel.
   *
   * <p>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);
  }
Exemple #3
0
  /**
   * 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);
  }
Exemple #4
0
  /**
   * 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) {
    initDigitalPort(channel, true);

    LiveWindow.addSensor("DigitalInput", channel, this);
    UsageReporting.report(tResourceType.kResourceType_DigitalInput, channel);
  }