示例#1
0
/**
 * Get the number of oversample bits previously configured.
 * This gets the number of oversample bits from the FPGA. The actual number of
 * oversampled values is
 * 2^bits. The oversampling is done automatically in the FPGA.
 *
 * @return Number of bits of oversampling previously configured.
 */
uint32_t AnalogInput::GetOversampleBits() const {
    if (StatusIsFatal()) return 0;
    int32_t status = 0;
    int32_t oversampleBits = getAnalogOversampleBits(m_port, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));
    return oversampleBits;
}
示例#2
0
/**
 * Get a scaled sample from the output of the oversample and average engine for the channel.
 *
 * The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
 * Using oversampling will cause this value to be higher resolution, but it will update more slowly.
 * Using averaging will cause this value to be more stable, but it will update more slowly.
 *
 * @param analog_port_pointer Pointer to the analog port to use.
 * @return A scaled sample from the output of the oversample and average engine for the channel.
 */
float getAnalogAverageVoltage(void* analog_port_pointer, int32_t *status) {
  int32_t value = getAnalogAverageValue(analog_port_pointer, status);
  uint32_t LSBWeight = getAnalogLSBWeight(analog_port_pointer, status);
  int32_t offset = getAnalogOffset(analog_port_pointer, status);
  uint32_t oversampleBits = getAnalogOversampleBits(analog_port_pointer, status);
  float voltage = ((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) - offset * 1.0e-9;
  return voltage;
}
示例#3
0
/*
 * Class:     edu_wpi_first_wpilibj_hal_AnalogJNI
 * Method:    getAnalogOversampleBits
 * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
 */
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOversampleBits
  (JNIEnv * env, jclass, jobject id, jobject status)
{
	void ** javaId = (void**)env->GetDirectBufferAddress(id);
	ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
	jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
	jint returnValue = getAnalogOversampleBits( *javaId, statusPtr );
	ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
	ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << returnValue;
	return returnValue;
}