WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
InterruptableSensorBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 "AnalogTriggerType.h"
11 #include "HAL/Interrupts.h"
12 #include "SensorBase.h"
13 
14 namespace frc {
15 
17  public:
18  enum WaitResult {
19  kTimeout = 0x0,
20  kRisingEdge = 0x1,
21  kFallingEdge = 0x100,
22  kBoth = 0x101,
23  };
24 
25  InterruptableSensorBase() = default;
26  virtual ~InterruptableSensorBase() = default;
27 
28  virtual HAL_Handle GetPortHandleForRouting() const = 0;
29  virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
30  virtual void RequestInterrupts(
31  HAL_InterruptHandlerFunction handler,
32  void* param);
33  virtual void RequestInterrupts();
34  virtual void
36  virtual WaitResult WaitForInterrupt(
37  double timeout,
38  bool ignorePrevious = true);
39  virtual void
41  virtual void DisableInterrupts();
42  virtual double ReadRisingTimestamp();
43  virtual double ReadFallingTimestamp();
45  virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
47 
48  protected:
49  HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
50  void AllocateInterrupts(bool watcher);
51 };
52 
53 } // namespace frc
virtual void RequestInterrupts()
Synchronus Wait version.
Definition: InterruptableSensorBase.cpp:49
virtual double ReadFallingTimestamp()
Return the timestamp for the falling interrupt that occurred.
Definition: InterruptableSensorBase.cpp:171
Definition: InterruptableSensorBase.h:16
Base class for all sensors.
Definition: SensorBase.h:20
virtual void EnableInterrupts()
Enable interrupts - after finishing setup.
Definition: InterruptableSensorBase.cpp:125
virtual double ReadRisingTimestamp()
Return the timestamp for the rising interrupt that occurred.
Definition: InterruptableSensorBase.cpp:153
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set which edge to trigger interrupts on.
Definition: InterruptableSensorBase.cpp:186
virtual void CancelInterrupts()
Free up the underlying chipobject functions.
Definition: InterruptableSensorBase.cpp:78
virtual void DisableInterrupts()
Disable, but don't deallocate.
Definition: InterruptableSensorBase.cpp:136
virtual WaitResult WaitForInterrupt(double timeout, bool ignorePrevious=true)
Synchronus version.
Definition: InterruptableSensorBase.cpp:99