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

120 lines
2.9 KiB
C++
Raw Normal View History

// 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>
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"
2025-11-07 19:55:43 -05:00
#include "org_wpilib_hardware_hal_PWMJNI.h"
2025-11-07 19:56:21 -05:00
#include "wpi/hal/DIO.h"
#include "wpi/hal/PWM.h"
#include "wpi/hal/Ports.h"
#include "wpi/hal/handles/HandlesInternal.h"
2025-11-07 19:57:55 -05:00
#include "wpi/util/jni_util.hpp"
2014-01-06 09:27:51 -05:00
2025-11-07 20:00:05 -05:00
using namespace wpi::hal;
extern "C" {
2014-01-06 09:27:51 -05:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
2016-06-30 21:39:09 -07:00
* Method: initializePWMPort
2018-05-13 17:09:56 -07:00
* Signature: (I)I
*/
2016-06-30 21:39:09 -07:00
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_initializePWMPort
2025-01-30 18:59:34 -08:00
(JNIEnv* env, jclass, jint channel)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2025-11-07 20:00:05 -05:00
auto stack = wpi::util::java::GetJavaStackTrace(env, "edu.wpi.first");
2025-01-30 18:59:34 -08:00
auto pwm = HAL_InitializePWMPort(channel, stack.c_str(), &status);
CheckStatusForceThrow(env, status);
2016-06-30 21:39:09 -07:00
return (jint)pwm;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
* Method: checkPWMChannel
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_checkPWMChannel
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint channel)
{
return HAL_CheckPWMChannel(channel);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
2018-05-13 17:09:56 -07:00
* Method: freePWMPort
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_freePWMPort
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
if (id != HAL_kInvalidHandle) {
HAL_FreePWMPort((HAL_DigitalHandle)id);
}
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
* Method: setPWMSimDevice
* Signature: (II)V
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_setPWMSimDevice
(JNIEnv* env, jclass, jint handle, jint device)
2018-05-13 17:09:56 -07:00
{
HAL_SetPWMSimDevice((HAL_DigitalHandle)handle, (HAL_SimDeviceHandle)device);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
* Method: setPulseTimeMicroseconds
* Signature: (II)V
2014-01-06 09:27:51 -05:00
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_setPulseTimeMicroseconds
(JNIEnv* env, jclass, jint id, jint value)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
HAL_SetPWMPulseTimeMicroseconds((HAL_DigitalHandle)id, value, &status);
CheckStatus(env, status);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
* Method: getPulseTimeMicroseconds
* Signature: (I)I
2014-01-06 09:27:51 -05:00
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_getPulseTimeMicroseconds
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id)
{
int32_t status = 0;
int32_t returnValue =
HAL_GetPWMPulseTimeMicroseconds((HAL_DigitalHandle)id, &status);
CheckStatus(env, status);
return returnValue;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_PWMJNI
* Method: setPWMOutputPeriod
2016-06-30 21:39:09 -07:00
* Signature: (II)V
2014-01-06 09:27:51 -05:00
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_PWMJNI_setPWMOutputPeriod
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint id, jint value)
{
int32_t status = 0;
HAL_SetPWMOutputPeriod((HAL_DigitalHandle)id, value, &status);
CheckStatus(env, status);
2014-01-06 09:27:51 -05:00
}
} // extern "C"