WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
DutyCycleSim.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 <memory>
8
9#include <units/frequency.h>
10
12
13namespace frc {
14
15class DutyCycle;
16
17namespace sim {
18
19/**
20 * Class to control a simulated duty cycle digital input.
21 */
23 public:
24 /**
25 * Constructs from a DutyCycle object.
26 *
27 * @param dutyCycle DutyCycle to simulate
28 */
29 explicit DutyCycleSim(const DutyCycle& dutyCycle);
30
31 /**
32 * Creates a DutyCycleSim for a SmartIO channel.
33 *
34 * @param channel SmartIO channel
35 * @return Simulated object
36 */
37 static DutyCycleSim CreateForChannel(int channel);
38
39 /**
40 * Register a callback to be run when this duty cycle input is initialized.
41 *
42 * @param callback the callback
43 * @param initialNotify whether to run the callback with the initial state
44 * @return the CallbackStore object associated with this callback
45 */
46 [[nodiscard]]
47 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
48 NotifyCallback callback, bool initialNotify);
49
50 /**
51 * Check whether this duty cycle input has been initialized.
52 *
53 * @return true if initialized
54 */
55 bool GetInitialized() const;
56
57 /**
58 * Define whether this duty cycle input has been initialized.
59 *
60 * @param initialized whether this object is initialized
61 */
62 void SetInitialized(bool initialized);
63
64 /**
65 * Register a callback to be run whenever the frequency changes.
66 *
67 * @param callback the callback
68 * @param initialNotify whether to call the callback with the initial state
69 * @return the CallbackStore object associated with this callback
70 */
71 [[nodiscard]]
72 std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
73 NotifyCallback callback, bool initialNotify);
74
75 /**
76 * Measure the frequency.
77 *
78 * @return the duty cycle frequency
79 */
80 units::hertz_t GetFrequency() const;
81
82 /**
83 * Change the duty cycle frequency.
84 *
85 * @param frequency the new frequency
86 */
87 void SetFrequency(units::hertz_t frequency);
88
89 /**
90 * Register a callback to be run whenever the output changes.
91 *
92 * @param callback the callback
93 * @param initialNotify whether to call the callback with the initial state
94 * @return the CallbackStore object associated with this callback
95 */
96 [[nodiscard]]
97 std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
98 bool initialNotify);
99
100 /**
101 * Measure the output from this duty cycle port.
102 *
103 * @return the output value
104 */
105 double GetOutput() const;
106
107 /**
108 * Change the duty cycle output.
109 *
110 * @param output the new output value
111 */
112 void SetOutput(double output);
113
114 /**
115 * Reset all simulation data for the duty cycle output.
116 */
117 void ResetData();
118
119 private:
120 explicit DutyCycleSim(int index) : m_index{index} {}
121
122 int m_index;
123};
124} // namespace sim
125} // namespace frc
Class to read a duty cycle PWM input.
Definition DutyCycle.h:24
Class to control a simulated duty cycle digital input.
Definition DutyCycleSim.h:22
void SetFrequency(units::hertz_t frequency)
Change the duty cycle frequency.
void SetInitialized(bool initialized)
Define whether this duty cycle input has been initialized.
std::unique_ptr< CallbackStore > RegisterFrequencyCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the frequency changes.
double GetOutput() const
Measure the output from this duty cycle port.
std::unique_ptr< CallbackStore > RegisterOutputCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the output changes.
void ResetData()
Reset all simulation data for the duty cycle output.
DutyCycleSim(const DutyCycle &dutyCycle)
Constructs from a DutyCycle object.
void SetOutput(double output)
Change the duty cycle output.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when this duty cycle input is initialized.
static DutyCycleSim CreateForChannel(int channel)
Creates a DutyCycleSim for a SmartIO channel.
bool GetInitialized() const
Check whether this duty cycle input has been initialized.
units::hertz_t GetFrequency() const
Measure the frequency.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.h:14
Definition SystemServer.h:9