WPILibC++ 2023.4.3
DigitalInput.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
9
10#include "frc/DigitalSource.h"
11
12namespace frc {
13
14class DigitalGlitchFilter;
15
16/**
17 * Class to read a digital input.
18 *
19 * This class will read digital inputs and return the current value on the
20 * channel. Other devices such as encoders, gear tooth sensors, etc. that are
21 * implemented elsewhere will automatically allocate digital inputs and outputs
22 * as required. This class is only for devices like switches etc. that aren't
23 * implemented anywhere else.
24 */
26 public wpi::Sendable,
27 public wpi::SendableHelper<DigitalInput> {
28 public:
29 /**
30 * Create an instance of a Digital Input class.
31 *
32 * Creates a digital input given a channel.
33 *
34 * @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
35 */
36 explicit DigitalInput(int channel);
37
38 ~DigitalInput() override;
39
42
43 /**
44 * Get the value from a digital input channel.
45 *
46 * Retrieve the value of a single digital input channel from the FPGA.
47 */
48 bool Get() const;
49
50 // Digital Source Interface
51 /**
52 * @return The HAL Handle to the specified source.
53 */
55
56 /**
57 * @return The type of analog trigger output to be used. 0 for Digitals
58 */
60
61 /**
62 * Is source an AnalogTrigger
63 */
64 bool IsAnalogTrigger() const override;
65
66 /**
67 * @return The GPIO channel number that this object represents.
68 */
69 int GetChannel() const override;
70
71 /**
72 * Indicates this input is used by a simulated device.
73 *
74 * @param device simulated device handle
75 */
77
78 void InitSendable(wpi::SendableBuilder& builder) override;
79
80 private:
81 int m_channel;
82 hal::Handle<HAL_DigitalHandle> m_handle;
83
84 friend class DigitalGlitchFilter;
85};
86
87} // namespace frc
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:30
Class to read a digital input.
Definition: DigitalInput.h:27
HAL_Handle GetPortHandleForRouting() const override
bool Get() const
Get the value from a digital input channel.
int GetChannel() const override
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
bool IsAnalogTrigger() const override
Is source an AnalogTrigger.
DigitalInput & operator=(DigitalInput &&)=default
DigitalInput(DigitalInput &&)=default
~DigitalInput() override
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this input is used by a simulated device.
DigitalInput(int channel)
Create an instance of a Digital Input class.
DigitalSource Interface.
Definition: DigitalSource.h:22
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 HAL_Handle
Definition: Types.h:17
HAL_Handle HAL_SimDeviceHandle
Definition: Types.h:53
Definition: AprilTagFieldLayout.h:22
AnalogTriggerType
Definition: AnalogTriggerType.h:9