WPILibC++ 2027.0.0-alpha-2
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
11namespace frc {
12
13/**
14 * Class to read a digital input.
15 *
16 * This class will read digital inputs and return the current value on the
17 * channel. Other devices such as encoders, gear tooth sensors, etc. that are
18 * implemented elsewhere will automatically allocate digital inputs and outputs
19 * as required. This class is only for devices like switches etc. that aren't
20 * implemented anywhere else.
21 */
23 public wpi::SendableHelper<DigitalInput> {
24 public:
25 /**
26 * Create an instance of a Digital Input class.
27 *
28 * Creates a digital input given a channel.
29 *
30 * @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
31 */
32 explicit DigitalInput(int channel);
33
36
37 ~DigitalInput() override = default;
38
39 /**
40 * Get the value from a digital input channel.
41 *
42 * Retrieve the value of a single digital input channel from the FPGA.
43 */
44 bool Get() const;
45
46 /**
47 * @return The GPIO channel number that this object represents.
48 */
49 int GetChannel() const;
50
51 /**
52 * Indicates this input is used by a simulated device.
53 *
54 * @param device simulated device handle
55 */
57
58 void InitSendable(wpi::SendableBuilder& builder) override;
59
60 private:
61 int m_channel;
63};
64
65} // namespace frc
Class to read a digital input.
Definition DigitalInput.h:23
~DigitalInput() override=default
bool Get() const
Get the value from a digital input channel.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
DigitalInput & operator=(DigitalInput &&)=default
DigitalInput(DigitalInput &&)=default
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this input is used by a simulated device.
int GetChannel() const
DigitalInput(int channel)
Create an instance of a Digital Input class.
A move-only C++ wrapper around a HAL handle.
Definition Types.h:98
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
HAL_Handle HAL_SimDeviceHandle
Definition Types.h:51
Definition SystemServer.h:9