mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add lambda overloads for interrupts (#1636)
This commit is contained in:
committed by
Peter Johnson
parent
90957aeea4
commit
7de9477347
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. 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 the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include <hal/Interrupts.h>
|
||||
|
||||
#include "frc/AnalogTriggerType.h"
|
||||
@@ -24,10 +27,22 @@ class InterruptableSensorBase : public ErrorBase, public SendableBase {
|
||||
kBoth = 0x101,
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for interrupts.
|
||||
*
|
||||
* First parameter is if rising, 2nd is if falling.
|
||||
*/
|
||||
using InterruptEventHandler = std::function<void(WaitResult)>;
|
||||
|
||||
InterruptableSensorBase() = default;
|
||||
|
||||
InterruptableSensorBase(InterruptableSensorBase&&) = default;
|
||||
InterruptableSensorBase& operator=(InterruptableSensorBase&&) = default;
|
||||
/**
|
||||
* Free the resources for an interrupt event.
|
||||
*/
|
||||
virtual ~InterruptableSensorBase();
|
||||
|
||||
InterruptableSensorBase(InterruptableSensorBase&&);
|
||||
InterruptableSensorBase& operator=(InterruptableSensorBase&&);
|
||||
|
||||
virtual HAL_Handle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
@@ -43,6 +58,16 @@ class InterruptableSensorBase : public ErrorBase, public SendableBase {
|
||||
virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
|
||||
void* param);
|
||||
|
||||
/**
|
||||
* Request one of the 8 interrupts asynchronously on this digital input.
|
||||
*
|
||||
* Request interrupts in asynchronous mode where the user's interrupt handler
|
||||
* will be called when the interrupt fires. Users that want control over the
|
||||
* thread priority should use the synchronous method with their own spawned
|
||||
* thread. The default is interrupt on rising edges only.
|
||||
*/
|
||||
virtual void RequestInterrupts(InterruptEventHandler handler);
|
||||
|
||||
/**
|
||||
* Request one of the 8 interrupts synchronously on this digital input.
|
||||
*
|
||||
@@ -119,7 +144,8 @@ class InterruptableSensorBase : public ErrorBase, public SendableBase {
|
||||
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
|
||||
|
||||
protected:
|
||||
HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
|
||||
// atomic for proper destruction
|
||||
std::atomic<HAL_InterruptHandle> m_interrupt{HAL_kInvalidHandle};
|
||||
|
||||
void AllocateInterrupts(bool watcher);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user