WPILibC++  unspecified
InterruptableSensorBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <HAL/Interrupts.h>
11 
12 #include "AnalogTriggerType.h"
13 #include "ErrorBase.h"
14 #include "SmartDashboard/SendableBase.h"
15 
16 namespace frc {
17 
19  public:
20  enum WaitResult {
21  kTimeout = 0x0,
22  kRisingEdge = 0x1,
23  kFallingEdge = 0x100,
24  kBoth = 0x101,
25  };
26 
27  InterruptableSensorBase() = default;
28 
29  virtual HAL_Handle GetPortHandleForRouting() const = 0;
30  virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
31 
40  virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
41  void* param);
42 
50  virtual void RequestInterrupts();
51 
57  virtual void CancelInterrupts();
58 
71  virtual WaitResult WaitForInterrupt(double timeout,
72  bool ignorePrevious = true);
73 
81  virtual void EnableInterrupts();
82 
86  virtual void DisableInterrupts();
87 
97  virtual double ReadRisingTimestamp();
98 
108  virtual double ReadFallingTimestamp();
109 
116  virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
117 
118  protected:
119  HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
120 
121  void AllocateInterrupts(bool watcher);
122 };
123 
124 } // namespace frc
Definition: Utility.cpp:119
virtual void RequestInterrupts()
Request one of the 8 interrupts synchronously on this digital input.
Definition: InterruptableSensorBase.cpp:35
virtual double ReadFallingTimestamp()
Return the timestamp for the falling interrupt that occurred most recently.
Definition: InterruptableSensorBase.cpp:104
Definition: InterruptableSensorBase.h:18
virtual void EnableInterrupts()
Enable interrupts to occur on this input.
Definition: InterruptableSensorBase.cpp:79
virtual double ReadRisingTimestamp()
Return the timestamp for the rising interrupt that occurred most recently.
Definition: InterruptableSensorBase.cpp:95
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set which edge to trigger interrupts on.
Definition: InterruptableSensorBase.cpp:113
Base class for most objects.
Definition: ErrorBase.h:74
virtual void CancelInterrupts()
Cancel interrupts on this device.
Definition: InterruptableSensorBase.cpp:51
Definition: SendableBase.h:19
virtual void DisableInterrupts()
Disable Interrupts without without deallocating structures.
Definition: InterruptableSensorBase.cpp:87
virtual WaitResult WaitForInterrupt(double timeout, bool ignorePrevious=true)
In synchronous mode, wait for the defined interrupt to occur.
Definition: InterruptableSensorBase.cpp:60