WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
PWMSim.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 <memory>
8
10
11namespace wpi {
12
13class PWM;
15
16namespace sim {
17
18/**
19 * Class to control a simulated PWM output.
20 */
21class PWMSim {
22 public:
23 /**
24 * Constructs from a PWM object.
25 *
26 * @param pwm PWM to simulate
27 */
28 explicit PWMSim(const PWM& pwm);
29
30 /**
31 * Constructs from a PWM channel number.
32 *
33 * @param channel Channel number
34 */
35 explicit PWMSim(int channel);
36
37 /**
38 * Register a callback to be run when the PWM is initialized.
39 *
40 * @param callback the callback
41 * @param initialNotify whether to run the callback with the initial state
42 * @return the CallbackStore object associated with this callback
43 */
44 [[nodiscard]]
45 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
46 NotifyCallback callback, bool initialNotify);
47
48 /**
49 * Check whether the PWM has been initialized.
50 *
51 * @return true if initialized
52 */
53 bool GetInitialized() const;
54
55 /**
56 * Define whether the PWM has been initialized.
57 *
58 * @param initialized whether this object is initialized
59 */
60 void SetInitialized(bool initialized);
61
62 /**
63 * Register a callback to be run when the PWM pulse microsecond value changes.
64 *
65 * @param callback the callback
66 * @param initialNotify whether to run the callback with the initial value
67 * @return the CallbackStore object associated with this callback
68 */
69 [[nodiscard]]
70 std::unique_ptr<CallbackStore> RegisterPulseMicrosecondCallback(
71 NotifyCallback callback, bool initialNotify);
72
73 /**
74 * Get the PWM pulse microsecond value.
75 *
76 * @return the PWM pulse microsecond value
77 */
78 int32_t GetPulseMicrosecond() const;
79
80 /**
81 * Set the PWM pulse microsecond value.
82 *
83 * @param microsecondPulseTime the PWM pulse microsecond value
84 */
85 void SetPulseMicrosecond(int32_t microsecondPulseTime);
86
87 /**
88 * Register a callback to be run when the PWM period scale changes.
89 *
90 * @param callback the callback
91 * @param initialNotify whether to run the callback with the initial value
92 * @return the CallbackStore object associated with this callback
93 */
94 [[nodiscard]]
95 std::unique_ptr<CallbackStore> RegisterOutputPeriodCallback(
96 NotifyCallback callback, bool initialNotify);
97
98 /**
99 * Get the PWM period scale.
100 *
101 * @return the PWM period scale
102 */
103 int GetOutputPeriod() const;
104
105 /**
106 * Set the PWM period scale.
107 *
108 * @param period the PWM period scale
109 */
110 void SetOutputPeriod(int period);
111
112 /**
113 * Reset all simulation data.
114 */
115 void ResetData();
116
117 private:
118 int m_index;
119};
120} // namespace sim
121} // namespace wpi
Class implements the PWM generation in the FPGA.
Definition PWM.hpp:26
Common base class for all PWM Motor Controllers.
Definition PWMMotorController.hpp:35
std::unique_ptr< CallbackStore > RegisterPulseMicrosecondCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the PWM pulse microsecond value changes.
std::unique_ptr< CallbackStore > RegisterOutputPeriodCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the PWM period scale changes.
PWMSim(int channel)
Constructs from a PWM channel number.
void ResetData()
Reset all simulation data.
void SetInitialized(bool initialized)
Define whether the PWM has been initialized.
void SetPulseMicrosecond(int32_t microsecondPulseTime)
Set the PWM pulse microsecond value.
PWMSim(const PWM &pwm)
Constructs from a PWM object.
int32_t GetPulseMicrosecond() const
Get the PWM pulse microsecond value.
int GetOutputPeriod() const
Get the PWM period scale.
void SetOutputPeriod(int period)
Set the PWM period scale.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the PWM is initialized.
bool GetInitialized() const
Check whether the PWM has been initialized.
Definition CTREPCMSim.hpp:13
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.hpp:16
Definition CvSource.hpp:15