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