WPILibC++  unspecified
InterruptableSensorBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 "SensorBase.h"
14 
15 namespace frc {
16 
18  public:
19  enum WaitResult {
20  kTimeout = 0x0,
21  kRisingEdge = 0x1,
22  kFallingEdge = 0x100,
23  kBoth = 0x101,
24  };
25 
26  InterruptableSensorBase() = default;
27  virtual ~InterruptableSensorBase() = default;
28 
29  virtual HAL_Handle GetPortHandleForRouting() const = 0;
30  virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
31  virtual void RequestInterrupts(
32  HAL_InterruptHandlerFunction handler,
33  void* param);
34  virtual void RequestInterrupts();
35  virtual void
37  virtual WaitResult WaitForInterrupt(
38  double timeout,
39  bool ignorePrevious = true);
40  virtual void
42  virtual void DisableInterrupts();
43  virtual double ReadRisingTimestamp();
44  virtual double ReadFallingTimestamp();
46  virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
48 
49  protected:
50  HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
51  void AllocateInterrupts(bool watcher);
52 };
53 
54 } // namespace frc
Definition: Timer.cpp:18
virtual void RequestInterrupts()
Synchronus Wait version.
Definition: InterruptableSensorBase.cpp:50
virtual double ReadFallingTimestamp()
Return the timestamp for the falling interrupt that occurred.
Definition: InterruptableSensorBase.cpp:172
Definition: InterruptableSensorBase.h:17
Base class for all sensors.
Definition: SensorBase.h:20
virtual void EnableInterrupts()
Enable interrupts - after finishing setup.
Definition: InterruptableSensorBase.cpp:126
virtual double ReadRisingTimestamp()
Return the timestamp for the rising interrupt that occurred.
Definition: InterruptableSensorBase.cpp:154
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set which edge to trigger interrupts on.
Definition: InterruptableSensorBase.cpp:187
virtual void CancelInterrupts()
Free up the underlying chipobject functions.
Definition: InterruptableSensorBase.cpp:79
virtual void DisableInterrupts()
Disable, but don&#39;t deallocate.
Definition: InterruptableSensorBase.cpp:137
virtual WaitResult WaitForInterrupt(double timeout, bool ignorePrevious=true)
Synchronus version.
Definition: InterruptableSensorBase.cpp:100