mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[sim] Move WPILib C++ sim implementations out of line (#2598)
This makes the sim classes consistent with the rest of the WPILibC classes.
This commit is contained in:
85
wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp
Normal file
85
wpilibc/src/main/native/cpp/simulation/DutyCycleSim.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "frc/simulation/DutyCycleSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/DutyCycleData.h>
|
||||
|
||||
#include "frc/DutyCycle.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
DutyCycleSim::DutyCycleSim(const DutyCycle& dutyCycle)
|
||||
: m_index{dutyCycle.GetFPGAIndex()} {}
|
||||
|
||||
DutyCycleSim DutyCycleSim::CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindDutyCycleForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no duty cycle found for channel");
|
||||
return DutyCycleSim{index};
|
||||
}
|
||||
|
||||
DutyCycleSim DutyCycleSim::CreateForIndex(int index) {
|
||||
return DutyCycleSim{index};
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool DutyCycleSim::GetInitialized() const {
|
||||
return HALSIM_GetDutyCycleInitialized(m_index);
|
||||
}
|
||||
|
||||
void DutyCycleSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetDutyCycleInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterFrequencyCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int DutyCycleSim::GetFrequency() const {
|
||||
return HALSIM_GetDutyCycleFrequency(m_index);
|
||||
}
|
||||
|
||||
void DutyCycleSim::SetFrequency(int count) {
|
||||
HALSIM_SetDutyCycleFrequency(m_index, count);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterOutputCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double DutyCycleSim::GetOutput() const {
|
||||
return HALSIM_GetDutyCycleOutput(m_index);
|
||||
}
|
||||
|
||||
void DutyCycleSim::SetOutput(double period) {
|
||||
HALSIM_SetDutyCycleOutput(m_index, period);
|
||||
}
|
||||
|
||||
void DutyCycleSim::ResetData() { HALSIM_ResetDutyCycleData(m_index); }
|
||||
Reference in New Issue
Block a user