WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
PWM.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 <stdint.h>
8
9#include "wpi/hal/PWM.h"
10#include "wpi/hal/Types.hpp"
11#include "wpi/units/time.hpp"
14
15namespace wpi {
16class AddressableLED;
17
18/**
19 * Class for sending pulse-width modulation (PWM) signals.
20 */
22 public:
23 friend class AddressableLED;
24
25 /**
26 * Allocate a PWM given a channel number.
27 *
28 * Checks channel value range and allocates the appropriate channel.
29 * The allocation is only done to help users ensure that they don't double
30 * assign channels.
31 *
32 * @param channel The SmartIO channel number.
33 * @param registerSendable If true, adds this instance to SendableRegistry
34 */
35 explicit PWM(int channel, bool registerSendable = true);
36
37 PWM(PWM&&) = default;
38 PWM& operator=(PWM&&) = default;
39
40 /**
41 * Free the PWM channel.
42 *
43 * Free the resource associated with the PWM channel and set the value to 0.
44 */
45 ~PWM() override;
46
47 /**
48 * Set the PWM pulse time directly to the hardware.
49 *
50 * Write a microsecond value to a PWM channel.
51 *
52 * @param time Microsecond PWM value. Range 0 - 4096.
53 */
54 void SetPulseTime(wpi::units::microsecond_t time);
55
56 /**
57 * Get the PWM pulse time directly from the hardware.
58 *
59 * Read a microsecond value from a PWM channel.
60 *
61 * @return Microsecond PWM control value. Range 0 - 4096.
62 */
63 wpi::units::microsecond_t GetPulseTime() const;
64
65 /**
66 * Temporarily disables the PWM output. The next set call will re-enable
67 * the output.
68 */
70
71 /**
72 * Sets the PWM output period.
73 *
74 * @param period The output period to apply to this channel, in milliseconds.
75 * Valid values are 5ms, 10ms, and 20ms. Default is 20 ms.
76 */
77 void SetOutputPeriod(wpi::units::millisecond_t period);
78
79 int GetChannel() const;
80
81 /**
82 * Indicates this input is used by a simulated device.
83 *
84 * @param device simulated device handle
85 */
87
88 protected:
90
91 private:
92 int m_channel;
94};
95
96} // namespace wpi
A class for driving addressable LEDs, such as WS2812B, WS2815, and NeoPixels.
Definition AddressableLED.hpp:31
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
~PWM() override
Free the PWM channel.
void SetOutputPeriod(wpi::units::millisecond_t period)
Sets the PWM output period.
void SetPulseTime(wpi::units::microsecond_t time)
Set the PWM pulse time directly to the hardware.
void SetDisabled()
Temporarily disables the PWM output.
PWM & operator=(PWM &&)=default
PWM(int channel, bool registerSendable=true)
Allocate a PWM given a channel number.
friend class AddressableLED
Definition PWM.hpp:23
wpi::units::microsecond_t GetPulseTime() const
Get the PWM pulse time directly from the hardware.
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this input is used by a simulated device.
int GetChannel() const
PWM(PWM &&)=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:45
Definition CvSource.hpp:15