WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
DigitalGlitchFilter.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2015-2017. 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 "DigitalSource.h"
15 #include "HAL/cpp/priority_mutex.h"
16 
17 namespace frc {
18 
19 class Encoder;
20 class Counter;
21 
29  public:
32 
33  void Add(DigitalSource* input);
34  void Add(Encoder* input);
35  void Add(Counter* input);
36 
37  void Remove(DigitalSource* input);
38  void Remove(Encoder* input);
39  void Remove(Counter* input);
40 
41  void SetPeriodCycles(int fpga_cycles);
42  void SetPeriodNanoSeconds(uint64_t nanoseconds);
43 
44  int GetPeriodCycles();
45  uint64_t GetPeriodNanoSeconds();
46 
47  private:
48  // Sets the filter for the input to be the requested index. A value of 0
49  // disables the filter, and the filter value must be between 1 and 3,
50  // inclusive.
51  void DoAdd(DigitalSource* input, int requested_index);
52 
53  int m_channelIndex = -1;
54  static hal::priority_mutex m_mutex;
55  static std::array<bool, 3> m_filterAllocated;
56 };
57 
58 } // namespace frc
void SetPeriodCycles(int fpga_cycles)
Sets the number of cycles that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:153
Base class for all sensors.
Definition: SensorBase.h:20
Class to read quad encoders.
Definition: Encoder.h:40
void SetPeriodNanoSeconds(uint64_t nanoseconds)
Sets the number of nanoseconds that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:164
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:28
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:34
uint64_t GetPeriodNanoSeconds()
Gets the number of nanoseconds that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:192
DigitalSource Interface.
Definition: DigitalSource.h:25
void Remove(DigitalSource *input)
Removes a digital input from this filter.
Definition: DigitalGlitchFilter.cpp:114
int GetPeriodCycles()
Gets the number of cycles that the input must not change state for.
Definition: DigitalGlitchFilter.cpp:178
Definition: priority_mutex.h:57
void Add(DigitalSource *input)
Assigns the DigitalSource to this glitch filter.
Definition: DigitalGlitchFilter.cpp:51