Beispiel #1
0
/**
 * Construct an analog input.
 *
 * @param channel The channel number on the roboRIO to represent. 0-3 are
 * on-board 4-7 are on the MXP port.
 */
AnalogInput::AnalogInput(uint32_t channel) {
    std::stringstream buf;
    buf << "Analog Input " << channel;
    Resource::CreateResourceObject(inputs, kAnalogInputs);

    if (!checkAnalogInputChannel(channel)) {
        wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
        return;
    }

    if (inputs->Allocate(channel, buf.str()) ==
            std::numeric_limits<uint32_t>::max()) {
        CloneError(*inputs);
        return;
    }

    m_channel = channel;

    void *port = getPort(channel);
    int32_t status = 0;
    m_port = initializeAnalogInputPort(port, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));

    LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
    HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
}
Beispiel #2
0
/*
 * Class:     edu_wpi_first_wpilibj_hal_AnalogJNI
 * Method:    checkAnalogInputChannel
 * Signature: (I)B
 */
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel
  (JNIEnv *, jclass, jint value)
{
	//ANALOGJNI_LOG(logDEBUG) << "Channel = " << value;
	jbyte returnValue = checkAnalogInputChannel( value );
	//ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue;
	return returnValue;
}
Beispiel #3
0
/**
 * Get a sample from the output of the oversample and average engine for the channel.
 *
 * The sample is 12-bit + the value configured in SetOversampleBits().
 * The value configured in SetAverageBits() will cause this value to be averaged 2**bits number of samples.
 * This is not a sliding window.  The sample will not change until 2**(OversamplBits + AverageBits) samples
 * have been acquired from the module on this channel.
 * Use GetAverageVoltage() to get the analog value in calibrated units.
 *
 * @param analog_port_pointer Pointer to the analog port to use.
 * @return A sample from the oversample and average engine for the channel.
 */
int32_t getAnalogAverageValue(void* analog_port_pointer, int32_t *status) {
  AnalogPort* port = (AnalogPort*) analog_port_pointer;
  int32_t value;
  checkAnalogInputChannel(port->port.pin);

  tAI::tReadSelect readSelect;
  readSelect.Channel = port->port.pin;
  readSelect.Averaged = true;

  {
    std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
    analogInputSystem->writeReadSelect(readSelect, status);
    analogInputSystem->strobeLatchOutput(status);
    value = (int32_t) analogInputSystem->readOutput(status);
  }

  return value;
}