Example #1
0
/**
 * Read the accumulated value and the number of accumulated values atomically.
 *
 * This function reads the value and count from the FPGA atomically.
 * This can be used for averaging.
 *
 * @param value Reference to the 64-bit accumulated output.
 * @param count Reference to the number of accumulation cycles.
 */
void AnalogInput::GetAccumulatorOutput(int64_t &value, uint32_t &count) const {
    if (StatusIsFatal()) return;
    int32_t status = 0;
    getAccumulatorOutput(m_port, &value, &count, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));
    value += m_accumulatorOffset;
}
Example #2
0
/*
 * Class:     edu_wpi_first_wpilibj_hal_AnalogJNI
 * Method:    getAccumulatorOutput
 * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/LongBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V
 */
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput
  (JNIEnv * env, jclass, jobject id, jobject value, jobject count, jobject status)
{
	void ** javaId = (void**)env->GetDirectBufferAddress(id);
	ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
	jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);

	jlong * valuePtr = (jlong*)env->GetDirectBufferAddress(value);
	uint32_t * countPtr = (uint32_t*)env->GetDirectBufferAddress(count);

	getAccumulatorOutput(*javaId, valuePtr, countPtr, statusPtr);

	ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
	ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr;
	ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
}