Files
allwpilib/hal/src/main/native/cpp/jni/PDPJNI.cpp
Peter Johnson 8f1f64ffb6 Remove year from file copyright message (NFC) (#2972)
Also update copyright to include "and other WPILib contributors" and clarify
license referral language to not be restricted to FIRST teams.
2020-12-26 14:12:05 -08:00

191 lines
4.3 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 "HALUtil.h"
#include "edu_wpi_first_hal_PDPJNI.h"
#include "hal/PDP.h"
#include "hal/Ports.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: initializePDP
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PDPJNI_initializePDP
(JNIEnv* env, jclass, jint module)
{
int32_t status = 0;
auto handle = HAL_InitializePDP(module, &status);
CheckStatusRange(env, status, 0, HAL_GetNumPDPModules(), module);
return static_cast<jint>(handle);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPChannel
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPChannel
(JNIEnv* env, jclass, jint channel)
{
return HAL_CheckPDPChannel(channel);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPModule
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPModule
(JNIEnv* env, jclass, jint module)
{
return HAL_CheckPDPModule(module);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTemperature
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double temperature = HAL_GetPDPTemperature(handle, &status);
CheckStatus(env, status, false);
return temperature;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPVoltage
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPVoltage
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double voltage = HAL_GetPDPVoltage(handle, &status);
CheckStatus(env, status, false);
return voltage;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPChannelCurrent
* Signature: (BI)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPChannelCurrent
(JNIEnv* env, jclass, jbyte channel, jint handle)
{
int32_t status = 0;
double current = HAL_GetPDPChannelCurrent(handle, channel, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPAllCurrents
* Signature: (I[D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPAllCurrents
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
{
double storage[16];
int32_t status = 0;
HAL_GetPDPAllChannelCurrents(handle, storage, &status);
if (!CheckStatus(env, status, false)) {
return;
}
env->SetDoubleArrayRegion(jarr, 0, 16, storage);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalCurrent
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalCurrent
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double current = HAL_GetPDPTotalCurrent(handle, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalPower
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalPower
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double power = HAL_GetPDPTotalPower(handle, &status);
CheckStatus(env, status, false);
return power;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalEnergy
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double energy = HAL_GetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
return energy;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: resetPDPTotalEnergy
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_resetPDPTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ResetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: clearPDPStickyFaults
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_clearPDPStickyFaults
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ClearPDPStickyFaults(handle, &status);
CheckStatus(env, status, false);
}
} // extern "C"