Files
allwpilib/wpilibc/src/main/native/include/frc/counter/ExternalDirectionCounter.h
2021-11-23 20:33:36 -08:00

80 lines
2.1 KiB
C++

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "EdgeConfiguration.h"
namespace frc {
class DigitalSource;
/** Counter using external direction. */
class ExternalDirectionCounter
: public wpi::Sendable,
public wpi::SendableHelper<ExternalDirectionCounter> {
public:
/**
* Constructs a new ExternalDirectionCounter.
*
* @param countSource The source for counting.
* @param directionSource The source for selecting count direction.
*/
ExternalDirectionCounter(DigitalSource& countSource,
DigitalSource& directionSource);
/**
* Constructs a new ExternalDirectionCounter.
*
* @param countSource The source for counting.
* @param directionSource The source for selecting count direction.
*/
ExternalDirectionCounter(std::shared_ptr<DigitalSource> countSource,
std::shared_ptr<DigitalSource> directionSource);
~ExternalDirectionCounter() override;
ExternalDirectionCounter(ExternalDirectionCounter&&) = default;
ExternalDirectionCounter& operator=(ExternalDirectionCounter&&) = default;
/**
* Gets the current count.
*
* @return The current count.
*/
int GetCount() const;
/**
* Sets to revert the counter direction.
*
* @param reverseDirection True to reverse counting direction.
*/
void SetReverseDirection(bool reverseDirection);
/** Resets the current count. */
void Reset();
/**
* Sets the edge configuration for counting.
*
* @param configuration The counting edge configuration.
*/
void SetEdgeConfiguration(EdgeConfiguration configuration);
protected:
void InitSendable(wpi::SendableBuilder& builder) override;
private:
std::shared_ptr<DigitalSource> m_countSource;
std::shared_ptr<DigitalSource> m_directionSource;
hal::Handle<HAL_CounterHandle> m_handle;
int32_t m_index = 0;
};
} // namespace frc