Files
allwpilib/hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
Thad House 87a64ccedc [hal] Convert DutyCycle Raw output to be a high time measurement (#4466)
The existing raw time has an issue where it jumps around, as in the FPGA if the frequency is not a multiple or divisor of 25 Mhz it jumps around by 1 every second. While waiting on an FPGA change, update the API to make raw output give nanoseconds rather then a scaled value. This does a longer read cycle to get the correct value, but in the future if a fast FPGA function is added this can be easily changed.
2022-10-12 10:15:09 -07:00

124 lines
2.9 KiB
C++

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include "HALUtil.h"
#include "edu_wpi_first_hal_DutyCycleJNI.h"
#include "hal/DutyCycle.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: initialize
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_initialize
(JNIEnv* env, jclass, jint digitalSourceHandle, jint analogTriggerType)
{
int32_t status = 0;
auto handle = HAL_InitializeDutyCycle(
static_cast<HAL_Handle>(digitalSourceHandle),
static_cast<HAL_AnalogTriggerType>(analogTriggerType), &status);
CheckStatus(env, status);
return handle;
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: free
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_free
(JNIEnv*, jclass, jint handle)
{
HAL_FreeDutyCycle(static_cast<HAL_DutyCycleHandle>(handle));
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: getFrequency
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_getFrequency
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto retVal = HAL_GetDutyCycleFrequency(
static_cast<HAL_DutyCycleHandle>(handle), &status);
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: getOutput
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_getOutput
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto retVal =
HAL_GetDutyCycleOutput(static_cast<HAL_DutyCycleHandle>(handle), &status);
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: getHighTime
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_getHighTime
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto retVal = HAL_GetDutyCycleHighTime(
static_cast<HAL_DutyCycleHandle>(handle), &status);
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: getOutputScaleFactor
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_getOutputScaleFactor
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto retVal = HAL_GetDutyCycleOutputScaleFactor(
static_cast<HAL_DutyCycleHandle>(handle), &status);
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_hal_DutyCycleJNI
* Method: getFPGAIndex
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DutyCycleJNI_getFPGAIndex
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto retVal = HAL_GetDutyCycleFPGAIndex(
static_cast<HAL_DutyCycleHandle>(handle), &status);
CheckStatus(env, status);
return retVal;
}
} // extern "C"