[wpilib] Don't print PD errors for LiveWindow reads (#3708)

If something happens with the PD connection, these would have spammed messages continuously.
This wasn't the case previously, and we don't want this behavior now.
This commit is contained in:
Thad House
2021-11-07 13:45:28 -08:00
committed by GitHub
parent 7699a1f827
commit 3dd41c0d37
4 changed files with 117 additions and 9 deletions

View File

@@ -46,4 +46,14 @@ public class PowerDistributionJNI extends JNIWrapper {
public static native boolean getSwitchableChannel(int handle);
public static native void setSwitchableChannel(int handle, boolean enabled);
public static native double getVoltageNoError(int handle);
public static native double getChannelCurrentNoError(int handle, int channel);
public static native double getTotalCurrentNoError(int handle);
public static native boolean getSwitchableChannelNoError(int handle);
public static native void setSwitchableChannelNoError(int handle, boolean enabled);
}

View File

@@ -292,4 +292,74 @@ Java_edu_wpi_first_hal_PowerDistributionJNI_getSwitchableChannel
return state;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getVoltageNoError
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getVoltageNoError
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double voltage = HAL_GetPowerDistributionVoltage(handle, &status);
return voltage;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getChannelCurrentNoError
* Signature: (II)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getChannelCurrentNoError
(JNIEnv* env, jclass, jint handle, jint channel)
{
int32_t status = 0;
double current =
HAL_GetPowerDistributionChannelCurrent(handle, channel, &status);
return current;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getTotalCurrentNoError
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalCurrentNoError
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double current = HAL_GetPowerDistributionTotalCurrent(handle, &status);
return current;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: setSwitchableChannelNoError
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_setSwitchableChannelNoError
(JNIEnv* env, jclass, jint handle, jboolean enabled)
{
int32_t status = 0;
HAL_SetPowerDistributionSwitchableChannel(handle, enabled, &status);
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getSwitchableChannelNoError
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getSwitchableChannelNoError
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto state = HAL_GetPowerDistributionSwitchableChannel(handle, &status);
return state;
}
} // extern "C"

View File

@@ -132,15 +132,38 @@ void PowerDistribution::InitSendable(wpi::SendableBuilder& builder) {
int32_t status = 0;
int numChannels = HAL_GetPowerDistributionNumChannels(m_handle, &status);
FRC_ReportError(status, "Module {}", m_module);
// Use manual reads to avoid printing errors
for (int i = 0; i < numChannels; ++i) {
builder.AddDoubleProperty(
fmt::format("Chan{}", i), [=] { return GetCurrent(i); }, nullptr);
fmt::format("Chan{}", i),
[=] {
int32_t lStatus = 0;
return HAL_GetPowerDistributionChannelCurrent(m_handle, i, &lStatus);
},
nullptr);
}
builder.AddDoubleProperty(
"Voltage", [=] { return GetVoltage(); }, nullptr);
"Voltage",
[=] {
int32_t lStatus = 0;
return HAL_GetPowerDistributionVoltage(m_handle, &lStatus);
},
nullptr);
builder.AddDoubleProperty(
"TotalCurrent", [=] { return GetTotalCurrent(); }, nullptr);
"TotalCurrent",
[=] {
int32_t lStatus = 0;
return HAL_GetPowerDistributionTotalCurrent(m_handle, &lStatus);
},
nullptr);
builder.AddBooleanProperty(
"SwitchableChannel", [=] { return GetSwitchableChannel(); },
[=](bool value) { SetSwitchableChannel(value); });
"SwitchableChannel",
[=] {
int32_t lStatus = 0;
return HAL_GetPowerDistributionSwitchableChannel(m_handle, &lStatus);
},
[=](bool value) {
int32_t lStatus = 0;
HAL_SetPowerDistributionSwitchableChannel(m_handle, value, &lStatus);
});
}

View File

@@ -160,11 +160,16 @@ public class PowerDistribution implements Sendable, AutoCloseable {
int numChannels = getNumChannels();
for (int i = 0; i < numChannels; ++i) {
final int chan = i;
builder.addDoubleProperty("Chan" + i, () -> getCurrent(chan), null);
builder.addDoubleProperty(
"Chan" + i, () -> PowerDistributionJNI.getChannelCurrentNoError(m_handle, chan), null);
}
builder.addDoubleProperty("Voltage", this::getVoltage, null);
builder.addDoubleProperty("TotalCurrent", this::getTotalCurrent, null);
builder.addDoubleProperty(
"Voltage", () -> PowerDistributionJNI.getVoltageNoError(m_handle), null);
builder.addDoubleProperty(
"TotalCurrent", () -> PowerDistributionJNI.getTotalCurrent(m_handle), null);
builder.addBooleanProperty(
"SwitchableChannel", this::getSwitchableChannel, this::setSwitchableChannel);
"SwitchableChannel",
() -> PowerDistributionJNI.getSwitchableChannelNoError(m_handle),
value -> PowerDistributionJNI.setSwitchableChannel(m_handle, value));
}
}