WPILibC++  unspecified
DigitalGlitchFilter.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-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 <stdint.h>
11 
12 #include <array>
13 
14 #include <support/mutex.h>
15 
16 #include "DigitalSource.h"
17 #include "SensorBase.h"
18 
19 namespace frc {
20 
21 class Encoder;
22 class Counter;
23 
32  public:
34  ~DigitalGlitchFilter() override;
35 
36  void Add(DigitalSource* input);
37  void Add(Encoder* input);
38  void Add(Counter* input);
39 
40  void Remove(DigitalSource* input);
41  void Remove(Encoder* input);
42  void Remove(Counter* input);
43 
44  void SetPeriodCycles(int fpgaCycles);
45  void SetPeriodNanoSeconds(uint64_t nanoseconds);
46 
47  int GetPeriodCycles();
48  uint64_t GetPeriodNanoSeconds();
49 
50  void InitSendable(SendableBuilder& builder) override;
51 
52  private:
53  // Sets the filter for the input to be the requested index. A value of 0
54  // disables the filter, and the filter value must be between 1 and 3,
55  // inclusive.
56  void DoAdd(DigitalSource* input, int requested_index);
57 
58  int m_channelIndex = -1;
59  static wpi::mutex m_mutex;
60  static std::array<bool, 3> m_filterAllocated;
61 };
62 
63 } // namespace frc
Definition: RobotController.cpp:14
Base class for all sensors.
Definition: SensorBase.h:25
Class to read quad encoders.
Definition: Encoder.h:39
void SetPeriodNanoSeconds(uint64_t nanoseconds)
Sets the number of nanoseconds that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:166
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:31
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:33
uint64_t GetPeriodNanoSeconds()
Gets the number of nanoseconds that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:194
DigitalSource Interface.
Definition: DigitalSource.h:25
void Remove(DigitalSource *input)
Removes a digital input from this filter.
Definition: DigitalGlitchFilter.cpp:116
int GetPeriodCycles()
Gets the number of cycles that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:180
void SetPeriodCycles(int fpgaCycles)
Sets the number of cycles that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:155
Definition: SendableBuilder.h:23
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: DigitalGlitchFilter.cpp:204
void Add(DigitalSource *input)
Assigns the DigitalSource to this glitch filter.
Definition: DigitalGlitchFilter.cpp:53