mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Fixes WaitForInterrupt to return values matching enum (#503)
This commit is contained in:
committed by
Peter Johnson
parent
f0c413f40d
commit
d348a5b947
@@ -108,7 +108,13 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
result = HAL_WaitForInterrupt(m_interrupt, timeout, ignorePrevious, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
|
||||
return static_cast<WaitResult>(result);
|
||||
// Rising edge result is the interrupt bit set in the byte 0xFF
|
||||
// Falling edge result is the interrupt bit set in the byte 0xFF00
|
||||
// Set any bit set to be true for that edge, and AND the 2 results
|
||||
// together to match the existing enum for all interrupts
|
||||
int32_t rising = (result & 0xFF) ? 0x1 : 0x0;
|
||||
int32_t falling = ((result & 0xFF00) ? 0x0100 : 0x0);
|
||||
return static_cast<WaitResult>(falling | rising);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -142,6 +142,14 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
}
|
||||
int result = InterruptJNI.waitForInterrupt(m_interrupt, timeout, ignorePrevious);
|
||||
|
||||
// Rising edge result is the interrupt bit set in the byte 0xFF
|
||||
// Falling edge result is the interrupt bit set in the byte 0xFF00
|
||||
// Set any bit set to be true for that edge, and AND the 2 results
|
||||
// together to match the existing enum for all interrupts
|
||||
int rising = ((result & 0xFF) != 0) ? 0x1 : 0x0;
|
||||
int falling = ((result & 0xFF00) != 0) ? 0x0100 : 0x0;
|
||||
result = rising | falling;
|
||||
|
||||
for (WaitResult mode : WaitResult.values()) {
|
||||
if (mode.value == result) {
|
||||
return mode;
|
||||
|
||||
Reference in New Issue
Block a user