Files
allwpilib/hal/src/main/native/cpp/jni/DIOJNI.cpp

254 lines
5.9 KiB
C++
Raw Normal View History

/*----------------------------------------------------------------------------*/
2019-09-06 18:42:40 -07:00
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <jni.h>
2014-01-06 09:27:51 -05:00
2018-05-13 17:09:56 -07:00
#include <cassert>
2014-01-06 09:27:51 -05:00
2018-05-13 17:09:56 -07:00
#include "HALUtil.h"
#include "edu_wpi_first_hal_DIOJNI.h"
#include "hal/DIO.h"
#include "hal/PWM.h"
#include "hal/Ports.h"
#include "hal/handles/HandlesInternal.h"
2014-01-06 09:27:51 -05:00
using namespace frc;
extern "C" {
2014-01-06 09:27:51 -05:00
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 21:39:09 -07:00
* Method: initializeDIOPort
2018-05-13 17:09:56 -07:00
* Signature: (IZ)I
2014-01-06 09:27:51 -05:00
*/
2016-06-30 21:39:09 -07:00
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jboolean input)
{
int32_t status = 0;
2018-05-13 17:09:56 -07:00
auto dio = HAL_InitializeDIOPort((HAL_PortHandle)id,
static_cast<uint8_t>(input), &status);
CheckStatusRange(env, status, 0, HAL_GetNumDigitalChannels(),
hal::getPortHandleChannel((HAL_PortHandle)id));
2016-06-30 21:39:09 -07:00
return (jint)dio;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: checkDIOChannel
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_DIOJNI_checkDIOChannel
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint channel)
{
return HAL_CheckDIOChannel(channel);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: freeDIOPort
2018-05-13 17:09:56 -07:00
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_freeDIOPort
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
HAL_FreeDIOPort((HAL_DigitalHandle)id);
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: setDIO
2016-06-30 21:39:09 -07:00
* Signature: (IS)V
2014-01-06 09:27:51 -05:00
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDIO
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jshort value)
{
int32_t status = 0;
HAL_SetDIO((HAL_DigitalHandle)id, value, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
* Method: setDIODirection
* Signature: (IZ)V
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDIODirection
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jboolean input)
{
int32_t status = 0;
HAL_SetDIODirection((HAL_DigitalHandle)id, input, &status);
CheckStatus(env, status);
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: getDIO
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_DIOJNI_getDIO
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
jboolean returnValue = HAL_GetDIO((HAL_DigitalHandle)id, &status);
CheckStatus(env, status);
return returnValue;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: getDIODirection
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_DIOJNI_getDIODirection
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
jboolean returnValue = HAL_GetDIODirection((HAL_DigitalHandle)id, &status);
CheckStatus(env, status);
return returnValue;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: pulse
2018-05-13 17:09:56 -07:00
* Signature: (ID)V
2014-01-06 09:27:51 -05:00
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_pulse
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jdouble value)
{
int32_t status = 0;
HAL_Pulse((HAL_DigitalHandle)id, value, &status);
CheckStatus(env, status);
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: isPulsing
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_DIOJNI_isPulsing
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
jboolean returnValue = HAL_IsPulsing((HAL_DigitalHandle)id, &status);
CheckStatus(env, status);
return returnValue;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: isAnyPulsing
* Signature: ()Z
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_DIOJNI_isAnyPulsing
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass)
{
int32_t status = 0;
jboolean returnValue = HAL_IsAnyPulsing(&status);
CheckStatus(env, status);
return returnValue;
2014-01-06 09:27:51 -05:00
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2014-01-06 09:27:51 -05:00
* Method: getLoopTiming
* Signature: ()S
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jshort JNICALL
Java_edu_wpi_first_hal_DIOJNI_getLoopTiming
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass)
{
int32_t status = 0;
jshort returnValue = HAL_GetPWMLoopTiming(&status);
CheckStatus(env, status);
return returnValue;
2014-01-06 09:27:51 -05:00
}
2016-06-30 23:43:00 -07:00
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 23:43:00 -07:00
* Method: allocateDigitalPWM
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_DIOJNI_allocateDigitalPWM
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass)
{
2016-06-30 23:43:00 -07:00
int32_t status = 0;
auto pwm = HAL_AllocateDigitalPWM(&status);
2016-06-30 23:43:00 -07:00
CheckStatus(env, status);
return (jint)pwm;
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 23:43:00 -07:00
* Method: freeDigitalPWM
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_freeDigitalPWM
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
2016-06-30 23:43:00 -07:00
int32_t status = 0;
HAL_FreeDigitalPWM((HAL_DigitalPWMHandle)id, &status);
2016-06-30 23:43:00 -07:00
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 23:43:00 -07:00
* Method: setDigitalPWMRate
* Signature: (D)V
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDigitalPWMRate
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jdouble value)
{
2016-06-30 23:43:00 -07:00
int32_t status = 0;
HAL_SetDigitalPWMRate(value, &status);
2016-06-30 23:43:00 -07:00
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 23:43:00 -07:00
* Method: setDigitalPWMDutyCycle
* Signature: (ID)V
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDigitalPWMDutyCycle
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jdouble value)
{
2016-06-30 23:43:00 -07:00
int32_t status = 0;
HAL_SetDigitalPWMDutyCycle((HAL_DigitalPWMHandle)id, value, &status);
2016-06-30 23:43:00 -07:00
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_DIOJNI
2016-06-30 23:43:00 -07:00
* Method: setDigitalPWMOutputChannel
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_DIOJNI_setDigitalPWMOutputChannel
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jint value)
{
2016-06-30 23:43:00 -07:00
int32_t status = 0;
2018-05-13 17:09:56 -07:00
HAL_SetDigitalPWMOutputChannel((HAL_DigitalPWMHandle)id,
static_cast<uint32_t>(value), &status);
2016-06-30 23:43:00 -07:00
CheckStatus(env, status);
}
} // extern "C"