WPILibC++  2018.4.1-20180729040223-1137-g011f0ff
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/mutex.h>
15 
16 #include "frc/DigitalSource.h"
17 #include "frc/ErrorBase.h"
18 #include "frc/smartdashboard/SendableBase.h"
19 
20 namespace frc {
21 
22 class Encoder;
23 class Counter;
24 
32 class DigitalGlitchFilter : public ErrorBase, public SendableBase {
33  public:
35  ~DigitalGlitchFilter() override;
36 
42  void Add(DigitalSource* input);
43 
49  void Add(Encoder* input);
50 
56  void Add(Counter* input);
57 
66  void Remove(DigitalSource* input);
67 
76  void Remove(Encoder* input);
77 
86  void Remove(Counter* input);
87 
93  void SetPeriodCycles(int fpgaCycles);
94 
100  void SetPeriodNanoSeconds(uint64_t nanoseconds);
101 
107  int GetPeriodCycles();
108 
114  uint64_t GetPeriodNanoSeconds();
115 
116  void InitSendable(SendableBuilder& builder) override;
117 
118  private:
119  // Sets the filter for the input to be the requested index. A value of 0
120  // disables the filter, and the filter value must be between 1 and 3,
121  // inclusive.
122  void DoAdd(DigitalSource* input, int requested_index);
123 
124  int m_channelIndex = -1;
125  static wpi::mutex m_mutex;
126  static std::array<bool, 3> m_filterAllocated;
127 };
128 
129 } // namespace frc
Definition: SPIAccelerometerSim.h:18
void SetPeriodCycles(int fpgaCycles)
Sets the number of cycles that the input must not change state for.
Class to read quad encoders.
Definition: Encoder.h:40
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:32
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:34
void Add(DigitalSource *input)
Assigns the DigitalSource to this glitch filter.
void SetPeriodNanoSeconds(uint64_t nanoseconds)
Sets the number of nanoseconds that the input must not change state for.
DigitalSource Interface.
Definition: DigitalSource.h:25
int GetPeriodCycles()
Gets the number of cycles that the input must not change state for.
void Remove(DigitalSource *input)
Removes a digital input from this filter.
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
Definition: SendableBuilder.h:23
uint64_t GetPeriodNanoSeconds()
Gets the number of nanoseconds that the input must not change state for.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.