WPILibC++  2019.1.1-beta-4-30-g3635116
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 "frc/AnalogTriggerType.h"
13 #include "frc/ErrorBase.h"
14 #include "frc/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 
30  InterruptableSensorBase& operator=(InterruptableSensorBase&&) = default;
31 
32  virtual HAL_Handle GetPortHandleForRouting() const = 0;
33  virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
34 
43  virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
44  void* param);
45 
53  virtual void RequestInterrupts();
54 
60  virtual void CancelInterrupts();
61 
74  virtual WaitResult WaitForInterrupt(double timeout,
75  bool ignorePrevious = true);
76 
84  virtual void EnableInterrupts();
85 
89  virtual void DisableInterrupts();
90 
100  virtual double ReadRisingTimestamp();
101 
111  virtual double ReadFallingTimestamp();
112 
119  virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
120 
121  protected:
122  HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
123 
124  void AllocateInterrupts(bool watcher);
125 };
126 
127 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: InterruptableSensorBase.h:18
virtual double ReadFallingTimestamp()
Return the timestamp for the falling interrupt that occurred most recently.
virtual WaitResult WaitForInterrupt(double timeout, bool ignorePrevious=true)
In synchronous mode, wait for the defined interrupt to occur.
virtual void RequestInterrupts()
Request one of the 8 interrupts synchronously on this digital input.
virtual void EnableInterrupts()
Enable interrupts to occur on this input.
virtual double ReadRisingTimestamp()
Return the timestamp for the rising interrupt that occurred most recently.
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set which edge to trigger interrupts on.
virtual void CancelInterrupts()
Cancel interrupts on this device.
virtual void DisableInterrupts()
Disable Interrupts without without deallocating structures.