/* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderSamplesToAverage * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderSamplesToAverage (JNIEnv * env, jclass, jobject id, jint value, jobject status) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderSamplesToAverage"; void ** javaId = (void**)env->GetDirectBufferAddress(id); ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; setEncoderSamplesToAverage(*javaId, value, statusPtr); ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; }
/* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderSamplesToAverage * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderSamplesToAverage (JNIEnv * env, jclass, jlong id, jint value) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderSamplesToAverage"; ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; int32_t status = 0; setEncoderSamplesToAverage((void*)id, value, &status); ENCODERJNI_LOG(logDEBUG) << "Status = " << status; if (status == PARAMETER_OUT_OF_RANGE) { ThrowBoundaryException(env, value, 1, 127); return; } CheckStatus(env, status); }
/** * Set the Samples to Average which specifies the number of samples of the timer * to average when calculating the period. * * Perform averaging to account for mechanical imperfections or as oversampling * to increase resolution. * * @param samplesToAverage The number of samples to average from 1 to 127. */ void Encoder::SetSamplesToAverage(int samplesToAverage) { if (samplesToAverage < 1 || samplesToAverage > 127) { wpi_setWPIErrorWithContext( ParameterOutOfRange, "Average counter values must be between 1 and 127"); } int32_t status = 0; switch (m_encodingType) { case k4X: setEncoderSamplesToAverage(m_encoder, samplesToAverage, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); break; case k1X: case k2X: m_counter->SetSamplesToAverage(samplesToAverage); break; } }