WPILibC++ 2023.4.3
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/Types.h>
12
13#include "EdgeConfiguration.h"
14
15namespace frc {
16class DigitalSource;
17
18/** Counter using external direction.
19 *
20 * <p>This counts on an edge from one digital input and the whether it counts
21 * up or down based on the state of a second digital input.
22 *
23 */
25 : public wpi::Sendable,
26 public wpi::SendableHelper<ExternalDirectionCounter> {
27 public:
28 /**
29 * Constructs a new ExternalDirectionCounter.
30 *
31 * @param countSource The source for counting.
32 * @param directionSource The source for selecting count direction.
33 */
35 DigitalSource& directionSource);
36
37 /**
38 * Constructs a new ExternalDirectionCounter.
39 *
40 * @param countSource The source for counting.
41 * @param directionSource The source for selecting count direction.
42 */
43 ExternalDirectionCounter(std::shared_ptr<DigitalSource> countSource,
44 std::shared_ptr<DigitalSource> directionSource);
45
47
50
51 /**
52 * Gets the current count.
53 *
54 * @return The current count.
55 */
56 int GetCount() const;
57
58 /**
59 * Sets to reverse the counter direction.
60 *
61 * @param reverseDirection True to reverse counting direction.
62 */
63 void SetReverseDirection(bool reverseDirection);
64
65 /** Resets the current count. */
66 void Reset();
67
68 /**
69 * Sets the edge configuration for counting.
70 *
71 * @param configuration The counting edge configuration.
72 */
74
75 protected:
76 void InitSendable(wpi::SendableBuilder& builder) override;
77
78 private:
79 std::shared_ptr<DigitalSource> m_countSource;
80 std::shared_ptr<DigitalSource> m_directionSource;
81 hal::Handle<HAL_CounterHandle> m_handle;
82 int32_t m_index = 0;
83};
84} // namespace frc
DigitalSource Interface.
Definition: DigitalSource.h:22
Counter using external direction.
Definition: ExternalDirectionCounter.h:26
int GetCount() const
Gets the current count.
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.
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
::int32_t int32_t
Definition: Meta.h:57
Definition: AprilTagFieldLayout.h:22
EdgeConfiguration
Definition: EdgeConfiguration.h:8