WPILibC++ 2024.3.2
UpDownCounter.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 <memory>
8
9#include <hal/Types.h>
12
13#include "EdgeConfiguration.h"
14
15namespace frc {
16class DigitalSource;
17
18/** Up Down Counter.
19 *
20 * This class can count edges on a single digital input or count up based on an
21 * edge from one digital input and down on an edge from another digital input.
22 *
23 */
25 public wpi::SendableHelper<UpDownCounter> {
26 public:
27 /**
28 * Constructs a new UpDown Counter.
29 *
30 * @param upSource The up count source (can be null).
31 * @param downSource The down count source (can be null).
32 */
33 UpDownCounter(DigitalSource& upSource, DigitalSource& downSource);
34
35 /**
36 * Constructs a new UpDown Counter.
37 *
38 * @param upSource The up count source (can be null).
39 * @param downSource The down count source (can be null).
40 */
41 UpDownCounter(std::shared_ptr<DigitalSource> upSource,
42 std::shared_ptr<DigitalSource> downSource);
43
44 ~UpDownCounter() override;
45
48
49 /**
50 * Gets the current count.
51 *
52 * @return The current count.
53 */
54 int GetCount() const;
55
56 /**
57 * Sets to revert the counter direction.
58 *
59 * @param reverseDirection True to reverse counting direction.
60 */
61 void SetReverseDirection(bool reverseDirection);
62
63 /** Resets the current count. */
64 void Reset();
65
66 /**
67 * Sets the configuration for the up source.
68 *
69 * @param configuration The up source configuration.
70 */
72
73 /**
74 * Sets the configuration for the down source.
75 *
76 * @param configuration The down source configuration.
77 */
79
80 protected:
81 void InitSendable(wpi::SendableBuilder& builder) override;
82
83 private:
84 void InitUpDownCounter();
85 std::shared_ptr<DigitalSource> m_upSource;
86 std::shared_ptr<DigitalSource> m_downSource;
88 int32_t m_index = 0;
89};
90} // namespace frc
DigitalSource Interface.
Definition: DigitalSource.h:22
Up Down Counter.
Definition: UpDownCounter.h:25
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
UpDownCounter(DigitalSource &upSource, DigitalSource &downSource)
Constructs a new UpDown Counter.
UpDownCounter(UpDownCounter &&)=default
void SetReverseDirection(bool reverseDirection)
Sets to revert the counter direction.
UpDownCounter & operator=(UpDownCounter &&)=default
void Reset()
Resets the current count.
int GetCount() const
Gets the current count.
void SetUpEdgeConfiguration(EdgeConfiguration configuration)
Sets the configuration for the up source.
~UpDownCounter() override
UpDownCounter(std::shared_ptr< DigitalSource > upSource, std::shared_ptr< DigitalSource > downSource)
Constructs a new UpDown Counter.
void SetDownEdgeConfiguration(EdgeConfiguration configuration)
Sets the configuration for the down source.
Helper class for building Sendable dashboard representations.
Definition: SendableBuilder.h:21
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
EdgeConfiguration
Edge configuration.
Definition: EdgeConfiguration.h:11