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