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 "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 
28  virtual HAL_Handle GetPortHandleForRouting() const = 0;
29  virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
30 
31  // Asynchronous handler version.
32  virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
33  void* param);
34 
35  // Synchronous wait version.
36  virtual void RequestInterrupts();
37 
38  // Free up the underlying ChipObject functions.
39  virtual void CancelInterrupts();
40 
41  // Synchronous version.
42  virtual WaitResult WaitForInterrupt(double timeout,
43  bool ignorePrevious = true);
44 
45  // Enable interrupts - after finishing setup.
46  virtual void EnableInterrupts();
47 
48  // Disable, but don't deallocate.
49  virtual void DisableInterrupts();
50 
51  // Return the timestamp for the rising interrupt that occurred.
52  virtual double ReadRisingTimestamp();
53 
54  // Return the timestamp for the falling interrupt that occurred.
55  virtual double ReadFallingTimestamp();
56 
57  virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
58 
59  protected:
60  HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
61  void AllocateInterrupts(bool watcher);
62 };
63 
64 } // namespace frc
Definition: RobotController.cpp:14
virtual void RequestInterrupts()
Request one of the 8 interrupts synchronously on this digital input.
Definition: InterruptableSensorBase.cpp:50
virtual double ReadFallingTimestamp()
Return the timestamp for the falling interrupt that occurred most recently.
Definition: InterruptableSensorBase.cpp:172
Definition: InterruptableSensorBase.h:17
Base class for all sensors.
Definition: SensorBase.h:25
virtual void EnableInterrupts()
Enable interrupts to occur on this input.
Definition: InterruptableSensorBase.cpp:126
virtual double ReadRisingTimestamp()
Return the timestamp for the rising interrupt that occurred most recently.
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()
Cancel interrupts on this device.
Definition: InterruptableSensorBase.cpp:79
virtual void DisableInterrupts()
Disable Interrupts without without deallocating structures.
Definition: InterruptableSensorBase.cpp:137
virtual WaitResult WaitForInterrupt(double timeout, bool ignorePrevious=true)
In synchronous mode, wait for the defined interrupt to occur.
Definition: InterruptableSensorBase.cpp:100