WPILibC++ 2024.3.2
SPIAccelerometerSim.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
10
11namespace frc::sim {
13 public:
14 /**
15 * Construct a new simulation object.
16 *
17 * @param index the HAL index of the accelerometer
18 */
19 explicit SPIAccelerometerSim(int index);
20
21 /**
22 * Register a callback to be run when this accelerometer activates.
23 *
24 * @param callback the callback
25 * @param initialNotify whether to run the callback with the initial state
26 * @return the CallbackStore object associated with this callback
27 */
28 [[nodiscard]]
29 std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
30 bool initialNotify);
31
32 /**
33 * Check whether the accelerometer is active.
34 *
35 * @return true if active
36 */
37 bool GetActive() const;
38
39 /**
40 * Define whether this accelerometer is active.
41 *
42 * @param active the new state
43 */
44 void SetActive(bool active);
45
46 /**
47 * Register a callback to be run whenever the range changes.
48 *
49 * @param callback the callback
50 * @param initialNotify whether to call the callback with the initial state
51 * @return the CallbackStore object associated with this callback
52 */
53 [[nodiscard]]
54 std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
55 bool initialNotify);
56
57 /**
58 * Check the range of this accelerometer.
59 *
60 * @return the accelerometer range
61 */
62 int GetRange() const;
63
64 /**
65 * Change the range of this accelerometer.
66 *
67 * @param range the new accelerometer range
68 */
69 void SetRange(int range);
70
71 /**
72 * Register a callback to be run whenever the X axis value changes.
73 *
74 * @param callback the callback
75 * @param initialNotify whether to call the callback with the initial state
76 * @return the CallbackStore object associated with this callback
77 */
78 [[nodiscard]]
79 std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
80 bool initialNotify);
81
82 /**
83 * Measure the X axis value.
84 *
85 * @return the X axis measurement
86 */
87 double GetX() const;
88
89 /**
90 * Change the X axis value of the accelerometer.
91 *
92 * @param x the new reading of the X axis
93 */
94 void SetX(double x);
95
96 /**
97 * Register a callback to be run whenever the Y axis value changes.
98 *
99 * @param callback the callback
100 * @param initialNotify whether to call the callback with the initial state
101 * @return the CallbackStore object associated with this callback
102 */
103 [[nodiscard]]
104 std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
105 bool initialNotify);
106
107 /**
108 * Measure the Y axis value.
109 *
110 * @return the Y axis measurement
111 */
112 double GetY() const;
113
114 /**
115 * Change the Y axis value of the accelerometer.
116 *
117 * @param y the new reading of the Y axis
118 */
119 void SetY(double y);
120
121 /**
122 * Register a callback to be run whenever the Z axis value changes.
123 *
124 * @param callback the callback
125 * @param initialNotify whether to call the callback with the initial state
126 * @return the CallbackStore object associated with this callback
127 */
128 [[nodiscard]]
129 std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
130 bool initialNotify);
131
132 /**
133 * Measure the Z axis value.
134 *
135 * @return the Z axis measurement
136 */
137 double GetZ() const;
138
139 /**
140 * Change the Z axis value of the accelerometer.
141 *
142 * @param z the new reading of the Z axis
143 */
144 void SetZ(double z);
145
146 /**
147 * Reset all simulation data of this object.
148 */
149 void ResetData();
150
151 private:
152 int m_index;
153};
154} // namespace frc::sim
Definition: SPIAccelerometerSim.h:12
SPIAccelerometerSim(int index)
Construct a new simulation object.
double GetY() const
Measure the Y axis value.
void SetRange(int range)
Change the range of this accelerometer.
std::unique_ptr< CallbackStore > RegisterActiveCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when this accelerometer activates.
std::unique_ptr< CallbackStore > RegisterXCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the X axis value changes.
void SetActive(bool active)
Define whether this accelerometer is active.
void SetY(double y)
Change the Y axis value of the accelerometer.
int GetRange() const
Check the range of this accelerometer.
std::unique_ptr< CallbackStore > RegisterYCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Y axis value changes.
std::unique_ptr< CallbackStore > RegisterRangeCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the range changes.
double GetX() const
Measure the X axis value.
void SetX(double x)
Change the X axis value of the accelerometer.
void ResetData()
Reset all simulation data of this object.
bool GetActive() const
Check whether the accelerometer is active.
void SetZ(double z)
Change the Z axis value of the accelerometer.
double GetZ() const
Measure the Z axis value.
std::unique_ptr< CallbackStore > RegisterZCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Z axis value changes.
Definition: XboxControllerSim.h:13
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14