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 AnalogTrigger;
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated analog trigger.
|
|
|
|
|
*/
|
2018-05-11 12:38:23 -07:00
|
|
|
class AnalogTriggerSim {
|
|
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs from an AnalogTrigger object.
|
|
|
|
|
*
|
|
|
|
|
* @param analogTrigger AnalogTrigger to simulate
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an AnalogTriggerSim for an analog input channel.
|
|
|
|
|
*
|
|
|
|
|
* @param channel analog input channel
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
* @throws std::out_of_range if no AnalogTrigger is configured for that
|
|
|
|
|
* channel
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static AnalogTriggerSim CreateForChannel(int channel);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an AnalogTriggerSim for a simulated index.
|
|
|
|
|
* The index is incremented for each simulated AnalogTrigger.
|
|
|
|
|
*
|
|
|
|
|
* @param index simulator index
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static AnalogTriggerSim CreateForIndex(int index);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* 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(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Check if this analog trigger 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
|
|
|
/**
|
|
|
|
|
* Change whether this analog trigger has been initialized.
|
|
|
|
|
*
|
|
|
|
|
* @param initialized the new value
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetInitialized(bool initialized);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* 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);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Get the lower bound.
|
|
|
|
|
*
|
|
|
|
|
* @return the lower bound
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetTriggerLowerBound() const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the lower bound.
|
|
|
|
|
*
|
|
|
|
|
* @param triggerLowerBound the new lower bound
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetTriggerLowerBound(double triggerLowerBound);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* 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);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Get the upper bound.
|
|
|
|
|
*
|
|
|
|
|
* @return the upper bound
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetTriggerUpperBound() const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the upper bound.
|
|
|
|
|
*
|
|
|
|
|
* @param triggerUpperBound the new upper bound
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetTriggerUpperBound(double triggerUpperBound);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Reset all simulation data for this object.
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void ResetData();
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
private:
|
2020-07-04 10:10:43 -07:00
|
|
|
explicit AnalogTriggerSim(int index) : m_index{index} {}
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|