Files
allwpilib/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h

80 lines
2.1 KiB
C
Raw Normal View History

2019-11-01 23:41:30 -07:00
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
2019-11-01 23:41:30 -07:00
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <memory>
#include "frc/simulation/CallbackStore.h"
2019-11-01 23:41:30 -07:00
namespace frc {
class DutyCycle;
2019-11-01 23:41:30 -07:00
namespace sim {
/**
* Class to control a simulated duty cycle digital input.
*/
2019-11-01 23:41:30 -07:00
class DutyCycleSim {
public:
/**
* Constructs from a DutyCycle object.
*
* @param dutyCycle DutyCycle to simulate
*/
explicit DutyCycleSim(const DutyCycle& dutyCycle);
/**
* Creates a DutyCycleSim for a digital input channel.
*
* @param channel digital input channel
* @return Simulated object
* @throws std::out_of_range if no DutyCycle is configured for that channel
*/
static DutyCycleSim CreateForChannel(int channel);
/**
* Creates a DutyCycleSim for a simulated index.
* The index is incremented for each simulated DutyCycle.
*
* @param index simulator index
* @return Simulated object
*/
static DutyCycleSim CreateForIndex(int index);
2019-11-01 23:41:30 -07:00
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const;
void SetInitialized(bool initialized);
2019-11-01 23:41:30 -07:00
std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
NotifyCallback callback, bool initialNotify);
2019-11-01 23:41:30 -07:00
int GetFrequency() const;
2019-11-01 23:41:30 -07:00
void SetFrequency(int count);
2019-11-01 23:41:30 -07:00
std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
bool initialNotify);
2019-11-01 23:41:30 -07:00
double GetOutput() const;
2019-11-01 23:41:30 -07:00
void SetOutput(double period);
2019-11-01 23:41:30 -07:00
void ResetData();
2019-11-01 23:41:30 -07:00
private:
explicit DutyCycleSim(int index) : m_index{index} {}
2019-11-01 23:41:30 -07:00
int m_index;
};
} // namespace sim
} // namespace frc