WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
ExternalDirectionCounter.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/** Counter using external direction.
20 *
21 * <p>This counts on an edge from one digital input and the whether it counts
22 * up or down based on the state of a second digital input.
23 *
24 */
26 : public wpi::Sendable,
27 public wpi::SendableHelper<ExternalDirectionCounter> {
28 public:
29 /**
30 * Constructs a new ExternalDirectionCounter.
31 *
32 * @param countSource The source for counting.
33 * @param directionSource The source for selecting count direction.
34 */
36 DigitalSource& directionSource);
37
38 /**
39 * Constructs a new ExternalDirectionCounter.
40 *
41 * @param countSource The source for counting.
42 * @param directionSource The source for selecting count direction.
43 */
44 ExternalDirectionCounter(std::shared_ptr<DigitalSource> countSource,
45 std::shared_ptr<DigitalSource> directionSource);
46
49
50 ~ExternalDirectionCounter() override = default;
51
52 /**
53 * Gets the current count.
54 *
55 * @return The current count.
56 */
57 int GetCount() const;
58
59 /**
60 * Sets to reverse the counter direction.
61 *
62 * @param reverseDirection True to reverse counting direction.
63 */
64 void SetReverseDirection(bool reverseDirection);
65
66 /** Resets the current count. */
67 void Reset();
68
69 /**
70 * Sets the edge configuration for counting.
71 *
72 * @param configuration The counting edge configuration.
73 */
75
76 protected:
77 void InitSendable(wpi::SendableBuilder& builder) override;
78
79 private:
80 std::shared_ptr<DigitalSource> m_countSource;
81 std::shared_ptr<DigitalSource> m_directionSource;
83 int32_t m_index = 0;
84};
85} // namespace frc
DigitalSource Interface.
Definition DigitalSource.h:22
Counter using external direction.
Definition ExternalDirectionCounter.h:27
int GetCount() const
Gets the current count.
~ExternalDirectionCounter() override=default
void SetEdgeConfiguration(EdgeConfiguration configuration)
Sets the edge configuration for counting.
void SetReverseDirection(bool reverseDirection)
Sets to reverse the counter direction.
ExternalDirectionCounter & operator=(ExternalDirectionCounter &&)=default
ExternalDirectionCounter(ExternalDirectionCounter &&)=default
ExternalDirectionCounter(std::shared_ptr< DigitalSource > countSource, std::shared_ptr< DigitalSource > directionSource)
Constructs a new ExternalDirectionCounter.
ExternalDirectionCounter(DigitalSource &countSource, DigitalSource &directionSource)
Constructs a new ExternalDirectionCounter.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
void Reset()
Resets the current count.
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