mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Move interrupt methods to InterruptableSensorBase
Analog interrupts work again now, and RequestInterrupts is no longer duplicated three times. Change-Id: I5244b76262d7620852141cd21b2429d627636793
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "InterruptableSensorBase.h"
|
||||
#include "Utility.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
Resource *InterruptableSensorBase::m_interrupts = NULL;
|
||||
|
||||
@@ -20,6 +21,54 @@ InterruptableSensorBase::~InterruptableSensorBase()
|
||||
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(InterruptHandlerFunction handler, void *param)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
uint32_t index = m_interrupts->Allocate("Async Interrupt");
|
||||
if (index == ~0ul)
|
||||
{
|
||||
CloneError(m_interrupts);
|
||||
return;
|
||||
}
|
||||
m_interruptIndex = index;
|
||||
|
||||
// Creates a manager too
|
||||
AllocateInterrupts(false);
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
GetAnalogTriggerForRouting(), &status);
|
||||
SetUpSourceEdge(true, false);
|
||||
attachInterruptHandler(m_interrupt, handler, param, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request interrupts synchronously on this digital input.
|
||||
* Request interrupts in synchronus mode where the user program will have to explicitly
|
||||
* wait for the interrupt to occur.
|
||||
* The default is interrupt on rising edges only.
|
||||
*/
|
||||
void InterruptableSensorBase::RequestInterrupts()
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
uint32_t index = m_interrupts->Allocate("Sync Interrupt");
|
||||
if (index == ~0ul)
|
||||
{
|
||||
CloneError(m_interrupts);
|
||||
return;
|
||||
}
|
||||
m_interruptIndex = index;
|
||||
|
||||
AllocateInterrupts(true);
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
GetAnalogTriggerForRouting(), &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
SetUpSourceEdge(true, false);
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::AllocateInterrupts(bool watcher)
|
||||
{
|
||||
wpi_assert(m_interrupt == NULL);
|
||||
@@ -117,3 +166,27 @@ double InterruptableSensorBase::ReadFallingTimestamp()
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which edge to trigger interrupts on
|
||||
*
|
||||
* @param risingEdge
|
||||
* true to interrupt on rising edge
|
||||
* @param fallingEdge
|
||||
* true to interrupt on falling edge
|
||||
*/
|
||||
void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge, bool fallingEdge)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_interrupt == NULL)
|
||||
{
|
||||
wpi_setWPIErrorWithContext(NullParameter, "You must call RequestInterrupts before SetUpSourceEdge");
|
||||
return;
|
||||
}
|
||||
if (m_interrupt != NULL)
|
||||
{
|
||||
int32_t status = 0;
|
||||
setInterruptUpSourceEdge(m_interrupt, risingEdge, fallingEdge, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user