WPILibC++  2020.2.2-33-g65eab93
DigitalGlitchFilter.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-2019 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 <stdint.h>
11 
12 #include <array>
13 
14 #include <wpi/mutex.h>
15 
16 #include "frc/DigitalSource.h"
17 #include "frc/ErrorBase.h"
18 #include "frc/smartdashboard/Sendable.h"
19 #include "frc/smartdashboard/SendableHelper.h"
20 
21 namespace frc {
22 
23 class Encoder;
24 class Counter;
25 
34  public Sendable,
35  public SendableHelper<DigitalGlitchFilter> {
36  public:
38  ~DigitalGlitchFilter() override;
39 
41  DigitalGlitchFilter& operator=(DigitalGlitchFilter&& rhs);
42 
48  void Add(DigitalSource* input);
49 
55  void Add(Encoder* input);
56 
62  void Add(Counter* input);
63 
72  void Remove(DigitalSource* input);
73 
82  void Remove(Encoder* input);
83 
92  void Remove(Counter* input);
93 
99  void SetPeriodCycles(int fpgaCycles);
100 
106  void SetPeriodNanoSeconds(uint64_t nanoseconds);
107 
113  int GetPeriodCycles();
114 
120  uint64_t GetPeriodNanoSeconds();
121 
122  void InitSendable(SendableBuilder& builder) override;
123 
124  private:
125  // Sets the filter for the input to be the requested index. A value of 0
126  // disables the filter, and the filter value must be between 1 and 3,
127  // inclusive.
128  void DoAdd(DigitalSource* input, int requested_index);
129 
130  int m_channelIndex = -1;
131  static wpi::mutex m_mutex;
132  static std::array<bool, 3> m_filterAllocated;
133 };
134 
135 } // namespace frc
frc::DigitalGlitchFilter::Add
void Add(DigitalSource *input)
Assigns the DigitalSource to this glitch filter.
frc::DigitalGlitchFilter::SetPeriodCycles
void SetPeriodCycles(int fpgaCycles)
Sets the number of cycles that the input must not change state for.
frc::DigitalGlitchFilter::Remove
void Remove(DigitalSource *input)
Removes a digital input from this filter.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::DigitalGlitchFilter::GetPeriodCycles
int GetPeriodCycles()
Gets the number of cycles that the input must not change state for.
frc::DigitalGlitchFilter
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:33
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::DigitalGlitchFilter::SetPeriodNanoSeconds
void SetPeriodNanoSeconds(uint64_t nanoseconds)
Sets the number of nanoseconds that the input must not change state for.
frc::Encoder
Class to read quad encoders.
Definition: Encoder.h:44
frc::DigitalGlitchFilter::GetPeriodNanoSeconds
uint64_t GetPeriodNanoSeconds()
Gets the number of nanoseconds that the input must not change state for.
frc
WPILib FRC namespace.
Definition: AnalogOutSim.h:16
frc::Counter
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:37
frc::DigitalGlitchFilter::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::DigitalSource
DigitalSource Interface.
Definition: DigitalSource.h:25
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23