WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
DigitalOutput.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"
9#include "wpi/units/time.hpp"
12
13namespace wpi {
14
15/**
16 * Class to write to digital outputs.
17 *
18 * Write values to the digital output channels. Other devices implemented
19 * elsewhere will allocate channels automatically so for those devices it
20 * shouldn't be done here.
21 */
23 public wpi::util::SendableHelper<DigitalOutput> {
24 public:
25 /**
26 * Create an instance of a digital output.
27 *
28 * Create a digital output given a channel.
29 *
30 * @param channel The SmartIO channel
31 */
32 explicit DigitalOutput(int channel);
33
36
37 ~DigitalOutput() override;
38
39 /**
40 * Set the value of a digital output.
41 *
42 * Set the value of a digital output to either one (true) or zero (false).
43 *
44 * @param value 1 (true) for high, 0 (false) for disabled
45 */
46 void Set(bool value);
47
48 /**
49 * Gets the value being output from the Digital Output.
50 *
51 * @return the state of the digital output.
52 */
53 bool Get() const;
54
55 /**
56 * @return The GPIO channel number that this object represents.
57 */
58 int GetChannel() const;
59
60 /**
61 * Output a single pulse on the digital output line.
62 *
63 * Send a single pulse on the digital output line where the pulse duration is
64 * specified in seconds. Maximum of 65535 microseconds.
65 *
66 * @param pulseLength The pulse length in seconds
67 */
68 void Pulse(wpi::units::second_t pulseLength);
69
70 /**
71 * Determine if the pulse is still going.
72 *
73 * Determine if a previously started pulse is still going.
74 */
75 bool IsPulsing() const;
76
77 /**
78 * Change the PWM frequency of the PWM output on a Digital Output line.
79 *
80 * The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
81 * logarithmic.
82 *
83 * There is only one PWM frequency for all digital channels.
84 *
85 * @param rate The frequency to output all digital output PWM signals.
86 */
87 void SetPWMRate(double rate);
88
89 /**
90 * Enable a PWM PPS (Pulse Per Second) Output on this line.
91 *
92 * Allocate one of the 6 DO PWM generator resources from this module.
93 *
94 * Supply the duty-cycle to output.
95 *
96 * The resolution of the duty cycle is 8-bit.
97 *
98 * @param dutyCycle The duty-cycle to start generating. [0..1]
99 */
100 void EnablePPS(double dutyCycle);
101
102 /**
103 * Enable a PWM Output on this line.
104 *
105 * Allocate one of the 6 DO PWM generator resources from this module.
106 *
107 * Supply the initial duty-cycle to output so as to avoid a glitch when first
108 * starting.
109 *
110 * The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
111 * less) but is reduced the higher the frequency of the PWM signal is.
112 *
113 * @param initialDutyCycle The duty-cycle to start generating. [0..1]
114 */
115 void EnablePWM(double initialDutyCycle);
116
117 /**
118 * Change this line from a PWM output back to a static Digital Output line.
119 *
120 * Free up one of the 6 DO PWM generator resources that were in use.
121 */
123
124 /**
125 * Change the duty-cycle that is being generated on the line.
126 *
127 * The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
128 * less) but is reduced the higher the frequency of the PWM signal is.
129 *
130 * @param dutyCycle The duty-cycle to change to. [0..1]
131 */
132 void UpdateDutyCycle(double dutyCycle);
133
134 /**
135 * Indicates this output is used by a simulated device.
136 *
137 * @param device simulated device handle
138 */
140
142
143 private:
144 int m_channel;
147};
148
149} // namespace wpi
bool Get() const
Gets the value being output from the Digital Output.
void Set(bool value)
Set the value of a digital output.
void EnablePWM(double initialDutyCycle)
Enable a PWM Output on this line.
DigitalOutput & operator=(DigitalOutput &&)=default
void Pulse(wpi::units::second_t pulseLength)
Output a single pulse on the digital output line.
int GetChannel() const
DigitalOutput(int channel)
Create an instance of a digital output.
void UpdateDutyCycle(double dutyCycle)
Change the duty-cycle that is being generated on the line.
bool IsPulsing() const
Determine if the pulse is still going.
void EnablePPS(double dutyCycle)
Enable a PWM PPS (Pulse Per Second) Output on this line.
DigitalOutput(DigitalOutput &&)=default
~DigitalOutput() override
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this output is used by a simulated device.
void SetPWMRate(double rate)
Change the PWM frequency of the PWM output on a Digital Output line.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
void DisablePWM()
Change this line from a PWM output back to a static Digital Output line.
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:45
Definition CvSource.hpp:15