WPILibC++ 2024.1.1-beta-4
DigitalGlitchFilter.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <array>
10
11#include <wpi/mutex.h>
14
15#include "frc/DigitalSource.h"
16
17namespace frc {
18
19class Encoder;
20class Counter;
21
22/**
23 * Class to enable glitch filtering on a set of digital inputs.
24 *
25 * This class will manage adding and removing digital inputs from a FPGA glitch
26 * filter. The filter lets the user configure the time that an input must remain
27 * high or low before it is classified as high or low.
28 */
30 public wpi::SendableHelper<DigitalGlitchFilter> {
31 public:
34
37
38 /**
39 * Assigns the DigitalSource to this glitch filter.
40 *
41 * @param input The DigitalSource to add.
42 */
43 void Add(DigitalSource* input);
44
45 /**
46 * Assigns the Encoder to this glitch filter.
47 *
48 * @param input The Encoder to add.
49 */
50 void Add(Encoder* input);
51
52 /**
53 * Assigns the Counter to this glitch filter.
54 *
55 * @param input The Counter to add.
56 */
57 void Add(Counter* input);
58
59 /**
60 * Removes a digital input from this filter.
61 *
62 * Removes the DigitalSource from this glitch filter and re-assigns it to
63 * the default filter.
64 *
65 * @param input The DigitalSource to remove.
66 */
67 void Remove(DigitalSource* input);
68
69 /**
70 * Removes an encoder from this filter.
71 *
72 * Removes the Encoder from this glitch filter and re-assigns it to
73 * the default filter.
74 *
75 * @param input The Encoder to remove.
76 */
77 void Remove(Encoder* input);
78
79 /**
80 * Removes a counter from this filter.
81 *
82 * Removes the Counter from this glitch filter and re-assigns it to
83 * the default filter.
84 *
85 * @param input The Counter to remove.
86 */
87 void Remove(Counter* input);
88
89 /**
90 * Sets the number of cycles that the input must not change state for.
91 *
92 * @param fpgaCycles The number of FPGA cycles.
93 */
94 void SetPeriodCycles(int fpgaCycles);
95
96 /**
97 * Sets the number of nanoseconds that the input must not change state for.
98 *
99 * @param nanoseconds The number of nanoseconds.
100 */
101 void SetPeriodNanoSeconds(uint64_t nanoseconds);
102
103 /**
104 * Gets the number of cycles that the input must not change state for.
105 *
106 * @return The number of cycles.
107 */
109
110 /**
111 * Gets the number of nanoseconds that the input must not change state for.
112 *
113 * @return The number of nanoseconds.
114 */
116
117 void InitSendable(wpi::SendableBuilder& builder) override;
118
119 private:
120 // Sets the filter for the input to be the requested index. A value of 0
121 // disables the filter, and the filter value must be between 1 and 3,
122 // inclusive.
123 void DoAdd(DigitalSource* input, int requested_index);
124
125 int m_channelIndex = -1;
126 static wpi::mutex m_mutex;
127 static std::array<bool, 3> m_filterAllocated;
128};
129
130} // namespace frc
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:35
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:30
void SetPeriodNanoSeconds(uint64_t nanoseconds)
Sets the number of nanoseconds that the input must not change state for.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
void Remove(Encoder *input)
Removes an encoder from this filter.
void Remove(DigitalSource *input)
Removes a digital input from this filter.
void SetPeriodCycles(int fpgaCycles)
Sets the number of cycles that the input must not change state for.
void Remove(Counter *input)
Removes a counter from this filter.
void Add(Counter *input)
Assigns the Counter to this glitch filter.
int GetPeriodCycles()
Gets the number of cycles that the input must not change state for.
DigitalGlitchFilter(DigitalGlitchFilter &&)=default
uint64_t GetPeriodNanoSeconds()
Gets the number of nanoseconds that the input must not change state for.
DigitalGlitchFilter & operator=(DigitalGlitchFilter &&)=default
~DigitalGlitchFilter() override
void Add(DigitalSource *input)
Assigns the DigitalSource to this glitch filter.
void Add(Encoder *input)
Assigns the Encoder to this glitch filter.
DigitalSource Interface.
Definition: DigitalSource.h:22
Class to read quad encoders.
Definition: Encoder.h:40
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
Definition: AprilTagPoseEstimator.h:15
::std::mutex mutex
Definition: mutex.h:17