Example #1
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);
  }