2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
#include "frc/simulation/CallbackStore.h"
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
class AnalogOutput;
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated analog output.
|
|
|
|
|
*/
|
|
|
|
|
class AnalogOutputSim {
|
2018-05-11 12:38:23 -07:00
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs from an AnalogOutput object.
|
|
|
|
|
*
|
|
|
|
|
* @param analogOutput AnalogOutput to simulate
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit AnalogOutputSim(const AnalogOutput& analogOutput);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs from an analog output channel number.
|
|
|
|
|
*
|
|
|
|
|
* @param channel Channel number
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit AnalogOutputSim(int channel);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* 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(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Read the analog output voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return the voltage on this analog output
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetVoltage() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Set the analog output voltage.
|
|
|
|
|
*
|
|
|
|
|
* @param voltage the new voltage on this analog output
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetVoltage(double voltage);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* 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(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Check whether this analog output has been initialized.
|
|
|
|
|
*
|
|
|
|
|
* @return true if initialized
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetInitialized() const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Define whether this analog output has been initialized.
|
|
|
|
|
*
|
|
|
|
|
* @param initialized whether this object is initialized
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetInitialized(bool initialized);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Reset all simulation data on this object.
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void ResetData();
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|