mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Allowed sharing of common C++ code between RoboRIO and Simulation.
Change-Id: I8bf2bda9df389c13ae0567a62dbf0ca931ceb6f8
This commit is contained in:
committed by
Thomas Clark
parent
b371600f0f
commit
7c8124d76c
94
wpilibc/wpilibC++Devices/src/InterruptableSensorBase.cpp
Normal file
94
wpilibc/wpilibC++Devices/src/InterruptableSensorBase.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "InterruptableSensorBase.h"
|
||||
#include "Utility.h"
|
||||
|
||||
Resource *InterruptableSensorBase::m_interrupts = NULL;
|
||||
|
||||
InterruptableSensorBase::InterruptableSensorBase()
|
||||
{
|
||||
m_interrupt = NULL;
|
||||
Resource::CreateResourceObject(&m_interrupts, interrupt_kNumSystems);
|
||||
}
|
||||
|
||||
InterruptableSensorBase::~InterruptableSensorBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::AllocateInterrupts(bool watcher)
|
||||
{
|
||||
wpi_assert(m_interrupt == NULL);
|
||||
// Expects the calling leaf class to allocate an interrupt index.
|
||||
int32_t status = 0;
|
||||
m_interrupt = initializeInterrupts(m_interruptIndex, watcher, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel interrupts on this device.
|
||||
* This deallocates all the chipobject structures and disables any interrupts.
|
||||
*/
|
||||
void InterruptableSensorBase::CancelInterrupts()
|
||||
{
|
||||
wpi_assert(m_interrupt != NULL);
|
||||
int32_t status = 0;
|
||||
cleanInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_interrupt = NULL;
|
||||
m_interrupts->Free(m_interruptIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* In synchronous mode, wait for the defined interrupt to occur.
|
||||
* @param timeout Timeout in seconds
|
||||
*/
|
||||
void InterruptableSensorBase::WaitForInterrupt(float timeout)
|
||||
{
|
||||
wpi_assert(m_interrupt != NULL);
|
||||
int32_t status = 0;
|
||||
waitForInterrupt(m_interrupt, timeout, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable interrupts to occur on this input.
|
||||
* Interrupts are disabled when the RequestInterrupt call is made. This gives time to do the
|
||||
* setup of the other options before starting to field interrupts.
|
||||
*/
|
||||
void InterruptableSensorBase::EnableInterrupts()
|
||||
{
|
||||
wpi_assert(m_interrupt != NULL);
|
||||
int32_t status = 0;
|
||||
enableInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Interrupts without without deallocating structures.
|
||||
*/
|
||||
void InterruptableSensorBase::DisableInterrupts()
|
||||
{
|
||||
wpi_assert(m_interrupt != NULL);
|
||||
int32_t status = 0;
|
||||
disableInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timestamp for the interrupt that occurred most recently.
|
||||
* This is in the same time domain as GetClock().
|
||||
* @return Timestamp in seconds since boot.
|
||||
*/
|
||||
double InterruptableSensorBase::ReadInterruptTimestamp()
|
||||
{
|
||||
wpi_assert(m_interrupt != NULL);
|
||||
int32_t status = 0;
|
||||
double timestamp = readInterruptTimestamp(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return timestamp;
|
||||
}
|
||||
Reference in New Issue
Block a user