WPILibC++  2019.1.1-beta-2-41-gd65547e
 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 
38  DigitalGlitchFilter& operator=(DigitalGlitchFilter&& rhs);
39 
45  void Add(DigitalSource* input);
46 
52  void Add(Encoder* input);
53 
59  void Add(Counter* input);
60 
69  void Remove(DigitalSource* input);
70 
79  void Remove(Encoder* input);
80 
89  void Remove(Counter* input);
90 
96  void SetPeriodCycles(int fpgaCycles);
97 
103  void SetPeriodNanoSeconds(uint64_t nanoseconds);
104 
110  int GetPeriodCycles();
111 
117  uint64_t GetPeriodNanoSeconds();
118 
119  void InitSendable(SendableBuilder& builder) override;
120 
121  private:
122  // Sets the filter for the input to be the requested index. A value of 0
123  // disables the filter, and the filter value must be between 1 and 3,
124  // inclusive.
125  void DoAdd(DigitalSource* input, int requested_index);
126 
127  int m_channelIndex = -1;
128  static wpi::mutex m_mutex;
129  static std::array<bool, 3> m_filterAllocated;
130 };
131 
132 } // namespace frc
WPILib FRC namespace.
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:33
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.