[wpilib] Document simulation APIs (#3079)

- Remove sim checkstyle suppression
- Add [[nodiscard]] to C++ register callback functions
- Add a couple of missing sim functions

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: Starlight220 <yotamshlomi@gmail.com>
This commit is contained in:
Peter Johnson
2021-01-11 21:55:45 -08:00
committed by GitHub
parent 26584ff145
commit 9c3b51ca0f
64 changed files with 4516 additions and 199 deletions

View File

@@ -52,39 +52,130 @@ class AddressableLEDSim {
*/
static AddressableLEDSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback on the Initialized property.
*
* @param callback the callback that will be called whenever the Initialized
* property is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object storing this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Change the Initialized value of the LED strip.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
/**
* Register a callback on the output port.
*
* @param callback the callback that will be called whenever the output port
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the output port.
*
* @return the output port
*/
int GetOutputPort() const;
/**
* Change the output port.
*
* @param outputPort the new output port
*/
void SetOutputPort(int outputPort);
std::unique_ptr<CallbackStore> RegisterLengthCallback(NotifyCallback callback,
bool initialNotify);
int GetLength() const;
void SetLength(int length);
std::unique_ptr<CallbackStore> RegisterRunningCallback(
/**
* Register a callback on the length.
*
* @param callback the callback that will be called whenever the length is
* changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterLengthCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the length of the LED strip.
*
* @return the length
*/
int GetLength() const;
/**
* Change the length of the LED strip.
*
* @param length the new value
*/
void SetLength(int length);
/**
* Register a callback on whether the LEDs are running.
*
* @param callback the callback that will be called whenever the LED state is
* changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRunningCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the LEDs are running.
*
* @return true if they are
*/
int GetRunning() const;
/**
* Change whether the LEDs are active.
*
* @param running the new value
*/
void SetRunning(bool running);
std::unique_ptr<CallbackStore> RegisterDataCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback on the LED data.
*
* @param callback the callback that will be called whenever the LED data is
* changed
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterDataCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the LED data.
*
* @param data output parameter to fill with LED data
* @return the length of the LED data
*/
int GetData(struct HAL_AddressableLEDData* data) const;
/**
* Change the LED data.
*
* @param data the new data
* @param length the length of the LED data
*/
void SetData(struct HAL_AddressableLEDData* data, int length);
private:

View File

@@ -28,7 +28,7 @@ class AnalogEncoderSim {
explicit AnalogEncoderSim(const AnalogEncoder& encoder);
/**
* Set the position using an {@link Rotation2d}.
* Set the position using an Rotation2d.
*
* @param angle The angle.
*/
@@ -47,7 +47,7 @@ class AnalogEncoderSim {
units::turn_t GetTurns();
/**
* Get the position as a {@link Rotation2d}.
* Get the position as a Rotation2d.
*/
Rotation2d GetPosition();

View File

@@ -33,27 +33,82 @@ class AnalogGyroSim {
*/
explicit AnalogGyroSim(int channel);
std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
bool initialNotify);
double GetAngle() const;
void SetAngle(double angle);
std::unique_ptr<CallbackStore> RegisterRateCallback(NotifyCallback callback,
bool initialNotify);
double GetRate() const;
void SetRate(double rate);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback on the angle.
*
* @param callback the callback that will be called whenever the angle changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterAngleCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the current angle of the gyro.
*
* @return the angle measured by the gyro
*/
double GetAngle() const;
/**
* Change the angle measured by the gyro.
*
* @param angle the new value
*/
void SetAngle(double angle);
/**
* Register a callback on the rate.
*
* @param callback the callback that will be called whenever the rate changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRateCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the rate of angle change on this gyro.
*
* @return the rate
*/
double GetRate() const;
/**
* Change the rate of the gyro.
*
* @param rate the new rate
*/
void SetRate(double rate);
/**
* Register a callback on whether the gyro is initialized.
*
* @param callback the callback that will be called whenever the gyro is
* initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the gyro is initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Set whether this gyro is initialized.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:

View File

@@ -33,69 +33,237 @@ class AnalogInputSim {
*/
explicit AnalogInputSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback on whether the analog input is initialized.
*
* @param callback the callback that will be called whenever the analog input
* is initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if this analog input has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Change whether this analog input has been initialized.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
/**
* Register a callback on the number of average bits.
*
* @param callback the callback that will be called whenever the number of
* average bits is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the number of average bits.
*
* @return the number of average bits
*/
int GetAverageBits() const;
/**
* Change the number of average bits.
*
* @param averageBits the new value
*/
void SetAverageBits(int averageBits);
std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
/**
* Register a callback on the amount of oversampling bits.
*
* @param callback the callback that will be called whenever the oversampling
* bits are changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the amount of oversampling bits.
*
* @return the amount of oversampling bits
*/
int GetOversampleBits() const;
/**
* Change the amount of oversampling bits.
*
* @param oversampleBits the new value
*/
void SetOversampleBits(int oversampleBits);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
/**
* Register a callback on the voltage.
*
* @param callback the callback that will be called whenever the voltage is
* changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the voltage.
*
* @return the voltage
*/
double GetVoltage() const;
/**
* Change the voltage.
*
* @param voltage the new value
*/
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on whether the accumulator is initialized.
*
* @param callback the callback that will be called whenever the accumulator
* is initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterAccumulatorInitializedCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check if the accumulator has been initialized.
*
* @return true if initialized
*/
bool GetAccumulatorInitialized() const;
/**
* Change whether the accumulator has been initialized.
*
* @param accumulatorInitialized the new value
*/
void SetAccumulatorInitialized(bool accumulatorInitialized);
std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
/**
* Register a callback on the accumulator value.
*
* @param callback the callback that will be called whenever the accumulator
* value is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator value.
*
* @return the accumulator value
*/
int64_t GetAccumulatorValue() const;
/**
* Change the accumulator value.
*
* @param accumulatorValue the new value
*/
void SetAccumulatorValue(int64_t accumulatorValue);
std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
/**
* Register a callback on the accumulator count.
*
* @param callback the callback that will be called whenever the accumulator
* count is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator count.
*
* @return the accumulator count.
*/
int64_t GetAccumulatorCount() const;
/**
* Change the accumulator count.
*
* @param accumulatorCount the new count.
*/
void SetAccumulatorCount(int64_t accumulatorCount);
std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on the accumulator center.
*
* @param callback the callback that will be called whenever the accumulator
* center is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterAccumulatorCenterCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the accumulator center.
*
* @return the accumulator center
*/
int GetAccumulatorCenter() const;
/**
* Change the accumulator center.
*
* @param accumulatorCenter the new center
*/
void SetAccumulatorCenter(int accumulatorCenter);
std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on the accumulator deadband.
*
* @param callback the callback that will be called whenever the accumulator
* deadband is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterAccumulatorDeadbandCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the accumulator deadband.
*
* @return the accumulator deadband
*/
int GetAccumulatorDeadband() const;
/**
* Change the accumulator deadband.
*
* @param accumulatorDeadband the new deadband
*/
void SetAccumulatorDeadband(int accumulatorDeadband);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:

View File

@@ -33,20 +33,57 @@ class AnalogOutputSim {
*/
explicit AnalogOutputSim(int channel);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
/**
* Register a callback to be run whenever the voltage changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the analog output voltage.
*
* @return the voltage on this analog output
*/
double GetVoltage() const;
/**
* Set the analog output voltage.
*
* @param voltage the new voltage on this analog output
*/
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when this analog output is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether this analog output has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether this analog output has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
/**
* Reset all simulation data on this object.
*/
void ResetData();
private:

View File

@@ -45,27 +45,86 @@ class AnalogTriggerSim {
*/
static AnalogTriggerSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback on whether the analog trigger is initialized.
*
* @param callback the callback that will be called whenever the analog
* trigger is initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if this analog trigger has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Change whether this analog trigger has been initialized.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterTriggerLowerBoundCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on the lower bound.
*
* @param callback the callback that will be called whenever the lower bound
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterTriggerLowerBoundCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the lower bound.
*
* @return the lower bound
*/
double GetTriggerLowerBound() const;
/**
* Change the lower bound.
*
* @param triggerLowerBound the new lower bound
*/
void SetTriggerLowerBound(double triggerLowerBound);
std::unique_ptr<CallbackStore> RegisterTriggerUpperBoundCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on the upper bound.
*
* @param callback the callback that will be called whenever the upper bound
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterTriggerUpperBoundCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the upper bound.
*
* @return the upper bound
*/
double GetTriggerUpperBound() const;
/**
* Change the upper bound.
*
* @param triggerUpperBound the new upper bound
*/
void SetTriggerUpperBound(double triggerUpperBound);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:

View File

@@ -33,41 +33,129 @@ class BuiltInAccelerometerSim {
*/
explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel);
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run when this accelerometer activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterActiveCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the accelerometer is active.
*
* @return true if active
*/
bool GetActive() const;
/**
* Define whether this accelerometer is active.
*
* @param active the new state
*/
void SetActive(bool active);
std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the range changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRangeCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the range of this accelerometer.
*
* @return the accelerometer range
*/
HAL_AccelerometerRange GetRange() const;
/**
* Change the range of this accelerometer.
*
* @param range the new accelerometer range
*/
void SetRange(HAL_AccelerometerRange range);
std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the X axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterXCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the X axis value.
*
* @return the X axis measurement
*/
double GetX() const;
/**
* Change the X axis value of the accelerometer.
*
* @param x the new reading of the X axis
*/
void SetX(double x);
std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the Y axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterYCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the Y axis value.
*
* @return the Y axis measurement
*/
double GetY() const;
/**
* Change the Y axis value of the accelerometer.
*
* @param y the new reading of the Y axis
*/
void SetY(double y);
std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the Z axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterZCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the Z axis value.
*
* @return the Z axis measurement
*/
double GetZ() const;
/**
* Change the Z axis value of the accelerometer.
*
* @param z the new reading of the Z axis
*/
void SetZ(double z);
/**
* Reset all simulation data of this object.
*/
void ResetData();
private:

View File

@@ -24,6 +24,9 @@ void ConstBufferCallbackStoreThunk(const char* name, void* param,
const unsigned char* buffer,
unsigned int count);
/**
* Manages simulation callbacks; each object is associated with a callback.
*/
class CallbackStore {
public:
CallbackStore(int32_t i, NotifyCallback cb, CancelCallbackNoIndexFunc ccf);

View File

@@ -41,41 +41,132 @@ class DIOSim {
*/
explicit DIOSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when this DIO is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether this DIO has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether this DIO has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterValueCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the DIO value changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterValueCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the value of the DIO port.
*
* @return the DIO value
*/
bool GetValue() const;
/**
* Change the DIO value.
*
* @param value the new value
*/
void SetValue(bool value);
std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
/**
* Register a callback to be run whenever the pulse length changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the pulse length.
*
* @return the pulse length of this DIO port
*/
double GetPulseLength() const;
/**
* Change the pulse length of this DIO port.
*
* @param pulseLength the new pulse length
*/
void SetPulseLength(double pulseLength);
std::unique_ptr<CallbackStore> RegisterIsInputCallback(
/**
* Register a callback to be run whenever this DIO changes to be an input.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterIsInputCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether this DIO port is currently an Input.
*
* @return true if Input
*/
bool GetIsInput() const;
/**
* Define whether this DIO port is an Input.
*
* @param isInput whether this DIO should be an Input
*/
void SetIsInput(bool isInput);
std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
/**
* Register a callback to be run whenever the filter index changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the filter index.
*
* @return the filter index of this DIO port
*/
int GetFilterIndex() const;
/**
* Change the filter index of this DIO port.
*
* @param filterIndex the new filter index
*/
void SetFilterIndex(int filterIndex);
/**
* Reset all simulation data of this object.
*/
void ResetData();
private:

View File

@@ -47,27 +47,81 @@ class DigitalPWMSim {
*/
static DigitalPWMSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when this PWM output is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether this PWM output has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether this PWM output has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
/**
* Register a callback to be run whenever the duty cycle value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the duty cycle value.
*
* @return the duty cycle value of this PWM output
*/
double GetDutyCycle() const;
/**
* Set the duty cycle value of this PWM output.
*
* @param dutyCycle the new value
*/
void SetDutyCycle(double dutyCycle);
std::unique_ptr<CallbackStore> RegisterPinCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the pin changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPinCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the pin number.
*
* @return the pin number
*/
int GetPin() const;
/**
* Change the pin number.
*
* @param pin the new pin number
*/
void SetPin(int pin);
/**
* Reset all simulation data.
*/
void ResetData();
private:

View File

@@ -18,60 +18,205 @@ namespace frc::sim {
*/
class DriverStationSim {
public:
static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
/**
* Register a callback on whether the DS is enabled.
*
* @param callback the callback that will be called whenever the enabled
* state is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the DS is enabled.
*
* @return true if enabled
*/
static bool GetEnabled();
/**
* Change whether the DS is enabled.
*
* @param enabled the new value
*/
static void SetEnabled(bool enabled);
static std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on whether the DS is in autonomous mode.
*
* @param callback the callback that will be called on autonomous mode
* entrance/exit
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterAutonomousCallback(NotifyCallback callback, bool initialNotify);
/**
* Check if the DS is in autonomous.
*
* @return true if autonomous
*/
static bool GetAutonomous();
/**
* Change whether the DS is in autonomous.
*
* @param autonomous the new value
*/
static void SetAutonomous(bool autonomous);
static std::unique_ptr<CallbackStore> RegisterTestCallback(
/**
* Register a callback on whether the DS is in test mode.
*
* @param callback the callback that will be called whenever the test mode
* is entered or left
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore> RegisterTestCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the DS is in test.
*
* @return true if test
*/
static bool GetTest();
/**
* Change whether the DS is in test.
*
* @param test the new value
*/
static void SetTest(bool test);
static std::unique_ptr<CallbackStore> RegisterEStopCallback(
/**
* Register a callback on the eStop state.
*
* @param callback the callback that will be called whenever the eStop state
* changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore> RegisterEStopCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if eStop has been activated.
*
* @return true if eStopped
*/
static bool GetEStop();
/**
* Set whether eStop is active.
*
* @param eStop true to activate
*/
static void SetEStop(bool eStop);
static std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on whether the FMS is connected.
*
* @param callback the callback that will be called whenever the FMS
* connection changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterFmsAttachedCallback(NotifyCallback callback, bool initialNotify);
/**
* Check if the FMS is connected.
*
* @return true if FMS is connected
*/
static bool GetFmsAttached();
/**
* Change whether the FMS is connected.
*
* @param fmsAttached the new value
*/
static void SetFmsAttached(bool fmsAttached);
static std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on whether the DS is connected.
*
* @param callback the callback that will be called whenever the DS
* connection changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterDsAttachedCallback(NotifyCallback callback, bool initialNotify);
/**
* Check if the DS is attached.
*
* @return true if attached
*/
static bool GetDsAttached();
/**
* Change whether the DS is attached.
*
* @param dsAttached the new value
*/
static void SetDsAttached(bool dsAttached);
static std::unique_ptr<CallbackStore> RegisterAllianceStationIdCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback on the alliance station ID.
*
* @param callback the callback that will be called whenever the alliance
* station changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterAllianceStationIdCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the alliance station ID (color + number).
*
* @return the alliance station color and number
*/
static HAL_AllianceStationID GetAllianceStationId();
/**
* Change the alliance station.
*
* @param allianceStationId the new alliance station
*/
static void SetAllianceStationId(HAL_AllianceStationID allianceStationId);
static std::unique_ptr<CallbackStore> RegisterMatchTimeCallback(
/**
* Register a callback on match time.
*
* @param callback the callback that will be called whenever match time
* changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore> RegisterMatchTimeCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the current value of the match timer.
*
* @return the current match time
*/
static double GetMatchTime();
/**
* Sets the match timer.
*
* @param matchTime the new match time
*/
static void SetMatchTime(double matchTime);
/**
@@ -238,6 +383,9 @@ class DriverStationSim {
*/
static void SetReplayNumber(int replayNumber);
/**
* Reset all simulation data for the Driver Station.
*/
static void ResetData();
};
} // namespace frc::sim

View File

@@ -44,27 +44,81 @@ class DutyCycleSim {
*/
static DutyCycleSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when this duty cycle input is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether this duty cycle input has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether this duty cycle input has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
/**
* Register a callback to be run whenever the frequency changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the frequency.
*
* @return the duty cycle frequency
*/
int GetFrequency() const;
/**
* Change the duty cycle frequency.
*
* @param frequency the new frequency
*/
void SetFrequency(int count);
std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the output changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterOutputCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the output from this duty cycle port.
*
* @return the output value
*/
double GetOutput() const;
/**
* Change the duty cycle output.
*
* @param output the new output value
*/
void SetOutput(double period);
/**
* Reset all simulation data for the duty cycle output.
*/
void ResetData();
private:

View File

@@ -45,77 +45,261 @@ class EncoderSim {
*/
static EncoderSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback on the Initialized property of the encoder.
*
* @param callback the callback that will be called whenever the Initialized
* property is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the Initialized value of the encoder.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Change the Initialized value of the encoder.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterCountCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback on the count property of the encoder.
*
* @param callback the callback that will be called whenever the count
* property is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterCountCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the count of the encoder.
*
* @return the count
*/
int GetCount() const;
/**
* Change the count of the encoder.
*
* @param count the new count
*/
void SetCount(int count);
std::unique_ptr<CallbackStore> RegisterPeriodCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback on the period of the encoder.
*
* @param callback the callback that will be called whenever the period is
* changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPeriodCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the period of the encoder.
*
* @return the encoder period
*/
double GetPeriod() const;
/**
* Change the encoder period.
*
* @param period the new period
*/
void SetPeriod(double period);
std::unique_ptr<CallbackStore> RegisterResetCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be called whenever the encoder is reset.
*
* @param callback the callback
* @param initialNotify whether to run the callback on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterResetCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the encoder has been reset.
*
* @return true if reset
*/
bool GetReset() const;
/**
* Change the reset property of the encoder.
*
* @param reset the new value
*/
void SetReset(bool reset);
std::unique_ptr<CallbackStore> RegisterMaxPeriodCallback(
/**
* Register a callback to be run whenever the max period of the encoder is
* changed.
*
* @param callback the callback
* @param initialNotify whether to run the callback on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterMaxPeriodCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the max period of the encoder.
*
* @return the max period of the encoder
*/
double GetMaxPeriod() const;
/**
* Change the max period of the encoder.
*
* @param maxPeriod the new value
*/
void SetMaxPeriod(double maxPeriod);
std::unique_ptr<CallbackStore> RegisterDirectionCallback(
/**
* Register a callback on the direction of the encoder.
*
* @param callback the callback that will be called whenever the direction
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterDirectionCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the direction of the encoder.
*
* @return the direction of the encoder
*/
bool GetDirection() const;
/**
* Set the direction of the encoder.
*
* @param direction the new direction
*/
void SetDirection(bool direction);
std::unique_ptr<CallbackStore> RegisterReverseDirectionCallback(
/**
* Register a callback on the reverse direction.
*
* @param callback the callback that will be called whenever the reverse
* direction is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterReverseDirectionCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the reverse direction of the encoder.
*
* @return the reverse direction of the encoder
*/
bool GetReverseDirection() const;
/**
* Set the reverse direction.
*
* @param reverseDirection the new value
*/
void SetReverseDirection(bool reverseDirection);
std::unique_ptr<CallbackStore> RegisterSamplesToAverageCallback(
/**
* Register a callback on the samples-to-average value of this encoder.
*
* @param callback the callback that will be called whenever the
* samples-to-average is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterSamplesToAverageCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the samples-to-average value.
*
* @return the samples-to-average value
*/
int GetSamplesToAverage() const;
/**
* Set the samples-to-average value.
*
* @param samplesToAverage the new value
*/
void SetSamplesToAverage(int samplesToAverage);
std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
/**
* Register a callback on the distance per pulse value of this encoder.
*
* @param callback the callback that will be called whenever the
* distance per pulse is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
NotifyCallback callback, bool initialNotify);
/**
* Read the distance per pulse of the encoder.
*
* @return the encoder distance per pulse
*/
double GetDistancePerPulse() const;
/**
* Change the encoder distance per pulse.
*
* @param distancePerPulse the new distance per pulse
*/
void SetDistancePerPulse(double distancePerPulse);
/**
* Resets all simulation data for this encoder.
*/
void ResetData();
/**
* Change the encoder distance.
*
* @param distance the new distance
*/
void SetDistance(double distance);
/**
* Read the distance of the encoder.
*
* @return the encoder distance
*/
double GetDistance();
/**
* Change the rate of the encoder.
*
* @param rate the new rate
*/
void SetRate(double rate);
/**
* Get the rate of the encoder.
*
* @return the rate of change
*/
double GetRate();
private:

View File

@@ -38,30 +38,101 @@ class GenericHIDSim {
*/
void NotifyNewData();
/**
* Set the value of a given button.
*
* @param button the button to set
* @param value the new value
*/
void SetRawButton(int button, bool value);
/**
* Set the value of a given axis.
*
* @param axis the axis to set
* @param value the new value
*/
void SetRawAxis(int axis, double value);
/**
* Set the value of a given POV.
*
* @param pov the POV to set
* @param value the new value
*/
void SetPOV(int pov, int value);
/**
* Set the value of the default POV (port 0).
*
* @param value the new value
*/
void SetPOV(int value);
/**
* Set the axis count of this device.
*
* @param count the new axis count
*/
void SetAxisCount(int count);
/**
* Set the POV count of this device.
*
* @param count the new POV count
*/
void SetPOVCount(int count);
/**
* Set the button count of this device.
*
* @param count the new button count
*/
void SetButtonCount(int count);
/**
* Set the type of this device.
*
* @param type the new device type
*/
void SetType(GenericHID::HIDType type);
/**
* Set the name of this device.
*
* @param name the new device name
*/
void SetName(const char* name);
/**
* Set the type of an axis.
*
* @param axis the axis
* @param type the type
*/
void SetAxisType(int axis, int type);
/**
* Read the output of a button.
*
* @param outputNumber the button number
* @return the value of the button (true = pressed)
*/
bool GetOutput(int outputNumber);
/**
* Get the encoded 16-bit integer that passes button values.
*
* @return the button values
*/
int64_t GetOutputs();
/**
* Get the joystick rumble.
*
* @param type the rumble to read
* @return the rumble value
*/
double GetRumble(GenericHID::RumbleType type);
protected:

View File

@@ -31,18 +31,53 @@ class JoystickSim : public GenericHIDSim {
*/
explicit JoystickSim(int port);
/**
* Set the X value of the joystick.
*
* @param value the new X value
*/
void SetX(double value);
/**
* Set the Y value of the joystick.
*
* @param value the new Y value
*/
void SetY(double value);
/**
* Set the Z value of the joystick.
*
* @param value the new Z value
*/
void SetZ(double value);
/**
* Set the twist value of the joystick.
*
* @param value the new twist value
*/
void SetTwist(double value);
/**
* Set the throttle value of the joystick.
*
* @param value the new throttle value
*/
void SetThrottle(double value);
/**
* Set the trigger value of the joystick.
*
* @param state the new value
*/
void SetTrigger(bool state);
/**
* Set the top state of the joystick.
*
* @param state the new state
*/
void SetTop(bool state);
private:

View File

@@ -38,59 +38,204 @@ class PCMSim {
*/
explicit PCMSim(const Compressor& compressor);
std::unique_ptr<CallbackStore> RegisterSolenoidInitializedCallback(
int channel, NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run when a solenoid is initialized on a channel.
*
* @param channel the channel to monitor
* @param callback the callback
* @param initialNotify should the callback be run with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterSolenoidInitializedCallback(int channel, NotifyCallback callback,
bool initialNotify);
/**
* Check if a solenoid has been initialized on a specific channel.
*
* @param channel the channel to check
* @return true if initialized
*/
bool GetSolenoidInitialized(int channel) const;
/**
* Define whether a solenoid has been initialized on a specific channel.
*
* @param channel the channel
* @param solenoidInitialized is there a solenoid initialized on that channel
*/
void SetSolenoidInitialized(int channel, bool solenoidInitialized);
std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
/**
* Register a callback to be run when the solenoid output on a channel
* changes.
*
* @param channel the channel to monitor
* @param callback the callback
* @param initialNotify should the callback be run with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
int channel, NotifyCallback callback, bool initialNotify);
/**
* Check the solenoid output on a specific channel.
*
* @param channel the channel to check
* @return the solenoid output
*/
bool GetSolenoidOutput(int channel) const;
/**
* Change the solenoid output on a specific channel.
*
* @param channel the channel to check
* @param solenoidOutput the new solenoid output
*/
void SetSolenoidOutput(int channel, bool solenoidOutput);
std::unique_ptr<CallbackStore> RegisterCompressorInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run when the compressor is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterCompressorInitializedCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check whether the compressor has been initialized.
*
* @return true if initialized
*/
bool GetCompressorInitialized() const;
/**
* Define whether the compressor has been initialized.
*
* @param compressorInitialized whether the compressor is initialized
*/
void SetCompressorInitialized(bool compressorInitialized);
std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
/**
* Register a callback to be run when the compressor activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the compressor is on.
*
* @return true if the compressor is active
*/
bool GetCompressorOn() const;
/**
* Set whether the compressor is active.
*
* @param compressorOn the new value
*/
void SetCompressorOn(bool compressorOn);
std::unique_ptr<CallbackStore> RegisterClosedLoopEnabledCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the closed loop state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterClosedLoopEnabledCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check whether the closed loop compressor control is active.
*
* @return true if active
*/
bool GetClosedLoopEnabled() const;
/**
* Turn on/off the closed loop control of the compressor.
*
* @param closedLoopEnabled whether the control loop is active
*/
void SetClosedLoopEnabled(bool closedLoopEnabled);
std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
/**
* Register a callback to be run whenever the pressure switch value changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the value of the pressure switch.
*
* @return the pressure switch value
*/
bool GetPressureSwitch() const;
/**
* Set the value of the pressure switch.
*
* @param pressureSwitch the new value
*/
void SetPressureSwitch(bool pressureSwitch);
std::unique_ptr<CallbackStore> RegisterCompressorCurrentCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the compressor current changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterCompressorCurrentCallback(NotifyCallback callback,
bool initialNotify);
/**
* Read the compressor current.
*
* @return the current of the compressor connected to this module
*/
double GetCompressorCurrent() const;
/**
* Set the compressor current.
*
* @param compressorCurrent the new compressor current
*/
void SetCompressorCurrent(double compressorCurrent);
/**
* Get the current value of all solenoid outputs.
*
* @return the solenoid outputs (1 bit per output)
*/
uint8_t GetAllSolenoidOutputs() const;
/**
* Change all of the solenoid outputs.
*
* @param outputs the new solenoid outputs (1 bit per output)
*/
void SetAllSolenoidOutputs(uint8_t outputs);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:

View File

@@ -33,38 +33,125 @@ class PDPSim {
*/
explicit PDPSim(const PowerDistributionPanel& pdp);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when the PDP is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PDP has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether the PDP has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
/**
* Register a callback to be run whenever the PDP temperature changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the temperature of the PDP.
*
* @return the PDP temperature
*/
double GetTemperature() const;
/**
* Define the PDP temperature.
*
* @param temperature the new PDP temperature
*/
void SetTemperature(double temperature);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
/**
* Register a callback to be run whenever the PDP voltage changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the PDP voltage.
*
* @return the PDP voltage.
*/
double GetVoltage() const;
/**
* Set the PDP voltage.
*
* @param voltage the new PDP voltage
*/
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterCurrentCallback(
/**
* Register a callback to be run whenever the current of a specific channel
* changes.
*
* @param channel the channel
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterCurrentCallback(
int channel, NotifyCallback callback, bool initialNotify);
/**
* Read the current in one of the PDP channels.
*
* @param channel the channel to check
* @return the current in the given channel
*/
double GetCurrent(int channel) const;
/**
* Change the current in the given channel.
*
* @param channel the channel to edit
* @param current the new current for the channel
*/
void SetCurrent(int channel, double current);
/**
* Read the current of all of the PDP channels.
*
* @param currents output array; set to the current in each channel. The
* array must be big enough to hold all the PDP channels
*/
void GetAllCurrents(double* currents) const;
/**
* Change the current in all of the PDP channels.
*
* @param currents array containing the current values for each channel. The
* array must be big enough to hold all the PDP channels
*/
void SetAllCurrents(const double* currents);
/**
* Reset all PDP simulation data.
*/
void ResetData();
private:

View File

@@ -33,48 +33,153 @@ class PWMSim {
*/
explicit PWMSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
/**
* Register a callback to be run when the PWM is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PWM has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether the PWM has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterRawValueCallback(
/**
* Register a callback to be run when the PWM raw value changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRawValueCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM raw value.
*
* @return the PWM raw value
*/
int GetRawValue() const;
/**
* Set the PWM raw value.
*
* @param rawValue the PWM raw value
*/
void SetRawValue(int rawValue);
std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run when the PWM speed changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterSpeedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM speed.
*
* @return the PWM speed (-1.0 to 1.0)
*/
double GetSpeed() const;
/**
* Set the PWM speed.
*
* @param speed the PWM speed (-1.0 to 1.0)
*/
void SetSpeed(double speed);
std::unique_ptr<CallbackStore> RegisterPositionCallback(
/**
* Register a callback to be run when the PWM position changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPositionCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM position.
*
* @return the PWM position (0.0 to 1.0)
*/
double GetPosition() const;
/**
* Set the PWM position.
*
* @param position the PWM position (0.0 to 1.0)
*/
void SetPosition(double position);
std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
/**
* Register a callback to be run when the PWM period scale changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the PWM period scale.
*
* @return the PWM period scale
*/
int GetPeriodScale() const;
/**
* Set the PWM period scale.
*
* @param periodScale the PWM period scale
*/
void SetPeriodScale(int periodScale);
std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
/**
* Register a callback to be run when the PWM zero latch state changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PWM is zero latched.
*
* @return true if zero latched
*/
bool GetZeroLatch() const;
/**
* Define whether the PWM has been zero latched.
*
* @param zeroLatch true to indicate zero latched
*/
void SetZeroLatch(bool zeroLatch);
/**
* Reset all simulation data.
*/
void ResetData();
private:

View File

@@ -33,34 +33,107 @@ class RelaySim {
*/
explicit RelaySim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run when the forward direction is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterInitializedForwardCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check whether the forward direction has been initialized.
*
* @return true if initialized
*/
bool GetInitializedForward() const;
/**
* Define whether the forward direction has been initialized.
*
* @param initializedForward whether this object is initialized
*/
void SetInitializedForward(bool initializedForward);
std::unique_ptr<CallbackStore> RegisterInitializedReverseCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run when the reverse direction is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore>
RegisterInitializedReverseCallback(NotifyCallback callback,
bool initialNotify);
/**
* Check whether the reverse direction has been initialized.
*
* @return true if initialized
*/
bool GetInitializedReverse() const;
/**
* Define whether the reverse direction has been initialized.
*
* @param initializedReverse whether this object is initialized
*/
void SetInitializedReverse(bool initializedReverse);
std::unique_ptr<CallbackStore> RegisterForwardCallback(
/**
* Register a callback to be run when the forward direction changes state.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterForwardCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the forward direction is active.
*
* @return true if active
*/
bool GetForward() const;
/**
* Set whether the forward direction is active.
*
* @param forward true to make active
*/
void SetForward(bool forward);
std::unique_ptr<CallbackStore> RegisterReverseCallback(
/**
* Register a callback to be run when the reverse direction changes state.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterReverseCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the reverse direction is active.
*
* @return true if active
*/
bool GetReverse() const;
/**
* Set whether the reverse direction is active.
*
* @param reverse true to make active
*/
void SetReverse(bool reverse);
/**
* Reset all simulation data.
*/
void ResetData();
private:

View File

@@ -18,111 +18,385 @@ namespace frc::sim {
*/
class RoboRioSim {
public:
static std::unique_ptr<CallbackStore> RegisterFPGAButtonCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run when the FPGA button state changes.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterFPGAButtonCallback(NotifyCallback callback, bool initialNotify);
/**
* Query the state of the FPGA button.
*
* @return the FPGA button state
*/
static bool GetFPGAButton();
/**
* Define the state of the FPGA button.
*
* @param fpgaButton the new state
*/
static void SetFPGAButton(bool fPGAButton);
static std::unique_ptr<CallbackStore> RegisterVInVoltageCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the Vin voltage changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterVInVoltageCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the Vin voltage.
*
* @return the Vin voltage
*/
static units::volt_t GetVInVoltage();
/**
* Define the Vin voltage.
*
* @param vInVoltage the new voltage
*/
static void SetVInVoltage(units::volt_t vInVoltage);
static std::unique_ptr<CallbackStore> RegisterVInCurrentCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the Vin current changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterVInCurrentCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the Vin current.
*
* @return the Vin current
*/
static units::ampere_t GetVInCurrent();
/**
* Define the Vin current.
*
* @param vInCurrent the new current
*/
static void SetVInCurrent(units::ampere_t vInCurrent);
static std::unique_ptr<CallbackStore> RegisterUserVoltage6VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 6V rail voltage changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserVoltage6VCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 6V rail voltage.
*
* @return the 6V rail voltage
*/
static units::volt_t GetUserVoltage6V();
/**
* Define the 6V rail voltage.
*
* @param userVoltage6V the new voltage
*/
static void SetUserVoltage6V(units::volt_t userVoltage6V);
static std::unique_ptr<CallbackStore> RegisterUserCurrent6VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 6V rail current changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserCurrent6VCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 6V rail current.
*
* @return the 6V rail current
*/
static units::ampere_t GetUserCurrent6V();
/**
* Define the 6V rail current.
*
* @param userCurrent6V the new current
*/
static void SetUserCurrent6V(units::ampere_t userCurrent6V);
static std::unique_ptr<CallbackStore> RegisterUserActive6VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 6V rail active state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserActive6VCallback(NotifyCallback callback, bool initialNotify);
/**
* Get the 6V rail active state.
*
* @return true if the 6V rail is active
*/
static bool GetUserActive6V();
/**
* Set the 6V rail active state.
*
* @param userActive6V true to make rail active
*/
static void SetUserActive6V(bool userActive6V);
static std::unique_ptr<CallbackStore> RegisterUserVoltage5VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 5V rail voltage changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserVoltage5VCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 5V rail voltage.
*
* @return the 5V rail voltage
*/
static units::volt_t GetUserVoltage5V();
/**
* Define the 5V rail voltage.
*
* @param userVoltage5V the new voltage
*/
static void SetUserVoltage5V(units::volt_t userVoltage5V);
static std::unique_ptr<CallbackStore> RegisterUserCurrent5VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 5V rail current changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserCurrent5VCallback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 5V rail current.
*
* @return the 5V rail current
*/
static units::ampere_t GetUserCurrent5V();
/**
* Define the 5V rail current.
*
* @param userCurrent5V the new current
*/
static void SetUserCurrent5V(units::ampere_t userCurrent5V);
static std::unique_ptr<CallbackStore> RegisterUserActive5VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 5V rail active state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserActive5VCallback(NotifyCallback callback, bool initialNotify);
/**
* Get the 5V rail active state.
*
* @return true if the 5V rail is active
*/
static bool GetUserActive5V();
/**
* Set the 5V rail active state.
*
* @param userActive5V true to make rail active
*/
static void SetUserActive5V(bool userActive5V);
static std::unique_ptr<CallbackStore> RegisterUserVoltage3V3Callback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 3.3V rail voltage changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserVoltage3V3Callback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 3.3V rail voltage.
*
* @return the 3.3V rail voltage
*/
static units::volt_t GetUserVoltage3V3();
/**
* Define the 3.3V rail voltage.
*
* @param userVoltage3V3 the new voltage
*/
static void SetUserVoltage3V3(units::volt_t userVoltage3V3);
static std::unique_ptr<CallbackStore> RegisterUserCurrent3V3Callback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 3.3V rail current changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserCurrent3V3Callback(NotifyCallback callback, bool initialNotify);
/**
* Measure the 3.3V rail current.
*
* @return the 3.3V rail current
*/
static units::ampere_t GetUserCurrent3V3();
/**
* Define the 3.3V rail current.
*
* @param userCurrent3V3 the new current
*/
static void SetUserCurrent3V3(units::ampere_t userCurrent3V3);
static std::unique_ptr<CallbackStore> RegisterUserActive3V3Callback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 3.3V rail active state changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserActive3V3Callback(NotifyCallback callback, bool initialNotify);
/**
* Get the 3.3V rail active state.
*
* @return true if the 3.3V rail is active
*/
static bool GetUserActive3V3();
/**
* Set the 3.3V rail active state.
*
* @param userActive3V3 true to make rail active
*/
static void SetUserActive3V3(bool userActive3V3);
static std::unique_ptr<CallbackStore> RegisterUserFaults6VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 6V rail number of faults
* changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserFaults6VCallback(NotifyCallback callback, bool initialNotify);
/**
* Get the 6V rail number of faults.
*
* @return number of faults
*/
static int GetUserFaults6V();
/**
* Set the 6V rail number of faults.
*
* @param userFaults6V number of faults
*/
static void SetUserFaults6V(int userFaults6V);
static std::unique_ptr<CallbackStore> RegisterUserFaults5VCallback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 5V rail number of faults
* changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserFaults5VCallback(NotifyCallback callback, bool initialNotify);
/**
* Get the 5V rail number of faults.
*
* @return number of faults
*/
static int GetUserFaults5V();
/**
* Set the 5V rail number of faults.
*
* @param userFaults5V number of faults
*/
static void SetUserFaults5V(int userFaults5V);
static std::unique_ptr<CallbackStore> RegisterUserFaults3V3Callback(
NotifyCallback callback, bool initialNotify);
/**
* Register a callback to be run whenever the 3.3V rail number of faults
* changes.
*
* @param callback the callback
* @param initialNotify whether the callback should be called with the
* initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] static std::unique_ptr<CallbackStore>
RegisterUserFaults3V3Callback(NotifyCallback callback, bool initialNotify);
/**
* Get the 3.3V rail number of faults.
*
* @return number of faults
*/
static int GetUserFaults3V3();
/**
* Set the 3.3V rail number of faults.
*
* @param userFaults3V3 number of faults
*/
static void SetUserFaults3V3(int userFaults3V3);
/**
* Reset all simulation data.
*/
static void ResetData();
};
} // namespace frc::sim

View File

@@ -11,43 +11,136 @@
namespace frc::sim {
class SPIAccelerometerSim {
public:
/**
* Construct a new simulation object.
*
* @param index the HAL index of the accelerometer
*/
explicit SPIAccelerometerSim(int index);
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run when this accelerometer activates.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterActiveCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check whether the accelerometer is active.
*
* @return true if active
*/
bool GetActive() const;
/**
* Define whether this accelerometer is active.
*
* @param active the new state
*/
void SetActive(bool active);
std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the range changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRangeCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check the range of this accelerometer.
*
* @return the accelerometer range
*/
int GetRange() const;
/**
* Change the range of this accelerometer.
*
* @param range the new accelerometer range
*/
void SetRange(int range);
std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the X axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterXCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the X axis value.
*
* @return the X axis measurement
*/
double GetX() const;
/**
* Change the X axis value of the accelerometer.
*
* @param x the new reading of the X axis
*/
void SetX(double x);
std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the Y axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterYCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the Y axis value.
*
* @return the Y axis measurement
*/
double GetY() const;
/**
* Change the Y axis value of the accelerometer.
*
* @param y the new reading of the Y axis
*/
void SetY(double y);
std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
bool initialNotify);
/**
* Register a callback to be run whenever the Z axis value changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterZCallback(
NotifyCallback callback, bool initialNotify);
/**
* Measure the Z axis value.
*
* @return the Z axis measurement
*/
double GetZ() const;
/**
* Change the Z axis value of the accelerometer.
*
* @param z the new reading of the Z axis
*/
void SetZ(double z);
/**
* Reset all simulation data of this object.
*/
void ResetData();
private:

View File

@@ -25,26 +25,84 @@ class SimDeviceSim {
*/
explicit SimDeviceSim(const char* name);
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimValue GetValue(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimInt GetInt(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimLong GetLong(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimDouble GetDouble(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimEnum GetEnum(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimBoolean GetBoolean(const char* name) const;
/**
* Get all options for the given enum.
*
* @param val the enum
* @return names of the different values for that enum
*/
static std::vector<std::string> GetEnumOptions(hal::SimEnum val);
/**
* Get all properties.
*
* @param callback callback called for each property (SimValue). Signature
* of the callback must be const char*, HAL_SimValueHandle,
* int, const HAL_Value*
*/
template <typename F>
void EnumerateValues(F callback) const {
return HALSIM_EnumerateSimValues(
m_handle, &callback,
[](const char* name, void* param, HAL_SimValueHandle handle,
HAL_Bool readonly, const struct HAL_Value* value) {
std::invoke(*static_cast<F*>(param), name, handle, readonly, value);
int direction, const struct HAL_Value* value) {
std::invoke(*static_cast<F*>(param), name, handle, direction, value);
});
}
/**
* Get the raw handle of this object.
*
* @return the handle used to refer to this object
*/
operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT
template <typename F>
@@ -56,6 +114,9 @@ class SimDeviceSim {
});
}
/**
* Reset all SimDevice data.
*/
static void ResetData();
private:

View File

@@ -11,6 +11,11 @@
namespace frc::sim {
/**
* Override the HAL runtime type (simulated/real).
*
* @param type runtime type
*/
void SetRuntimeType(HAL_RuntimeType type);
void WaitForProgramStart();
@@ -19,16 +24,40 @@ void SetProgramStarted();
bool GetProgramStarted();
/**
* Restart the simulator time.
*/
void RestartTiming();
/**
* Pause the simulator time.
*/
void PauseTiming();
/**
* Resume the simulator time.
*/
void ResumeTiming();
/**
* Check if the simulator time is paused.
*
* @return true if paused
*/
bool IsTimingPaused();
/**
* Advance the simulator time and wait for all notifiers to run.
*
* @param deltaSeconds the amount to advance (in seconds)
*/
void StepTiming(units::second_t delta);
/**
* Advance the simulator time and return immediately.
*
* @param deltaSeconds the amount to advance (in seconds)
*/
void StepTimingAsync(units::second_t delta);
} // namespace frc::sim

View File

@@ -31,26 +31,86 @@ class XboxControllerSim : public GenericHIDSim {
*/
explicit XboxControllerSim(int port);
/**
* Change the X value of the joystick.
*
* @param hand the joystick hand
* @param value the new value
*/
void SetX(GenericHID::JoystickHand hand, double value);
/**
* Change the Y value of the joystick.
*
* @param hand the joystick hand
* @param value the new value
*/
void SetY(GenericHID::JoystickHand hand, double value);
/**
* Change the value of a trigger axis on the joystick.
*
* @param hand the joystick hand
* @param value the new value
*/
void SetTriggerAxis(GenericHID::JoystickHand hand, double value);
/**
* Change the value of a bumper on the joystick.
*
* @param hand the joystick hand
* @param state the new value
*/
void SetBumper(GenericHID::JoystickHand hand, bool state);
/**
* Change the value of a button on the joystick.
*
* @param hand the joystick hand
* @param state the new value
*/
void SetStickButton(GenericHID::JoystickHand hand, bool state);
/**
* Change the value of the A button.
*
* @param state the new value
*/
void SetAButton(bool state);
/**
* Change the value of the B button.
*
* @param state the new value
*/
void SetBButton(bool state);
/**
* Change the value of the X button.
*
* @param state the new value
*/
void SetXButton(bool state);
/**
* Change the value of the Y button.
*
* @param state the new value
*/
void SetYButton(bool state);
/**
* Change the value of the Back button.
*
* @param state the new value
*/
void SetBackButton(bool state);
/**
* Change the value of the Start button.
*
* @param state the new value
*/
void SetStartButton(bool state);
};