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