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